@@ -93,6 +93,27 @@ def test_this_field_receiver_resolves_to_declared_type(tmp_path: Path):
9393 assert (run , gateway_charge ) in calls
9494
9595
96+ def test_this_field_uses_field_type_when_parameter_shadows_name (tmp_path : Path ):
97+ calls , result = _calls (tmp_path , {
98+ ** _AMBIGUOUS_METHODS ,
99+ "Checkout.java" : (
100+ "class Checkout {\n "
101+ " PaymentGateway service;\n "
102+ " void run(AuditLog service) {\n "
103+ " service.charge();\n "
104+ " this.service.charge();\n "
105+ " }\n "
106+ "}\n "
107+ ),
108+ })
109+
110+ run = _find (result , ".run()" , "checkout" )
111+ gateway_charge = _find (result , ".charge()" , "paymentgateway" )
112+ audit_charge = _find (result , ".charge()" , "auditlog" )
113+ assert (run , gateway_charge ) in calls
114+ assert (run , audit_charge ) in calls
115+
116+
96117def test_parameter_and_local_receivers_resolve_per_method (tmp_path : Path ):
97118 calls , result = _calls (tmp_path , {
98119 ** _AMBIGUOUS_METHODS ,
@@ -114,6 +135,34 @@ def test_parameter_and_local_receivers_resolve_per_method(tmp_path: Path):
114135 assert (from_local , gateway_charge ) not in calls
115136
116137
138+ def test_nested_receiver_bindings_do_not_escape_their_scope (tmp_path : Path ):
139+ calls , result = _calls (tmp_path , {
140+ ** _AMBIGUOUS_METHODS ,
141+ "Checkout.java" : (
142+ "class Checkout {\n "
143+ " PaymentGateway service;\n "
144+ " void blockLocal() {\n "
145+ " service.charge();\n "
146+ " { AuditLog service = null; service.charge(); }\n "
147+ " }\n "
148+ " void anonymousClass() {\n "
149+ " new Object() { void nested() { AuditLog service = null; } };\n "
150+ " service.charge();\n "
151+ " }\n "
152+ "}\n "
153+ ),
154+ })
155+
156+ block_local = _find (result , ".blockLocal()" , "checkout" )
157+ anonymous_class = _find (result , ".anonymousClass()" , "checkout" )
158+ gateway_charge = _find (result , ".charge()" , "paymentgateway" )
159+ audit_charge = _find (result , ".charge()" , "auditlog" )
160+ assert not any (source == block_local and "charge" in target
161+ for source , target in calls )
162+ assert (anonymous_class , gateway_charge ) in calls
163+ assert (anonymous_class , audit_charge ) not in calls
164+
165+
117166def test_overloaded_callers_keep_body_scoped_receiver_types (tmp_path : Path ):
118167 calls , result = _calls (tmp_path , {
119168 ** _AMBIGUOUS_METHODS ,
0 commit comments