-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Minification interferes with generic functions #38005
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
Comments
@jodinathan on Gitter mentioned that this code shouldn't work at all and that I should instead use if statements to achieve the same. His solution worked and now I'm using a lot of if statements instead of a large switch statement. However, if this isn't supposed to work anyway, why does it work without minification and throws an error if I use minification? |
FYI - @fishythefish @rakudrama - missing tracking on direct type var use? |
class MyClass {}
void foo<T>() {
switch (T) {
case MyClass:
print("MyClass");
return;
default:
print("other");
return;
}
}
void main() {
foo<MyClass>();
} This currently prints main: function() {
switch (new H.TypeImpl(V.MyClass)) {
case C.Type_MyClass_GMm:
P.print("MyClass");
break;
default:
P.print("other");
break;
}
} You can see that This issue will be fixed when the new dart2js RTI rolls out, since we canonicalize RTI objects. |
As @fishythefish points out, the root cause is that type objects are not canonicalized by dart2js and therefore, types are not supported in switch cases except on some simple cases where all values are type literals. There use to be an error reported for this in the past, but a recent bug made us not show the compile-time error. We have a duplicate issue filed under #17207 with details about the underlying problem. I'm going to keep that one open and close this one as a duplicate, but if we are missing something detail that we should be tracking, please let us know. |
Although this issue will eventually be fixed by the new type representation that we are currently working on, we should make sure that there is test coverage of the use case reported here. Re-close after the test coverage is confirmed or implemented. |
This tracker is for issues related to:
dart2js
Dart SDK Version (
dart --version
)2.4.1
TLDR:
Minification changes generic type names which could lead to problems if they're hardcoded.
Example code:
Proposed solution:
Don't minify generic type names.
Are there any workarounds? I've tried using enums but it doesn't work like Typescript..
The text was updated successfully, but these errors were encountered: