-
-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[null safety] Possible null safety hole with structs and/or monomorphs #10147
Comments
More cases: typedef HasAString = {
text:String
}
typedef HasANullString = {
text:Null<String>
}
@:nullSafety(StrictThreaded)
class Main {
static function main() {
final has:HasAString = {text: null};
final tmp = {text: null};
final typed:HasAString = tmp;
final tmp = {text: null};
final typed:{text:String} = tmp;
final tmp = {text: null};
final arr:Array<String> = [tmp.text];
// should pass
final tmp = {text: null};
final typed:{text:Null<String>} = tmp;
final typed2:HasANullString = tmp;
final typed3:HasANullString = typed;
}
} My solution for | TObjectDecl fields ->
List.iter (fun ((name,pos,_), e) ->
begin match e.etype with
(* Field type still Unknown *)
| TMono r when r.tm_type = None -> ()
| _ ->
if not (self#can_pass_expr e e.etype e.epos) then begin
self#error ("Cannot use nullable value as an field of type " ^ (str_type e.etype)) [e.epos; pos];
end;
end;
self#check_expr e
) fields |
It happens because Haxe doesn't add |
Yep, this will solve it too. Would be nice to change typing, so as example "Left operand is not nullable" warnings can be added to null coalescing, without false positive warnings for |
I saw a post on reddit that suggested that using structs can sometimes evade the compile-time null safety checks.
I have also been able to reproduce it without the typedef, although with a more obvious intermediate
{ text : Unknown<0> }
monomorph:Oddly, the follow still isn't allowed to compile, as desired:
Related: r/haxe: Null safety in structs
Related: original example, on try-haxe
Related: other examples, on try-haxe
The text was updated successfully, but these errors were encountered: