Open restorer opened 5 years ago
This is for Haxe 4.0.0-preview.5 and Safety from master.
This is an intended behavior for a typed cast: https://github.com/RealyUniqueName/Safety/blob/9dc8579041dd9121eba1825ac1b6a7124a85129a/test/cases/TestCompileTime.hx#L505-L509
However, Std.instance()
uses an untyped cast, which should ignore null safety checks: https://github.com/RealyUniqueName/Safety/blob/9dc8579041dd9121eba1825ac1b6a7124a85129a/test/cases/TestCompileTime.hx#L511-L514
Maybe Haxe typer makes them indistinguishable for the Safety plugin in case of Std.instance()
I think problem is in Std.instance signature, which is
public static function instance<T:{},S:T>( value : T, c : Class<S> ) : S;
However, documentation says:
This method checks if a downcast is possible. That is, if the runtime type of value is assignable to the class specified by c, value is returned. Otherwise null is returned.
Proper signature should be
public static function instance<T:{},S:T>( value : T, c : Class<S> ) : Null<S>;
I "fix" this by
@:safety(unsafe)
public static function instanceExt<T : {}, S : T>(value : T, c : Class<S>) : Null<S> {
return Std.instance(value, c);
}
I understand that this is something not on Safety side, but maybe you can propose this change for Haxe.
See https://github.com/restorer/haxe-safety-bugs/blob/master/safetybugs/Main.hx#L163 for working example.