Skip to content

Commit

Permalink
[typer] inherit some metadata to generic implementation class
Browse files Browse the repository at this point in the history
closes #10557, closes #10550
  • Loading branch information
Simn committed Jan 19, 2022
1 parent bfd518a commit d1a2bd1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/typing/generic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ let rec build_generic ctx c p tl =
} in
gctx.mg <- Some mg;
let cg = mk_class mg (pack,name) c.cl_pos c.cl_name_pos in
cg.cl_meta <- List.filter (fun (m,_,_) -> match m with
| Meta.Access | Allow
| Final
| Hack
| Internal
| Keep
| NoClosure | NullSafety
| Pure
| Struct | StructInit
| Using ->
true
| _ ->
false
) c.cl_meta;
cg.cl_meta <- (Meta.NoDoc,[],null_pos) :: cg.cl_meta;
mg.m_types <- [TClassDecl cg];
Hashtbl.add ctx.g.modules mg.m_path mg;
add_dependency mg m;
Expand Down Expand Up @@ -314,8 +329,6 @@ let rec build_generic ctx c p tl =
);
TypeloadFunction.add_constructor ctx cg false p;
cg.cl_kind <- KGenericInstance (c,tl);
cg.cl_meta <- (Meta.NoDoc,[],null_pos) :: cg.cl_meta;
if has_meta Meta.Keep c.cl_meta then cg.cl_meta <- (Meta.Keep,[],null_pos) :: cg.cl_meta;
if (has_class_flag c CInterface) then add_class_flag cg CInterface;
cg.cl_constructor <- (match cg.cl_constructor, c.cl_constructor, c.cl_super with
| _, Some cf, _ -> Some (build_field cf)
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/src/unit/issues/Issue10550.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package unit.issues;

@:structInit @:publicFields
private class Tuple2<T, U> {
final _1:T;
final _2:U;

inline function new(_1:T, _2:U) {
this._1 = _1;
this._2 = _2;
}
}

@:generic
@:structInit @:publicFields
private class Tuple2Generic<T, U> {
final _1:T;
final _2:U;

inline function new(_1:T, _2:U) {
this._1 = _1;
this._2 = _2;
}
}

class Issue10550 extends Test {
function test() {
final foo:Tuple2<Int, String> = {_1: 1, _2: "abc"}; // works
final bar:Tuple2Generic<Int, String> = {_1: 1, _2: "abc"}; // doesn't work
utest.Assert.pass();
}
}

0 comments on commit d1a2bd1

Please sign in to comment.