Skip to content

Instantly share code, notes, and snippets.

@gabrielgarciagava
Last active June 21, 2023 08:59
Show Gist options
  • Save gabrielgarciagava/61a4d13af42ac7e6749333728587fa08 to your computer and use it in GitHub Desktop.
Save gabrielgarciagava/61a4d13af42ac7e6749333728587fa08 to your computer and use it in GitHub Desktop.
Generics infer issue
void main() {
// This works fine
// final Base myImpl = Impl();
// This creates a compilation error in line 10
final myImpl = Impl();
final myGenerics = buildGenerics(myImpl);
print(myGenerics.value == myImpl);
print(foo(myGenerics, myImpl));
}
Generics<Base> buildGenerics(Base s) => Generics(s);
bool foo<G extends Generics<V>, V>(G g, V v) {
return g.value == v;
}
class Generics<T> {
Generics(this.value);
T value;
}
class Base {}
class Impl implements Base {
const Impl();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment