You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/07/28 15:35:00 UTC

[jira] [Comment Edited] (GROOVY-10706) Consider tightening of star import rules for type checked code

    [ https://issues.apache.org/jira/browse/GROOVY-10706?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17572153#comment-17572153 ] 

Eric Milles edited comment on GROOVY-10706 at 7/28/22 3:34 PM:
---------------------------------------------------------------

Both of these examples are problems for IDE integration with Java. I don’t have links directly at hand but can dig them up.

```groovy
void p(Proxy proxy) { x }
```
Without an import to disambiguate between `java.net.Proxy` and `groovy.util.Proxy`, this code gives an ambiguous type error from the Java tooling.  Groovy selected `java.net.Proxy` because `java.net.*` was the first star import checked by `ResolveVisitor`.  This makes it difficult for the editor to present "Proxy" as an unknown type and offer both options in the quick fix dialog.

https://github.com/groovy/groovy-eclipse/issues/1354


was (Author: emilles):
Both of these examples are problems for IDE integration with Java. I don’t have links directly at hand but can dig them up. 

> Consider tightening of star import rules for type checked code
> --------------------------------------------------------------
>
>                 Key: GROOVY-10706
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10706
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Static Type Checker
>            Reporter: Paul King
>            Priority: Major
>
> When faced we multiple star imports, dynamic Groovy has a rule whereby first seen match wins. With type checking, we might want to consider tightening up the rules and giving an error if duplicates are found, e.g.:
> {code}
> import java.awt.*;
> import java.util.*;
> @groovy.transform.CompileStatic
> static void main(args) {
>   println List
> }
> {code}
> The Java equivalent would complain with something like:
> {noformat}
> error: reference to List is ambiguous
>         System.out.println(List.class);
>                            ^
>   both interface java.util.List in java.util and class java.awt.List in java.awt match
> 1 error
> {noformat}
> This might have performance impacts though, so we'd need to investigate that as part of the analysis.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)