Skip to content

Unions generation: The operator '[]' isn't defined for the class 'int' #894

@supervital

Description

@supervital

Hello,

I have the next union:

"unions": {
    "myValue": {
      "types": [
        {
          "type": "integer",
          "description": "Simple integer value."
        },
        {
          "type": "double",
          "description": "Simple double value."
        },
        {
          "type": "someCustomValue",
          "description": "A custom value."
        },
        {
          "type": "someCustomValue2",
          "description": "A custom value."
        }
      ]
    }
  }

And while compiling I get the next error:

Error: The operator '[]' isn't defined for the class 'int'.
[ +6 ms] Try correcting the operator to an existing operator, or defining a '[]' operator.
[ ] factory.first((json['integer'] as int)['value']));

A part of the generated code (dart):

switch (discriminator) {
      case 'integer':
        return blaBlaMyValue._(
            factory.first((json['integer'] as int)['value']));
      case 'double':
        return blaBlaMyValue._(
            factory.second((json['double'] as double)['value']));
      case 'pressureObservationValue':

When I manually remove ['value'] compilation is successful.

What am I doing wrong? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions