Skip to content

Mixin class with instance field, bad CFE error message #61720

@lrhn

Description

@lrhn

For the following code:

void main() {
  print(E.e.value);
}

mixin class WithConstant {
  const WithConstant();
  final value = 42;
}

enum E with WithConstant {e}

I get the following errors:

  • Analyzer: "Mixins applied to enums can't have instance variables."
  • CFE: "A constant constructor can't call a non-constant super constructor."

The CFE is tecnnically correct. The mixin application of WithConstant introduces a non-constant forwarding constructor when the mixin has an instance variable, and then the superclass of E has a non-constant constructor.

It's not very understandable, though. The error message is a few steps away from the thing you can actually change: Removing the field or not mixing in the mixin.
The analyzer message is more directly actionable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-messagesPoor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions