Skip to content

Commit

Permalink
[java,cs] fix stack overflow from closures constraints (#11350)
Browse files Browse the repository at this point in the history
* [java,cs] revert some change from 7863

* [tests] add test for stack overflow
  • Loading branch information
kLabz committed Nov 14, 2023
1 parent 2c671fb commit 08bb8c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/codegen/gencommon/closuresToClass.ml
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,8 @@ let traverse gen ?tparam_anon_decl ?tparam_anon_acc (handle_anon_func:texpr->tfu

let rec get_type_params acc t =
match t with
| TInst(( { cl_kind = KTypeParameter constraints } as cl), []) ->
let params = List.fold_left get_type_params acc constraints in
List.filter (fun t -> not (List.memq t acc)) (cl :: params) @ acc;
| TInst(( { cl_kind = KTypeParameter _ } as cl), []) ->
if List.memq cl acc then acc else cl :: acc
| TFun (params,tret) ->
List.fold_left get_type_params acc ( tret :: List.map (fun (_,_,t) -> t) params )
| TDynamic None ->
Expand Down
10 changes: 10 additions & 0 deletions tests/misc/cs/projects/Issue11350/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Main {
public static function main() {}

public static function forComparable<T : Comparable<T>>(): T->T->Void
return (a: T, b: T) -> {}
}

typedef Comparable<T> = {
public function compareTo(that : T) : Int;
}
3 changes: 3 additions & 0 deletions tests/misc/cs/projects/Issue11350/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--main Main
-cs bin
-D net-ver=45

0 comments on commit 08bb8c1

Please sign in to comment.