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
improve error message "type 'A' is not a subtype of type 'A'" #14353
Comments
This comment was originally written by @Fox32 I get similar warnings that I suspect to be caused by different imports. The improved message would also be nice for: 'The argument of type A cannot be assigned to the parameter type A' |
Fixed in r r31621 Set owner to @sgmitrovic. |
This comment was originally written by yu.asakus...@gmail.com I am afraid that the original issue reported here has not been fixed, although some variant of it may have been fixed. Dart Editor version 1.2.0.edge_031904 Testcase: === typeerror/bin/typeerror.dart === import 'data.dart'; === typerror/bin/data.dart === import 'package:typeerror/myclass.dart'; === typeerror/lib/myclass.dart === library typeerror.myclass; === Actual results === In the Problems window in Dart Editor: When executed: Neither message clarifies that the two types mentioned in the message are different. The problem here is that from the compiler’s point of view, the library names such as typeerror.myclass do not uniquely identify a library; in the example above, package:typeerror/myclass.dart and file:///home/user/dart/typeerror/lib/myclass.dart are different libraries which have the same name typeerror.myclass. As far as I know, the only way to uniquely identify a library in Dart is the absolute URI of (the main compilation unit of) the library. Also note that the two types do not have to have the same name for this issue to arise. It is possible that the programmer intended to assign a value of type D to a variable of its superclass C, where the file defining C and D is imported twice as different libraries. |
Added Accepted label. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
I just hit this issue (the original one that fails on importing the same fila via different schemes as one source). I'm on Dart 1.21.0. It only happens in checked mode (which is what IntelliJ WebStorm uses when you run a file). I made a StackOverflow question out of it so that people at least get some information on how to deal with this on their end. But we really should fix it. It's confusing and looks bad. In case you need a test case, I'll provide it. |
Assigning to you, @kevmoo, because you were the last person acting on this bug. |
@filiph It's on the VM's hopper – and I'm not going to be able to fix it. 😬 |
I believe @crelier fixed this at some point. |
This should be a simple fix, but it would really help users diagnose and fix errors.
I've hit this error many times where both types are named exactly the same. The most common scenario when this happens is a canonicalization bug: I have 2 imports to the same library, but one uses "package:" and the other uses a file:// URL, and because of that they are resolved as separate libraries.
Maybe we could change the message so that when both types have the same name, we can also include some extra information about it. For example, instead of:
type 'A' is not a subtype of type 'A'
we could say:
type 'A' is not a subtype of type 'A'
- the first definition is from 'package:foo/bar.dart'
- the second definition is from 'file:///a/b/c/packages/foo/bar.dart'
The text was updated successfully, but these errors were encountered: