Skip to content
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

Closed
sigmundch opened this issue Oct 23, 2013 · 10 comments
Closed

improve error message "type 'A' is not a subtype of type 'A'" #14353

sigmundch opened this issue Oct 23, 2013 · 10 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@sigmundch
Copy link
Member

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'

@DartBot
Copy link

DartBot commented Oct 23, 2013

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'
and
'A value of type A cannot be assigned to a variable of type A'

@ghost
Copy link

ghost commented Jan 14, 2014

Fixed in r r31621


Set owner to @sgmitrovic.
Added Fixed label.

@DartBot
Copy link

DartBot commented Jan 17, 2014

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
Dart SDK version 1.2.0-edge.31903
obtained from
http://storage.googleapis.com/dart-archive/channels/be/raw/latest/editor/darteditor-windows-x64.zip

Testcase:

=== typeerror/bin/typeerror.dart ===

import 'data.dart';
import '../lib/myclass.dart';
void main() {
  A myVar = myA;
}

=== typerror/bin/data.dart ===

import 'package:typeerror/myclass.dart';
A myA = new A();

=== typeerror/lib/myclass.dart ===

library typeerror.myclass;
class A {}

=== Actual results ===

In the Problems window in Dart Editor:
A value of type 'A' cannot be assigned to a variable of type 'A'
(on line 4 of typeerror.dart)

When executed:
Unhandled exception:
type 'typeerror.myclass.A' is not a subtype of type 'typeerror.myclass.A' of 'myVar'.

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.

@ghost
Copy link

ghost commented Jan 17, 2014

Added Accepted label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@sigmundch sigmundch added Type-Enhancement area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. labels Aug 4, 2014
@sigmundch sigmundch assigned ghost Aug 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed accepted labels Feb 29, 2016
@filiph
Copy link
Contributor

filiph commented Dec 12, 2016

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.

@filiph filiph assigned kevmoo and unassigned ghost Dec 12, 2016
@filiph
Copy link
Contributor

filiph commented Dec 12, 2016

Assigning to you, @kevmoo, because you were the last person acting on this bug.

@kevmoo kevmoo removed their assignment Dec 12, 2016
@kevmoo
Copy link
Member

kevmoo commented Dec 12, 2016

@filiph It's on the VM's hopper – and I'm not going to be able to fix it. 😬

@rmacnak-google
Copy link
Contributor

I believe @crelier fixed this at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants