Skip to content

Instantly share code, notes, and snippets.

@osa1
Last active January 20, 2023 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osa1/fcf53af20733034550222490d4eb5855 to your computer and use it in GitHub Desktop.
Save osa1/fcf53af20733034550222490d4eb5855 to your computer and use it in GitHub Desktop.
Strange Dart 7
// Almost by definition, if I'm able to pass X where Y is expected, then X is a
// subtype of Y.
//
// In Dart, this mostly holds, but `dynamic` is an exception. I can pass
// `dynamic` everywhere, but it's not really a subtype of anything.
void f(int a) {}
class C<A> {}
void g<A>(C<A> a) {}
void main() {
dynamic x = 123;
f(x); // type checks
C<dynamic> y = C();
g<int>(y); // type error: C<dynamic> can't be assigned to C<int>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment