Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.0-alpha-3, 4.0.0-beta-1, 3.0.9
-
None
Description
I have the following Groovy program.
import java.util.function.Function; @groovy.transform.TypeChecked class Main { public static final void main() { Function<Long, Double> x // Works if (true) { x = {Long a -> (Double) a} } else { x = {Long b -> (Double) b} } // Fails Function<Long, Double> y = ((true) ? {Long a -> (Double) a} : {Long b -> (Double) b}) } }
Actual Behavior
The program does not compile, and I get the following error.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Main.groovy: 16: [Static type checking] - Cannot assign value of type java.lang.Double to variable of type java.util.function.Function<java.lang.Long, java.lang.Double> @ line 16, column 36. Function<Long, Double> y = ((true) ? {Long a -> (Double) a} : {Long b -> (Double) b}) ^ 1 error
Note that the computed type is the return type of the lambdas.
Expected Behavior
Compile successfully.
Comment
Tested against 4-beta-1, 4-alpha-3, 3.0.9, and master (commit: b26dbbeabe1e3d27d30c936701b1a571e24d5ab2). Maybe similar to GROOVY-10271.
Attachments
Issue Links
- relates to
-
GROOVY-10701 NullPointerException in instruction selection phase when having conditionals with lambdas and function references
- Closed