[jira] [Commented] (GROOVY-8342) Static compilation error with a method returning an array in a type parameter

2018-10-10 Thread Paul King (JIRA)


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

Paul King commented on GROOVY-8342:
---

Thanks [~emilles]. I haven't thought through whether there is a better way to 
refactor/fix this but your change certainly fixes this case, so I'll merge and 
we can think about improvements down the track.

> Static compilation error with a method returning an array in a type parameter
> -
>
> Key: GROOVY-8342
> URL: https://issues.apache.org/jira/browse/GROOVY-8342
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Reporter: M. Justin
>Priority: Major
>
> A compilation error occurs when using static compilation and attempting to 
> assign the result of a method that returns a parameterized argument that 
> contains an array in the type parameter.  The equivalent Java code has no 
> issues.
> Here is a specific example:
> {code}@CompileStatic
> class ArrayGenericsIssue {
>   static void main(String[] args) {
> Optional value = testArrayMethod(1) //This fails to compile
>   }
>   static  Optional testArrayMethod(E ignored) {
> return Optional.empty()
>   }
> }{code}
> The error returned is:
> {code}Error:(11, 33) Groovyc: [Static type checking] - Incompatible generic 
> argument types. Cannot assign java.util.Optional  to: java.util.Optional 
> {code}
> The expected behavior is that this code would compile and run successfully 
> with @CompileStatic enabled.
> Note that equivalent code with a non-array generic parameter works just fine:
> {code}
>   static void main(String[] args) {
> Optional> value = testListMethod(1)
>   }
>   static  Optional> testListMethod(E ignored) {
> return Optional.empty()
>   }
> {code}
> Additionally, there is no compilation issue if the value is cast:
> {code}Optional value = (Optional) 
> testArrayMethod(1){code}
> For some context, I'm running into this issue when working with 
> [jOOQ|https://www.jooq.org/], as some of its API involves working with array 
> type parameters. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (GROOVY-8342) Static compilation error with a method returning an array in a type parameter

2018-10-10 Thread Eric Milles (JIRA)


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

Eric Milles commented on GROOVY-8342:
-

This may fix the issue (edit indicated in the 2nd half):
{code:java}
private static GenericsType applyGenericsContext(Map 
spec, GenericsType gt) {
if (gt.isPlaceholder()) {
String name = gt.getName();
GenericsType specType = spec.get(name);
if (specType!=null) return specType;
if (hasNonTrivialBounds(gt)) {
GenericsType newGT = new GenericsType(gt.getType(), 
applyGenericsContext(spec, gt.getUpperBounds()), applyGenericsContext(spec, 
gt.getLowerBound()));
newGT.setPlaceholder(true);
return newGT;
}
return gt;
} else if (gt.isWildcard()) {
GenericsType newGT = new GenericsType(gt.getType(), 
applyGenericsContext(spec, gt.getUpperBounds()), applyGenericsContext(spec, 
gt.getLowerBound()));
newGT.setWildcard(true);
return newGT;
}
ClassNode type = gt.getType();
/* GRECLIPSE edit
if (type.getGenericsTypes()==null) return gt;
ClassNode newType = type.getPlainNodeReference();
newType.setGenericsPlaceHolder(type.isGenericsPlaceHolder());
newType.setGenericsTypes(applyGenericsContext(spec, 
type.getGenericsTypes()));
*/
ClassNode newType;
if (type.isArray()) {
newType = applyGenericsContext(spec, 
type.getComponentType()).makeArray();
} else {
if (type.getGenericsTypes()==null) return gt;
newType = type.getPlainNodeReference();
newType.setGenericsPlaceHolder(type.isGenericsPlaceHolder());
newType.setGenericsTypes(applyGenericsContext(spec, 
type.getGenericsTypes()));
}
GenericsType newGT = new GenericsType(newType);
return newGT;
}
{code}

> Static compilation error with a method returning an array in a type parameter
> -
>
> Key: GROOVY-8342
> URL: https://issues.apache.org/jira/browse/GROOVY-8342
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Reporter: M. Justin
>Priority: Major
>
> A compilation error occurs when using static compilation and attempting to 
> assign the result of a method that returns a parameterized argument that 
> contains an array in the type parameter.  The equivalent Java code has no 
> issues.
> Here is a specific example:
> {code}@CompileStatic
> class ArrayGenericsIssue {
>   static void main(String[] args) {
> Optional value = testArrayMethod(1) //This fails to compile
>   }
>   static  Optional testArrayMethod(E ignored) {
> return Optional.empty()
>   }
> }{code}
> The error returned is:
> {code}Error:(11, 33) Groovyc: [Static type checking] - Incompatible generic 
> argument types. Cannot assign java.util.Optional  to: java.util.Optional 
> {code}
> The expected behavior is that this code would compile and run successfully 
> with @CompileStatic enabled.
> Note that equivalent code with a non-array generic parameter works just fine:
> {code}
>   static void main(String[] args) {
> Optional> value = testListMethod(1)
>   }
>   static  Optional> testListMethod(E ignored) {
> return Optional.empty()
>   }
> {code}
> Additionally, there is no compilation issue if the value is cast:
> {code}Optional value = (Optional) 
> testArrayMethod(1){code}
> For some context, I'm running into this issue when working with 
> [jOOQ|https://www.jooq.org/], as some of its API involves working with array 
> type parameters. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (GROOVY-8342) Static compilation error with a method returning an array in a type parameter

2018-10-10 Thread Eric Milles (JIRA)


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

Eric Milles commented on GROOVY-8342:
-

Down from the above method, in {{StaticTypeCheckingSupport}}:
{code:java}
private static GenericsType applyGenericsContext(Map 
spec, GenericsType gt) {
if (gt.isPlaceholder()) { // returns false for "LE;" -- gt.getType() 
returns "T -> java.lang.Object[]"; placeholder is set on the component type
{code}

> Static compilation error with a method returning an array in a type parameter
> -
>
> Key: GROOVY-8342
> URL: https://issues.apache.org/jira/browse/GROOVY-8342
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Reporter: M. Justin
>Priority: Major
>
> A compilation error occurs when using static compilation and attempting to 
> assign the result of a method that returns a parameterized argument that 
> contains an array in the type parameter.  The equivalent Java code has no 
> issues.
> Here is a specific example:
> {code}@CompileStatic
> class ArrayGenericsIssue {
>   static void main(String[] args) {
> Optional value = testArrayMethod(1) //This fails to compile
>   }
>   static  Optional testArrayMethod(E ignored) {
> return Optional.empty()
>   }
> }{code}
> The error returned is:
> {code}Error:(11, 33) Groovyc: [Static type checking] - Incompatible generic 
> argument types. Cannot assign java.util.Optional  to: java.util.Optional 
> {code}
> The expected behavior is that this code would compile and run successfully 
> with @CompileStatic enabled.
> Note that equivalent code with a non-array generic parameter works just fine:
> {code}
>   static void main(String[] args) {
> Optional> value = testListMethod(1)
>   }
>   static  Optional> testListMethod(E ignored) {
> return Optional.empty()
>   }
> {code}
> Additionally, there is no compilation issue if the value is cast:
> {code}Optional value = (Optional) 
> testArrayMethod(1){code}
> For some context, I'm running into this issue when working with 
> [jOOQ|https://www.jooq.org/], as some of its API involves working with array 
> type parameters. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (GROOVY-8342) Static compilation error with a method returning an array in a type parameter

2018-10-10 Thread Eric Milles (JIRA)


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

Eric Milles commented on GROOVY-8342:
-

{{StaticTypeCheckingVisitor}} seems to have a handle on the generics.  When 
visiting method {{testListMethod}}, it does manage to understand the link 
between {{E}} and {{Integer}}.
{code:java}
protected ClassNode inferReturnTypeGenerics(
ClassNode receiver,
MethodNode method,
Expression arguments,
GenericsType[] explicitTypeHints) {
...
// resolvedPlaceholders: {E=java.lang.Integer}
// returnType: java.util.Optional <[LE;> -> java.util.Optional 
return applyGenericsContext(resolvedPlaceholders, returnType);
}
{code}

> Static compilation error with a method returning an array in a type parameter
> -
>
> Key: GROOVY-8342
> URL: https://issues.apache.org/jira/browse/GROOVY-8342
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Reporter: M. Justin
>Priority: Major
>
> A compilation error occurs when using static compilation and attempting to 
> assign the result of a method that returns a parameterized argument that 
> contains an array in the type parameter.  The equivalent Java code has no 
> issues.
> Here is a specific example:
> {code}@CompileStatic
> class ArrayGenericsIssue {
>   static void main(String[] args) {
> Optional value = testArrayMethod(1) //This fails to compile
>   }
>   static  Optional testArrayMethod(E ignored) {
> return Optional.empty()
>   }
> }{code}
> The error returned is:
> {code}Error:(11, 33) Groovyc: [Static type checking] - Incompatible generic 
> argument types. Cannot assign java.util.Optional  to: java.util.Optional 
> {code}
> The expected behavior is that this code would compile and run successfully 
> with @CompileStatic enabled.
> Note that equivalent code with a non-array generic parameter works just fine:
> {code}
>   static void main(String[] args) {
> Optional> value = testListMethod(1)
>   }
>   static  Optional> testListMethod(E ignored) {
> return Optional.empty()
>   }
> {code}
> Additionally, there is no compilation issue if the value is cast:
> {code}Optional value = (Optional) 
> testArrayMethod(1){code}
> For some context, I'm running into this issue when working with 
> [jOOQ|https://www.jooq.org/], as some of its API involves working with array 
> type parameters. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)