[jira] [Comment Edited] (GROOVY-8409) Static compilation with generic function wrapping BiFunction causes GroovyCastException

2018-10-06 Thread Shon Vella (JIRA)


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

Shon Vella edited comment on GROOVY-8409 at 10/7/18 1:58 AM:
-

Since reporting this issue 10 days ago I have run into this same general 
problem several times, which is probably best described as the generic type 
names from the call site scope getting conflated with the generic type names 
from declaration when CompileStatic is enabled. I've seen it both manifest 
itself at run time as described in the original bug because of an erroneous 
call to castTo() and at compile time where it either erroneously flags a type 
mismatch or can't resolve a property or method because it's trying to do so 
with the wrong type.


was (Author: svella):
Since reporting this issue 10 days ago I have run into this same general 
problem several times, which is probably best described as the generic type 
names from the call site getting conflated with scope getting conflated with 
the generic type names from declaration when CompileStatic is enabled. I've 
seen it both manifest itself at run time as described in the original bug 
because of an erroneous call to castTo() and at compile time where it either 
erroneously flags a type mismatch or can't resolve a property or method because 
it's trying to do so with the wrong type.

> Static compilation with generic function wrapping BiFunction causes 
> GroovyCastException
> ---
>
> Key: GROOVY-8409
> URL: https://issues.apache.org/jira/browse/GROOVY-8409
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.4.8, 2.4.13
> Environment: MacOS Sierra 10.12.6
>Reporter: Shon Vella
>Priority: Critical
> Attachments: Bug.groovy
>
>
> I have a statically compiled class with a method that declares Generic type T 
> as it's return type and accepts a parameter of type 
> java.util.function.BiFunction also with return type T. It makes a call to the 
> passed in BiFunction and assigns the the result to a variable of type T.
> {code:java}
> static  T actionWrapperT(BiFunction action) {
> T result = action.apply(new Date(), new URL('http://www.example.com'))
> // do something else here
> return result
> }
> {code}
> When actionWrapperT is called with runtime type T as something other than 
> Date (e.g. XXX), it causes a GroovyCastException.
> {panel}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object 'XXX@71b1176b' with class 'XXX' to class 'java.util.Date'
> {panel}
> because it incorrectly tries to cast result type to Date rather than to XXX.
> It appears to me that the compiler is conflating generic type T as declared 
> for the generic method with generic type T as declared by BiFunction 
> because if I change the name of the generic type of the generic method to R 
> (to match the return type name of BiFunction) or to some other name not used 
> by BiFunction, then it works correctly, but if I change it to U to match the 
> second parameter of the BiFunction then it fails trying to cast to the 
> BiFunction generic type U instead of the method generic type U.
> Problem does not happen under normal compilation or with only type checking 
> enabled.
> Attached file Bug.groovy reproduces the problem.



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


[jira] [Comment Edited] (GROOVY-8409) Static compilation with generic function wrapping BiFunction causes GroovyCastException

2018-08-25 Thread Paul King (JIRA)


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

Paul King edited comment on GROOVY-8409 at 8/26/18 1:47 AM:


Standalone example for testing showing two failing cases and two working cases 
(R workaround since that matches the third generic type in BiFunction and V 
since that avoids all existing types):
{code}
import java.util.function.BiFunction
import groovy.transform.CompileStatic

//@CompileStatic (if uncommented: GroovyCastException: Cannot cast object 'foo' 
with class 'java.lang.String' to class 'java.util.Date')
static  T actionWrapperT(BiFunction action) {
T result = action.apply(new Date(), new URL('http://www.example.com'))
// do something else here
return result
}

//@CompileStatic (if uncommented: GroovyCastException: Cannot cast object 'foo' 
with class 'java.lang.String' to class 'java.net.URL')
static  U actionWrapperU(BiFunction action) {
U result = action.apply(new Date(), new URL('http://www.example.com'))
// do something else here
return result
}

@CompileStatic
static  R actionWrapperR(BiFunction action) {
R result = action.apply(new Date(), new URL('http://www.example.com'))
// do something else here
return result
}

@CompileStatic
static  V actionWrapperV(BiFunction action) {
V result = action.apply(new Date(), new URL('http://www.example.com'))
// do something else here
return result
}

actionWrapperT{ Date d, URL u -> "foo" }
actionWrapperU{ Date d, URL u -> "foo" }
actionWrapperR{ Date d, URL u -> "foo" }
actionWrapperV{ Date d, URL u -> "foo" }
{code}
I will raise the priority of this too.


was (Author: paulk):
Standalone example for testing showing two failing cases and two working cases 
(R workaround since that matches the third generic type in BiFunction and V 
since that avoids all existing types):
{code}
import java.util.function.BiFunction
import groovy.transform.CompileStatic

//@CompileStatic
static  T actionWrapperT(BiFunction action) {
T result = action.apply(new Date(), new URL('http://www.example.com'))
// do something else here
return result
}

//@CompileStatic
static  U actionWrapperU(BiFunction action) {
U result = action.apply(new Date(), new URL('http://www.example.com'))
// do something else here
return result
}

@CompileStatic
static  R actionWrapperR(BiFunction action) {
R result = action.apply(new Date(), new URL('http://www.example.com'))
// do something else here
return result
}

@CompileStatic
static  V actionWrapperV(BiFunction action) {
V result = action.apply(new Date(), new URL('http://www.example.com'))
// do something else here
return result
}

actionWrapperT{ Date d, URL u -> "foo" }
actionWrapperU{ Date d, URL u -> "foo" }
actionWrapperR{ Date d, URL u -> "foo" }
actionWrapperV{ Date d, URL u -> "foo" }
{code}
I will raise the priority of this too.

> Static compilation with generic function wrapping BiFunction causes 
> GroovyCastException
> ---
>
> Key: GROOVY-8409
> URL: https://issues.apache.org/jira/browse/GROOVY-8409
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.4.8, 2.4.13
> Environment: MacOS Sierra 10.12.6
>Reporter: Shon Vella
>Priority: Critical
> Attachments: Bug.groovy
>
>
> I have a statically compiled with a method declares Generic type T as it's 
> return type and accepts a parameter of type java.util.function.BiFunction 
> also with return type T. It makes a call to the passed in BiFunction and 
> assigns the the result to a variable of type T.
> {code:java}
> static  T actionWrapperT(BiFunction action) {
> T result = action.apply(new Date(), new URL('http://www.example.com'))
> // do something else here
> return result
> }
> {code}
> When actionWrapperT is called with runtime type of T as something other the 
> Date, it causes a GroovyCastException.
> {panel}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object 'XXX@71b1176b' with class 'XXX' to class 'java.util.Date'
> {panel}
> because it incorrectly tries to cast result type Date rather than to .
> It appears to me that the compiler is conflating generic type T as declared 
> for the generic method with generic type T as declared by BiFunction 
> because if I change the name of the generic type of the generic method to R 
> (to match the return type name of BiFunction) or to some other name not used 
> by BiFunction, then it works correctly, but if I change it to U to match the 
> second parameter of the BiFunction then it fails trying to cast to the 
> BiFunction generic type U instead of the method generic type U.
> 

[jira] [Comment Edited] (GROOVY-8409) Static compilation with generic function wrapping BiFunction causes GroovyCastException

2018-08-18 Thread Daniel Sun (JIRA)


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

Daniel Sun edited comment on GROOVY-8409 at 8/18/18 10:02 AM:
--

The content of resolvedPlaceholders is shown as follows:
{code:java}
{R=T, T=java.util.Date, U=java.net.URL}
{code}
Note: the `T` of `R=T` is defined by user, but the `T` of `T=java.util.Date` is 
defined in `BiFunction`. As a result, R -> T -> Date

We should not just use generics name whose type is `String`.

 

The relevant code is:
{code:java}
//https://github.com/apache/groovy/blob/master/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L4954-L4957

Map resolvedPlaceholders = 
resolvePlaceHoldersFromDeclaration(receiver, getDeclaringClass(method, 
arguments), method, method.isStatic());
if (!receiver.isGenericsPlaceHolder()) {
GenericsUtils.extractPlaceholders(receiver, resolvedPlaceholders);
}
{code}


was (Author: daniel_sun):
The content of resolvedPlaceholders is shown as follows:
{code:java}
{R=T, T=java.util.Date, U=java.net.URL}
{code}
Note: the `T` of `R=T` is defined by user, but the `T` of `T=java.util.Date` is 
defined in `BiFunction`. We should not just use generics name whose type is 
`String`.

 

The relevant code is:
{code:java}
//https://github.com/apache/groovy/blob/master/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L4954-L4957

Map resolvedPlaceholders = 
resolvePlaceHoldersFromDeclaration(receiver, getDeclaringClass(method, 
arguments), method, method.isStatic());
if (!receiver.isGenericsPlaceHolder()) {
GenericsUtils.extractPlaceholders(receiver, resolvedPlaceholders);
}
{code}

> Static compilation with generic function wrapping BiFunction causes 
> GroovyCastException
> ---
>
> Key: GROOVY-8409
> URL: https://issues.apache.org/jira/browse/GROOVY-8409
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.4.8, 2.4.13
> Environment: MacOS Sierra 10.12.6
>Reporter: Shon Vella
>Priority: Major
> Attachments: Bug.groovy
>
>
> I have a statically compiled with a method declares Generic type T as it's 
> return type and accepts a parameter of type java.util.function.BiFunction 
> also with return type T. It makes a call to the passed in BiFunction and 
> assigns the the result to a variable of type T.
> {code:java}
> static  T actionWrapperT(BiFunction action) {
> T result = action.apply(new Date(), new URL('http://www.example.com'))
> // do something else here
> return result
> }
> {code}
> When actionWrapperT is called with runtime type of T as something other the 
> Date, it causes a GroovyCastException.
> {panel}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object 'XXX@71b1176b' with class 'XXX' to class 'java.util.Date'
> {panel}
> because it incorrectly tries to cast result type Date rather than to .
> It appears to me that the compiler is conflating generic type T as declared 
> for the generic method with generic type T as declared by BiFunction 
> because if I change the name of the generic type of the generic method to R 
> (to match the return type name of BiFunction) or to some other name not used 
> by BiFunction, then it works correctly, but if I change it to U to match the 
> second parameter of the BiFunction then it fails trying to cast to the 
> BiFunction generic type U instead of the method generic type U.
> Problem does not happen under normal compilation or with only type checking 
> enabled.
> Attached file Bug.groovy reproduces the problem.



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


[jira] [Comment Edited] (GROOVY-8409) Static compilation with generic function wrapping BiFunction causes GroovyCastException

2017-12-19 Thread Shon Vella (JIRA)

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

Shon Vella edited comment on GROOVY-8409 at 12/19/17 10:01 PM:
---

Since reporting this issue 10 days ago I have run into this same general 
problem several times, which is probably best described as the generic type 
names from the call site getting conflated with scope getting conflated with 
the generic type names from declaration when CompileStatic is enabled. I've 
seen it both manifest itself at run time as described in the original bug 
because of an erroneous call to castTo() and at compile time where it either 
erroneously flags a type mismatch or can't resolve a property or method because 
it's trying to do so with the wrong type.


was (Author: svella):
Since reporting this issue 10 days ago I have run into this same general 
problem, which is probably best described as the generic type names from the 
call site getting conflated with scope getting conflated with the generic type 
names from declaration when CompileStatic is enabled. I've seen it both 
manifest itself at run time as described in the original bug because of an 
erroneous call to castTo() and at compile time where it either erroneously 
flags a type mismatch or can't resolve a property or method because it's trying 
to do so with the wrong type. 

> Static compilation with generic function wrapping BiFunction causes 
> GroovyCastException
> ---
>
> Key: GROOVY-8409
> URL: https://issues.apache.org/jira/browse/GROOVY-8409
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.4.8, 2.4.13
> Environment: MacOS Sierra 10.12.6
>Reporter: Shon Vella
> Attachments: Bug.groovy
>
>
> I have a statically compiled with a method declares Generic type T as it's 
> return type and accepts a parameter of type java.util.function.BiFunction 
> also with return type T. It makes a call to the passed in BiFunction and 
> assigns the the result to a variable of type T.
> {code:java}
> static  T actionWrapperT(BiFunction action) {
> T result = action.apply(new Date(), new URL('http://www.example.com'))
> // do something else here
> return result
> }
> {code}
> When actionWrapperT is called with runtime type of T as something other the 
> Date, it causes a GroovyCastException.
> {panel}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object 'XXX@71b1176b' with class 'XXX' to class 'java.util.Date'
> {panel}
> because it incorrectly tries to cast result type Date rather than to .
> It appears to me that the compiler is conflating generic type T as declared 
> for the generic method with generic type T as declared by BiFunction 
> because if I change the name of the generic type of the generic method to R 
> (to match the return type name of BiFunction) or to some other name not used 
> by BiFunction, then it works correctly, but if I change it to U to match the 
> second parameter of the BiFunction then it fails trying to cast to the 
> BiFunction generic type U instead of the method generic type U.
> Problem does not happen under normal compilation or with only type checking 
> enabled.
> Attached file Bug.groovy reproduces the problem.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)