[
https://issues.apache.org/jira/browse/GROOVY-8549?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16616685#comment-16616685
]
ASF GitHub Bot commented on GROOVY-8549:
----------------------------------------
GitHub user paulk-asert opened a pull request:
https://github.com/apache/groovy/pull/798
GROOVY-8549: Compile Static causes getAt to fail
I started fixing this in STCSW first with something like below but then
putAt also needs fixing.
In the meantime, the added DGM methods provide sufficient info for the
static compiler to behave correctly.
```
Index:
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
---
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
(revision ba5eb9b2f19ca0cc8927359ce414c4e1974b7016)
+++
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
(date 1537092045389)
@@ -663,6 +663,10 @@
ClassNode classNode = controller.getClassNode();
ClassNode rType = typeChooser.resolveType(receiver, classNode);
ClassNode aType = typeChooser.resolveType(arguments, classNode);
+ if ("getAt".equals(message) &&
(rType.implementsInterface(LIST_TYPE) || LIST_TYPE.equals(rType)) &&
+ isOrExtends(aType, Number_TYPE))) {
+ aType = int_TYPE;
+ }
if (trySubscript(receiver, message, arguments, rType, aType,
safe)) {
return;
}
```
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/paulk-asert/groovy groovy8549
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/groovy/pull/798.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #798
----
commit e9d12703d6a29adf05694e3c04986ee5bbf96fd4
Author: Paul King <paulk@...>
Date: 2018-09-16T11:26:51Z
GROOVY-8549: Compile Static causes getAt to fail
----
> Compile Static causes getAt to fail
> -----------------------------------
>
> Key: GROOVY-8549
> URL: https://issues.apache.org/jira/browse/GROOVY-8549
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 2.4.13, 2.5.0-beta-3, 2.4.14, 3.0.0-alpha-2, 2.4.15
> Environment: Intellij plus various versions of Groovy; the same
> problem also occurs in Eclipse-Groovy with the same versions
> Reporter: Jon Kerridge
> Priority: Major
>
> I can reproduce by adding @CompileStatic to the example I tried previously
> and can confirm that 2.4.13 is where the regression started. Workaround would
> be to remove @CompileStatic until we can get a fix in place. If you can raise
> a bug issue in Jira, that would be great.
> the reproducer following is a shortened version created by Paul King:
> {code}
> import groovy.transform.CompileStatic
>
> @CompileStatic
> def method() {
> def list = [0, 1, 2, 3]
> for (idx in 1..2) {
> list[idx-1]++
> }
> list
> }
>
> assert method() == [1, 2, 2, 3]
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)