Skip to content

[enhanced-enums] A value declaration is a constant context #48232

Open
@eernstg

Description

@eernstg

Consider the following program:

enum E {
    v([]); // No error.
  const E(_);
}

The program uses --enable-experiment=enhanced-enums. It does not have any errors, in particular, [] can be used as an actual argument because the spec has:

where args are considered as occurring in a const context, ...

However, the CFE reports an error at [] (two, actually):

n017.dart:2:7: Error: Constant expression expected.
Try inserting 'const'.
    v([]);
      ^
n017.dart:2:7: Error: Non-constant list literal is not a constant expression.
    v([]);
      ^

The analyzer rejects the program as follows:

ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER|/usr/local/google/home/eernst/lang/dart/scratch/202201/n017.dart|3|9|1|A constant constructor can't call a non-constant super constructor of 'Enum'.

which means that the analyzer may or may not have the same fault, but we don't get to see it because we encounter an error with the Enum constructor (which could be a fault in the analyzer, or in the declaration of Enum, or both).

So we have at least one platform where there is a need to make this change: An enum value declaration is a constant context.


Subtasks:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-metaCross-cutting, high-level issues (for tracking many other implementation issues, ...).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