Skip to content

Instantly share code, notes, and snippets.

View stobix's full-sized avatar

Joel Ericson stobix

View GitHub Profile
@stobix
stobix / main.dart
Created November 7, 2023 20:07
Nullable dart bug
void main() {
String? x = test(null);
}
A test<A>(A a) =>
switch((A,a.runtimeType)){
(String,Null) => (){print("found nullable string"); return a;}(),
(String,_) => (){print("found nullable string"); return a;}(),
(String?,_) => (){print("found nullable string"); return a;}(),
(Type(),_) => (){print("failed to find nullable string for $A"); return a;}(),
};
@stobix
stobix / main.dart
Last active November 7, 2023 20:44
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;}(),