Analyzer Type Mismatch Error based on Import Method - Dart SDK

in #utopian-io6 years ago (edited)

Project Information

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 with class A {}, b.dart with class B{} and c.dart with class C {}. See this gist for more information

  • Step 2: In one of the classes, create an instance variable of one of the other classes and pass it to the class constructor.

class-a.png

  • Step 3: In one of the other empty classes import the other two classes, one by package and the other one by relative path.

imports.png

  • 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.

error.png

  • Step 5: Optional Step: to see compilation error, create a flutter project follow the steps for steps in the lib/ folder this time however, use main.dart in place of c.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.

error-report.png

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.

Recording Of The Bug

GitHub Account

https://github.com/tensor-programming

Sort:  

Hello @tensor,
This post was marvellous. Everything from Gists to screenshots to proper explanation of the bug was included in this post. The fact that you notified the PO and the severity of the bug was verified makes this post perfect for Staff-picks. Congratulations you have gotten a Full score and staff-picked by me.
Keep Contributing such great work!!
Thank you
Your contribution has been evaluated according to Utopian rules and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post,Click here


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for moderating my contribution. Hopefully, I will have more bugs to submit in the future.

Hi, I'm just passing by in your account and I wanna say thank you for the upvote of one of my posts... 😊

Hey @tensor
Thanks for contributing on Utopian.
Congratulations! Your contribution was Staff Picked to receive a maximum vote for the bug-hunting category on Utopian for being of significant value to the project and the open source community.

We’re already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.031
BTC 61882.63
ETH 2581.51
USDT 1.00
SBD 2.56