Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

generic methods should be able to override non-generic ones. #459

Closed
@jmesserly

Description

@jmesserly

Split from #301. Something like this should be supported (or we need to explicitly disallow it):

class B {
  Iterable map(f(x)); // (* -> *) -> Iterable<*>
}
class D extends B {
  Iterable<T> map<T>(T f(x)); // <T>(* -> T) -> Iterable<T>
}

See comments starting from #301 (comment).

Normally the subtyping relation is fine, because implicit instantiation can be generated as an explicit instantiation in the generated JavaScript. However for a method override, we don't have any way to express that. It'd be a little unfortunate if all generic method calls used a different calling convention, but perhaps it's unavoidable.

Activity

Andersmholmgren

Andersmholmgren commented on Feb 22, 2016

@Andersmholmgren

I am already hitting this in the wild. As the annotations are missing on the Iterable methods of the collections package, those methods are not considered to be overriding those in the core dart package. So I get warnings for them

jmesserly

jmesserly commented on Feb 22, 2016

@jmesserly
ContributorAuthor

Ah, that sounds like the reverse problem:

class B {
  Iterable<T> map<T>(T f(x));// <T>(* -> T) -> Iterable<T>
}
class D extends B {
  Iterable map(f(x)); 
}

Having a non-generic override a generic is not allowed in either strong or normal mode. If you think about it, it's kind of like optional arguments. You can add optional parameters in a subtype, but you can't take parameters away:

class B {
  m(x, y) { ... }
}
class D extends B {
  m(x) { ... } // error
}

The short term fix is to annotate the collections package.

We've discussed doing inference. Given my first example, we could conclude that D.map needs a type parameter, which would make it D.map<T>. However the return type of Iterable<dynamic> is also problematic, unless we can conclude it too should be Iterable<T>. But we're unsure if this kind of inference is a good idea, as it's sort of analogous to inferring a missing function parameter :)

jmesserly

jmesserly commented on Sep 13, 2016

@jmesserly
ContributorAuthor

This issue was moved to dart-lang/sdk#27334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Andersmholmgren@jmesserly

        Issue actions

          generic methods should be able to override non-generic ones. · Issue #459 · dart-archive/dev_compiler