Skip to content

Commit

Permalink
[struct-init] Ignore non-physical fields. (#11662)
Browse files Browse the repository at this point in the history
  • Loading branch information
Apprentice-Alchemist authored and kLabz committed Jun 28, 2024
1 parent e17d099 commit 1d01a83
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/typing/typeloadFields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ let ensure_struct_init_constructor ctx c ast_fields p =
let params = extract_param_types c.cl_params in
let ethis = mk (TConst TThis) (TInst(c,params)) p in
let doc_buf = Buffer.create 0 in
let args,el,tl = List.fold_left (fun (args,el,tl) cf -> match cf.cf_kind with
| Var { v_write = AccNever } -> args,el,tl
| Var _ ->
let args,el,tl = List.fold_left (fun (args,el,tl) cf -> if is_physical_var_field cf then
let has_default_expr = field_has_default_expr cf.cf_name in
let opt = has_default_expr || (Meta.has Meta.Optional cf.cf_meta) in
let t = if opt then ctx.t.tnull cf.cf_type else cf.cf_type in
Expand Down Expand Up @@ -245,7 +243,7 @@ let ensure_struct_init_constructor ctx c ast_fields p =
Buffer.add_string doc_buf "\n";
end;
(v,None) :: args,e :: el,(cf.cf_name,opt,t) :: tl
| Method _ ->
else
args,el,tl
) ([],[],[]) (List.rev c.cl_ordered_fields) in
let el = match super_expr with Some e -> e :: el | None -> el in
Expand Down
27 changes: 27 additions & 0 deletions tests/misc/projects/Issue11661/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@:structInit
class Foo {
@:isVar public var real(get, set):String;
public var foo(get, never):String;
public var bar(get, set):String;

function get_real()
return real;

function set_real(v)
return real = v;

function get_foo()
return "foo";

function get_bar()
return "bar";

function set_bar(v)
return v;
}

function main() {
var foo:Foo = {
real: "real"
};
}
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11661/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-m Main
--interp

0 comments on commit 1d01a83

Please sign in to comment.