Skip to content

dart2js generates error when using types as keys in a const map. #23009

Closed
@stereotype441

Description

@stereotype441

The following source code compiles and runs without error on the VM:

import "package:expect/expect.dart";
main() {
  const m = const { dynamic: 1, int: 2 };
  Expect.equals(1, m[dynamic]);
  Expect.equals(2, m[int]);
}

But with dart2js it produces the compile-time error "Const-map key type 'TypeImpl' overrides 'operator =='."

I believe the VM behavior is correct. Since the definition of the class "Type" in the SDK is:

  abstract class Type {}

it is reasonable for the user to expect that they can use Type objects as keys in constant maps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions