Skip to content

Too many errors when using const identifier in constructor initializer #44283

Open
@Naomi-alt

Description

@Naomi-alt

Not sure whether this is the right place for the issue, so tell me if I'm in the wrong place.
Version: Dart SDK version: 2.12.0-29.10.beta (beta) (Tue Nov 17 10:50:22 2020 +0100) on "linux_x64"

I have this class that I want to initialize using named parameters, and using those parameters I create the final variable in the initialization list.
But whatever I try, it doesn't seem to work. I have it narrowed down to the following example:

class Class1 {
  const Class1({this.variable});

  final int variable;
}

class Class2 {
  const Class2({
    int variable,
  }) : class1 = const Class1(variable: const variable);

  final Class1 class1;
}

But when creating the class1 I'm getting the following error:
The constructor returns type 'dynamic' that isn't of expected type 'int'.
When I remove the const however, I get this:
Invalid constant value.

What am I missing here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4analyzer-recoveryarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-error-recoveryError recovery in analyzer/CFE.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions