Skip to content

Is switch on .runtimeType valid? #30257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leafpetersen opened this issue Jul 25, 2017 · 2 comments
Closed

Is switch on .runtimeType valid? #30257

leafpetersen opened this issue Jul 25, 2017 · 2 comments

Comments

@leafpetersen
Copy link
Member

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

@sigmundch
Copy link
Member

This has come up a few times in the past - @floitschG has a lot of additional context, @rakudrama had a proposal on how to fix this in dart2js.

See these older issues describing the underlying problem:
#17123
#17207
#21553

Note in particular discussions about canonicalization of generic types, and ideas about treating raw vs generic types differently in the dart2js implementation.

@leafpetersen
Copy link
Member Author

Closing in favor of #21553 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants