Scott Murphy Heiberg created GROOVY-12820:
---------------------------------------------
Summary: SC: compound assignment to a subscript whose getAt/putAt
belong to an enclosing instance fails to compile or reads the wrong object
Key: GROOVY-12820
URL: https://issues.apache.org/jira/browse/GROOVY-12820
Project: Groovy
Issue Type: Bug
Reporter: Scott Murphy Heiberg
On master (09e84fa), JDK 25.0.4:
{code:groovy}
class Box {
String id
Box(String id) { this.id = id }
String getAt(int i) { 'g' + id + i }
void putAt(int i, String v) { id = 'put(' + v + ')' }
@groovy.transform.CompileStatic
class In { def t(In other) { other[2] += 'w' } }
Object in() { new In() }
}
def a = new Box('A'), b = new Box('B')
a.in().t(b.in())
assert b.id == 'put(gB2w)'
{code}
Dynamic Groovy and {{@TypeChecked}} call {{getAt}} and {{putAt}} on {{other}}'s
enclosing {{Box}}. Under {{@CompileStatic}}, {{other[2] += 'w'}},
{{other[2]++}} and {{other[2] ?= 'e'}} fail with GroovyBugError in class
generation, at {{StaticTypesCallSiteWriter.makeSingleArgumentCall}}. With
private {{getAt}}/{{putAt}} and an inner {{class Sub extends Box}}, the code
compiles, but the read uses {{getAt}} on {{other}} itself while the write goes
to the enclosing instance, so {{b.id}} becomes {{put(gself2w)}} instead of
{{put(gB2w)}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)