Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/tUnification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,11 @@ let rec unify (uctx : unification_context) a b =
| TEnum (ea,tl1) , TEnum (eb,tl2) ->
if ea != eb then error [cannot_unify a b];
unify_type_params uctx a b tl1 tl2
| TAbstract ({a_path=[],"Null"},[t1]), TAbstract ({a_path=[],"Null"},[t2]) ->
(* Unify the wrapped types directly so a monomorph on either side binds to the
unwrapped type instead of capturing the whole Null<...> - see #11077 *)
begin try unify uctx t1 t2
with Unify_error l -> error (cannot_unify a b :: l) end
| TAbstract ({a_path=[],"Null"},[t]),_ ->
begin try unify uctx t b
with Unify_error l -> error (cannot_unify a b :: l) end
Expand Down
15 changes: 15 additions & 0 deletions tests/nullsafety/src/cases/TestTypeParameters.hx
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,18 @@ class TestDeepTypeParams {
});
}
}

// Inlining a generic function returning Null<T> must not bind the inline
// type-param monomorph to Null<Int> instead of Int.
@:nullSafety
class TestInlineGenericReturn {
static function main() {
final arr = [1, 2, 3];
iter(arr, item -> true);
}

static inline function iter<T>(it:Array<T>, callback:(item:T) -> Bool):Null<T> {
for (v in it) callback(v);
return null;
}
}
Loading