Skip to content

Instantly share code, notes, and snippets.

@stobix
Last active November 7, 2023 20:44
Show Gist options
  • Save stobix/21b673331d8bb88349b0d6085227d4ca to your computer and use it in GitHub Desktop.
Save stobix/21b673331d8bb88349b0d6085227d4ca to your computer and use it in GitHub Desktop.
Nullable dart bug
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