Skip to content

Commit 6d5db24

Browse files
fixed typing of rest args against type parameters (closes #10124)
1 parent 2157ce7 commit 6d5db24

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

extra/CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
all : fixed compiler compatibility with OS X 10.13 (#10110)
1212
all : fixed compiler hanging on `switch` for abstracts with implicit casts involving type parameters and constraints (#10082)
1313
all : fixed inlining of `haxe.DynamicAccess.keyValueIterator` (#10118)
14+
all : fixed rest arguments typing against type parameters (#10124)
1415
analyzer : fixed side effect handling for enums (#10032)
1516
cpp : fixed handling of `cpp.ConstCharStar` with analyzer enabled (#9733)
1617
php : fixed failure with trailing slash in output dir (#6212)

src/typing/callUnification.ml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,30 @@ let rec unify_call_args ctx el args r callp inline force_inline in_overload =
106106
in
107107
(* these platforms deal with rest args on their own *)
108108
if ctx.com.config.pf_supports_rest_args then
109+
let type_rest t =
110+
List.map (fun e ->
111+
match e with
112+
| (EUnop (Spread,Prefix,_),p) -> unexpected_spread p
113+
| _ -> type_against name (t()) e
114+
) el
115+
in
109116
match el with
110117
| [(EUnop (Spread,Prefix,e),p)] ->
111118
(try [mk (TUnop (Spread, Prefix, type_against name t e)) t p]
112119
with WithTypeError(ul,p) -> arg_error ul name false p)
120+
| _ when ExtType.is_mono (follow arg_t) ->
121+
(try
122+
let el = type_rest mk_mono in
123+
try
124+
Type.unify arg_t (unify_min ctx el);
125+
el
126+
with Unify_error _ ->
127+
die ~p:callp "Unexpected unification error" __LOC__
128+
with WithTypeError(ul,p) ->
129+
arg_error ul name false p)
113130
| _ ->
114131
(try
115-
List.map (fun e ->
116-
match e with
117-
| (EUnop (Spread,Prefix,_),p) ->
118-
unexpected_spread p
119-
| _ -> type_against name arg_t e
120-
) el
132+
type_rest (fun() -> arg_t)
121133
with WithTypeError(ul,p) ->
122134
arg_error ul name false p)
123135
(* for other platforms make sure rest arguments are wrapped in an array *)

tests/unit/src/unit/issues/Issue10124.hx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,13 @@ class Issue10124 extends Test {
2828
arr.addFloat(5, 6, 7);
2929
Assert.same([1, 3, 4, 5, 6, 7], arr);
3030
}
31+
32+
function test3() {
33+
function rest<T>(...values:T):Array<T> {
34+
return values.toArray();
35+
}
36+
var a = rest(5, 6.2, 7);
37+
aeq([5, 6.2, 7], a);
38+
eq('Array<Float>', HelperMacros.typeString(a));
39+
}
3140
}

0 commit comments

Comments
 (0)