[
https://issues.apache.org/jira/browse/GROOVY-8788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17581022#comment-17581022
]
ASF GitHub Bot commented on GROOVY-8788:
----------------------------------------
sonatype-lift[bot] commented on code in PR #1766:
URL: https://github.com/apache/groovy/pull/1766#discussion_r948409220
##########
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java:
##########
@@ -1103,6 +1104,21 @@ Person foo(B b) {}
onlyExtensionMethods.add(choice);
}
}
+ if (onlyExtensionMethods.size() > 1) {
+ // GROOVY-8788: prefer closer parameter match over closer
self-type match
+ bestDist = Integer.MAX_VALUE; List<MethodNode> bestExtensions
= new LinkedList<>();
Review Comment:
*[JdkObsolete](https://errorprone.info/bugpattern/JdkObsolete):* It is very
rare for LinkedList to out-perform ArrayList or ArrayDeque. Avoid it unless
you're willing to invest a lot of time into benchmarking. Caveat: LinkedList
supports null elements, but ArrayDeque does not.
---
```suggestion
bestDist = Integer.MAX_VALUE; List<MethodNode>
bestExtensions = new ArrayList<>();
```
---
Reply with *"**@sonatype-lift help**"* for info about LiftBot commands.
Reply with *"**@sonatype-lift ignore**"* to tell LiftBot to leave out the
above finding from this PR.
Reply with *"**@sonatype-lift ignoreall**"* to tell LiftBot to leave out all
the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to **refresh** the page to see its
response. [Click here](https://help.sonatype.com/lift/talking-to-lift) to get
to know more about LiftBot commands.
---
Was this a good recommendation?
[ [🙁 Not
relevant](https://www.sonatype.com/lift-comment-rating?comment=317131720&lift_comment_rating=1)
] - [ [😕 Won't
fix](https://www.sonatype.com/lift-comment-rating?comment=317131720&lift_comment_rating=2)
] - [ [😑 Not critical, will
fix](https://www.sonatype.com/lift-comment-rating?comment=317131720&lift_comment_rating=3)
] - [ [🙂 Critical, will
fix](https://www.sonatype.com/lift-comment-rating?comment=317131720&lift_comment_rating=4)
] - [ [😊 Critical, fixing
now](https://www.sonatype.com/lift-comment-rating?comment=317131720&lift_comment_rating=5)
]
> Inconsistency in extension method selection with @CompileStatic
> ---------------------------------------------------------------
>
> Key: GROOVY-8788
> URL: https://issues.apache.org/jira/browse/GROOVY-8788
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Affects Versions: 2.4.15, 2.5.2
> Reporter: Daniil Ovchinnikov
> Assignee: Eric Milles
> Priority: Major
> Labels: breaking
>
> Given properly registered extension class:
> {code:java|title=MyExtensions.java}
> public class MyExtensions {
> public static void foo(Object self, String s) {
> System.out.println("Object#foo(String)");
> }
> public static void foo(String self, Object o) {
> System.out.println("String#foo(Object)");
> }
> }
> {code}
> Run
> {code:java|title=playground.groovy}
> void usageExt() {
> "".foo("") // prints "Object#foo(String)" which is correct
> }
> @groovy.transform.CompileStatic
> void usageExtStatic() {
> "".foo("") // prints "String#foo(Object)" which is questionable
> }
> usageExt()
> usageExtStatic()
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)