class NullableStringHolder {
public var s : Null<String>;
public function new(s : Null<String>) {
// safeApi generates non-null check (for more details see Bug14)
this.s = s;
}
}
class TypedHolder<T> {
public var v : T;
public function new(v : T) {
// safeApi generates non-null check, even when T is Null<...> (for more details see Bug14)
this.v = v;
}
}
class Bug14 {
// Generated code (js target):
//
// bug: function(s) {
// var this1 = s;
// if(this1 == null) {
// throw new js__$Boot_HaxeError(new safety_IllegalArgumentException("Null is not allowed for argument " + "s" + " in " + "safetybugs.Bug14" + "." + "bug" + "()"));
// }
// if(s != null) {
// haxe_Log.trace(s.length,{ fileName : "safetybugs/Main.hx", lineNumber : 206, className : "safetybugs.Bug14", methodName : "bug"});
// }
// }
//
// `s` CAN be null, but safeApi still generates non-null check.
public function bug(s : Null<String>) : Void {
if (s != null) {
trace(s.length);
}
}
}
See https://github.com/restorer/haxe-safety-bugs/blob/master/safetybugs/Main.hx#L182 for working example.