Conversation
|
Can you elaborate on the issue? what do you mean the hashCode is different? |
|
For example, if in one file within the same library a class named SomeClass is imported using 'src/some_class.dart', and in another file in that library the same is imported as 'package:mylib/src/some_class.dart'; then in those two files SomeClass.hashCode (the type itself) will give two different values. |
|
That sounds like an issue with the SDK, it should be perfectly valid to import from the current package using the "package:" prefix. Since this sounds like an issue with the SDK, I would want to make sure that 1. Is this the only package that causes the problem? and 2. Can you reproduce the issue using a simple project? |
|
Yes, it's an issue with Dart, can easily be reproduced in a small project. In general you won't notice until suddenly dynamic type resolutions or looking up things by type randomly don't work. Regardless, it's not very clean to import files in two different ways, and it also complicates if someone needs to rename the package for forking purposes. |
|
Due to Flutter main() being in /lib/ folder.. c:\source\darttest\type_mismatch>dart bin/main.dart c:\source\darttest\type_mismatch>dart lib/type_mismatch.dart https://github.com/nbspou/darttest/tree/master/type_mismatch |
|
See dart-lang/sdk#33076, and issues linked from there, it's the issue that used for tracking this problem. |
|
Thanks for the clarification!
I agree, some developers prefer package: imports and some use relative. I prefer Since this is a stylistic change, and the bug you're referring to has the attention of the Dart team, I'm going to close this. If we take any action, I would prefer we switch every import to a |
Consistently import library files using relative path.
Don't use
package:imports for files within the library as it seems to cause the types to be duplicated in another namespace causing mysterious type mismatch issues (The hashCode of a type from the library itself imported through relative path vs imported using package ends up being different).