Skip to content

Is switch on .runtimeType valid? #30257

Closed
@leafpetersen

Description

@leafpetersen

This code:

class  A {}

void main() {
  var x = new A();
  switch (x.runtimeType) {
    case A: print("hello");
  }
}

Is accepted by the analyzer, and runs on the VM and DDC with no errors. Dart2js rejects it with the following error:

leafp-macbookpro:sdk leafp$ rundart.sh dart2js -o test.js ~/tmp/test.dart
../../../tmp/test.dart:6:10:
Error: 'case' expression type 'TypeImpl' overrides 'operator =='.
    case A: print("hello");
         ^
Error: Compilation failed.

Is this valid code and dart2js is buggy here, or is this invalid code that should be rejected statically or dynamically?

cc @sigmundch @lrhn @munificent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions