Skip to content

In generics a restricted parameterized type behaves like dynamic if not specified #26778

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

Closed
fromlabs opened this issue Jun 28, 2016 · 2 comments

Comments

@fromlabs
Copy link

I know that parameterized type is optional and that for example List is a shorthand for List<dynamic> but when I declare a class with a parameterized type?

I think that the following example is a bug:

abstract class NumList<T extends num> implements List<T> {
}
abstract class DefNumList implements NumList<num> {
}
main() {
  NumList<num> numList;
  numList.add("10"); // ERROR
  numList.add(10); // OK

  NumList numList2;
  numList2.add("10"); // OK??? why, the base parameterized type is num not dynamic...
  numList2.add(10); // OK

  DefNumList numList3;
  numList3.add("10"); // ERROR
  numList3.add(10); // OK
}
@zoechi
Copy link
Contributor

zoechi commented Jun 28, 2016

For standard Dart this is as designed.

For strong mode see #26310

@fromlabs
Copy link
Author

Thanks Günter, I haven't looked yet at the strong mode documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants