Created with <3 with dartpad.dev.
Last active
November 7, 2023 20:44
-
-
Save stobix/21b673331d8bb88349b0d6085227d4ca to your computer and use it in GitHub Desktop.
Nullable dart bug
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
void main() { | |
String? x = test(null); | |
String y = test("a"); | |
} | |
A test<A extends Object?>(A a) => | |
switch((A,a.runtimeType)){ | |
(String,Null) => (){print("found miscasted nullable string"); return a;}(), | |
(String,_) => (){print("found non-null string"); return a;}(), | |
(String?,_) => (){print("found nullable string"); return a;}(), | |
(Type(),_) => (){print("failed to find nullable string for $A, " | |
"which" | |
" ${A is String? "is":"isn't"} String, " | |
"${A is String? "is":"isn't"} String?, " | |
" ${null is A ? "is": "isn't"} null," ); return a;}(), | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment