Skip to content

Enum mixin not used as runtime Type #51730

Closed
@felipeuematsu

Description

@felipeuematsu

When we have an Enum class that implements a mixin, the analyzer will accept any uses of that enum as it would any class, but when tried to run the code, the compiler will complain something along the lines of

Error: A value of type 'Enum?' can't be assigned to a variable of type 'LinkEnum?'.

Even if the variable was originally of LinkEnum,

Casting the variable to LinkEnum works, but raises an unnecessary_cast warning.

Example code below:

mixin LinkEnum on Enum {
  String get link;
}

enum Websites implements LinkEnum {
  google('google.com')
  ;
  const Websites(this.link);
  final String link;
}

Dart SDK version: 2.18.4 (stable) (Tue Nov 1 15:15:07 2022 +0000) on "macos_arm64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions