Last active
January 20, 2023 09:43
-
-
Save osa1/fcf53af20733034550222490d4eb5855 to your computer and use it in GitHub Desktop.
Strange Dart 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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