Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Erroneous fatal error about interfaces duplicated in the supertype graph #3803

Closed
lexprfuncall opened this issue Jun 20, 2012 · 7 comments
Closed
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Milestone

Comments

@lexprfuncall
Copy link

Consider the following code:

interface Interface<T> {
  T m();
}

abstract class A implements Interface {
}

class C extends A implements Interface<int> {
  int m() => 0;
}

The analyzer fails with the following error

file:/usr/local/google/home/cshapiro/dart-all/dart/darta.dart:8: Interface<int> and Interface<<dynamic>> are duplicated in the supertype graph
     7:
     8: class C extends A implements Interface<int> {
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation failed with 1 problem.

We believe no such prohibition exists and this should not be an error.

@DartBot
Copy link

DartBot commented Jun 21, 2012

This comment was originally written by zundel@google.com


I don't know the history of this message, it might be being accidentally triggered for another important case, but if this is valid, it makes me ask, are there rules about this situation in general as far as warnings are concerned that we should follow?

A slight variation:

interface Interface<T> {
  T m(T arg);
}
abstract class A implements Interface<String>;
class C extends A implements Interface<Int> {
  int m() => 0;
}

C instanceC = new C();
A instanceA = instanceC;
String a = instanceC.m();
String a = instanceA.m();

This creates a way around two unassignable types with no warnings.

Looking at the spec for guidance, I see we should generate warnings if we tried to use overrides on individual members. If its not supposed to be in the spec, maybe the analyzer could do a 'value add' warning.


Removed the owner.
Added this to the M1 milestone.
Added Triaged label.

@gbracha
Copy link
Contributor

gbracha commented Jun 21, 2012

The implicit interface of C has as superinterfaces:

The implicit interface of A
Interface<int>
Interface<String>

C has method m() whose name is "m". The superinterfaces Interface<int> and Interface<String> both declare methods with name "m", and so the interface of C overrides them (per 8.5.1). The override is a compile-time erro per 8.1 because the number of required parameters differs.

Perhaps you meant to write

interface Interface<T> {
  T m();
}

In this case, C's m overrides Interface<int>'s m correctly, but a warning will be issued for the attempt to override Interface<String>.

Now, consider

interface Interface<T> {
  m();
}

this one is interesting. The overrides are both legal. But of course now there is no contradiction.

@lexprfuncall
Copy link
Author

Marked this as blocking #2136.

@DartBot
Copy link

DartBot commented Jun 21, 2012

This comment was originally written by zundel@google.com


In this case, C's m overrides Interface<int>'s m correctly, but a warning will be
issued for the attempt to override Interface<String>.

I don't think it is sufficient to say to look at the override rules to determine how to warn for this issue.

First of all, is this a case of a problem in a method override? The class C clearly states it is implementing Interface<int>, and int m() matches the signature of that method exactly, so that doesn't sound like an override. Flagging this on m() will be very confusing, especially considering that every method define in Interface that references the type parameter would trigger this warning. What's more, changing the method signature to:

String m();

wouldn't fix it either, would it?

I see this issue is blocking progress, I'll take the compile error and do something better.


Set owner to zundel@google.com.

@DartBot
Copy link

DartBot commented Jun 22, 2012

This comment was originally written by zundel@google.com


Issue #2495 has been merged into this issue.

@DartBot
Copy link

DartBot commented Jun 22, 2012

This comment was originally written by zundel@google.com


https://chromiumcodereview.appspot.com/10627017

In the code originally in the bug report, the analyzer is now silent.

but in this variant, it emits warnings:

interface Interface<T> {
  T m();
}
abstract class A implements Interface<String> {
}
class C extends A implements Interface<int> {
  int m() => 0;
}

file:/tmp/t.dart:8: cannot override m of Interface because () -> int is not a subtype of () -> String
     7: class C extends A implements Interface<int> {
     8: int m() => 0;
file:/tmp/t.dart:7: Class inherits two variations of the same interface 'Interface<int>' and 'Interface<String>' with parameters that are not assignable to each other.
     6: }
     7: class C extends A implements Interface<int> {

The latter message is at the 'info' level and shouldn't trigger any unit tests.


Added Started label.

@DartBot
Copy link

DartBot commented Jun 22, 2012

This comment was originally written by zundel@google.com


r9035


Added Fixed label.

@lexprfuncall lexprfuncall added Type-Defect area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Jun 22, 2012
@lexprfuncall lexprfuncall added this to the M1 milestone Jun 22, 2012
This issue was closed.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

3 participants