Project Information
- Repository: https://github.com/dart-lang/sdk
- Project Name: Dart Programming Language SDK
- Publisher (if applicable): Google
Expected behavior
A Type should be usable as the defined type throughout entire application regardless of the import method. For instance, If I create a class called Test
then I should be able to use Test
inside any file in my Dart and/or Flutter project where Test
is needed; specifically as a parameter in a constructor for another class.
Actual behavior
The Dart Analyzer and compiler doesn't know that Type Test
is a Type of Test
because it seems to think that the instance of Test
in the new file is a different Test
Object then the original defined Test
Type.
When using this imported Type (Test
) in an Object Constructor the analyzer will throw back this error message: Error: [dart] The argument type 'A (<project-path>)' can't be assigned to the parameter type 'A (<project-path>)'.
On JIT compilation, the compiler will throw back this error:
A value of type '#lib1::A' can't be assigned to a variable of type '#lib2::A'. Try changing the type of the left hand side, or casting the right hand side to '#lib2::A'.
How to reproduce
Error Occurs on both the latest Flutter Master SDK: Dart 2.0.0-dev.54.0.flutter-46ab040e58
and on the latest Dart Dev SDK build: 2.0.0-dev.55.0 compiler
Tools used: Visual Studio Code, Dart-Code Visual Studio Code plugin, Flutter's Dart 2.0.0-dev.54.0.flutter-46ab040e58
and Dart's 2.0.0-dev.55.0 compiler
.
Operating System: Windows (though this seems to be OS agnostic).
Steps to reproduce:
Step 1: Create three files inside of a Dart project (in the
lib/
folder) each with a custom Class declaration. For example:a.dart
withclass A {}
,b.dart
withclass B{}
andc.dart
withclass C {}
. See this gist for more informationStep 2: In one of the classes, create an instance variable of one of the other classes and pass it to the class constructor.
- Step 3: In one of the other empty classes import the other two classes, one by package and the other one by relative path.
- Step 4: Try to instantiate the two classes inside of this new class, with the constructor made in step 2, either by making an instance variable before passing it to the constructor or by directly instantiating the variable into the constructor.
- Step 5: Optional Step: to see compilation error, create a flutter project follow the steps for steps in the
lib/
folder this time however, usemain.dart
in place ofc.dart
for parts 3 and 4. On compilation of the project you will receive an error (which will stop compilation) and the analyzer will also report the error mentioned above.
Notes:
Error was reported as issue #33149 of the Dart SDK GitHub repository. Issue was originally linked to #33076 however, because issue occurs even without an entry point or main.dart
file with a main(){}
function inside of it, issue was determined to be unique. The area-analyzer
tag was applied to this issue by PO.