Skip to content

Fix accessor class lookup for write too #12272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
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
8 changes: 7 additions & 1 deletion src/typing/operators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,13 @@ let type_assign ctx e1 e2 with_type p =
assign_to e1
| AKAccessor fa ->
let c,stat = match fa.fa_host with
| FHInstance(c,tl) -> Some c,false
| FHInstance(c,tl) ->
(* c refers to the host of the field, let's find the class we're actually accessing on *)
let c = match follow fa.fa_on.etype with
| TInst(c,_) -> c
| _ -> c
in
Some c,false
| FHStatic c -> Some c,true
| FHAbstract(a,tl,c) -> Some c,true
| _ -> None,false
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/src/unit/issues/Issue12259.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import unit.issues.misc.issue12259.Element;
@:access(unit.issues.misc.issue12259.Element)
class Issue12259 extends unit.Test {
public function test() {
eq(true, new Element().foo);
var elt = new Element();
eq(true, elt.foo);
eq(true, elt.foo = false);
}
}
5 changes: 4 additions & 1 deletion tests/unit/src/unit/issues/misc/issue12259/Entity.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package unit.issues.misc.issue12259;
class Entity {
function new() {}

var foo(get, never):Bool;
var foo(get, set):Bool;

function get_foo():Bool
return true;

function set_foo(b : Bool):Bool
return true;
}
Loading