[jira] [Updated] (GROOVY-10628) Elvis assignment operator loses type information
[ https://issues.apache.org/jira/browse/GROOVY-10628?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eric Milles updated GROOVY-10628: - Fix Version/s: 3.0.11 > Elvis assignment operator loses type information > > > Key: GROOVY-10628 > URL: https://issues.apache.org/jira/browse/GROOVY-10628 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker >Affects Versions: 4.0.2 >Reporter: Christopher Smith >Assignee: Eric Milles >Priority: Major > Fix For: 5.0.0-alpha-1, 3.0.11, 4.0.3 > > > This class works as expected: > {code} > class RoutingInfo { > String to > void hello() { this.to ?= 'alice' } > } > {code} > Trying to use Elvis assignment from a class _in another file_ (it must be > another file) causes the STC to lose track of the type of the RHS and > complain that it can't assign Object to String: > {code} > class Other { > void world() { > new RoutingInfo().to ?= 'bob' > } > } > {code} > {code} > Groovy:[Static type checking] - Cannot assign value of type java.lang.Object > to variable of type java.lang.String > {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Updated] (GROOVY-10628) Elvis assignment operator loses type information
[ https://issues.apache.org/jira/browse/GROOVY-10628?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eric Milles updated GROOVY-10628: - Fix Version/s: 4.0.3 > Elvis assignment operator loses type information > > > Key: GROOVY-10628 > URL: https://issues.apache.org/jira/browse/GROOVY-10628 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker >Affects Versions: 4.0.2 >Reporter: Christopher Smith >Assignee: Eric Milles >Priority: Major > Fix For: 5.0.0-alpha-1, 4.0.3 > > > This class works as expected: > {code} > class RoutingInfo { > String to > void hello() { this.to ?= 'alice' } > } > {code} > Trying to use Elvis assignment from a class _in another file_ (it must be > another file) causes the STC to lose track of the type of the RHS and > complain that it can't assign Object to String: > {code} > class Other { > void world() { > new RoutingInfo().to ?= 'bob' > } > } > {code} > {code} > Groovy:[Static type checking] - Cannot assign value of type java.lang.Object > to variable of type java.lang.String > {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Resolved] (GROOVY-10628) Elvis assignment operator loses type information
[ https://issues.apache.org/jira/browse/GROOVY-10628?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eric Milles resolved GROOVY-10628. -- Fix Version/s: 5.0.0-alpha-1 Resolution: Fixed https://github.com/apache/groovy/commit/a976ecdee1f17f7fafc55767de2d857c44d44697 > Elvis assignment operator loses type information > > > Key: GROOVY-10628 > URL: https://issues.apache.org/jira/browse/GROOVY-10628 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker >Affects Versions: 4.0.2 >Reporter: Christopher Smith >Assignee: Eric Milles >Priority: Major > Fix For: 5.0.0-alpha-1 > > > This class works as expected: > {code} > class RoutingInfo { > String to > void hello() { this.to ?= 'alice' } > } > {code} > Trying to use Elvis assignment from a class _in another file_ (it must be > another file) causes the STC to lose track of the type of the RHS and > complain that it can't assign Object to String: > {code} > class Other { > void world() { > new RoutingInfo().to ?= 'bob' > } > } > {code} > {code} > Groovy:[Static type checking] - Cannot assign value of type java.lang.Object > to variable of type java.lang.String > {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Commented] (GROOVY-10628) Elvis assignment operator loses type information
[ https://issues.apache.org/jira/browse/GROOVY-10628?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17539756#comment-17539756 ] Eric Milles commented on GROOVY-10628: -- The static type checker creates expression "%.setTo((new RoutingInfo().to) ? new RoutingInfo().to : 'bob')" and tries to get the method target for the target type. When the expression is reused for its getter semantic, something is going wrong. > Elvis assignment operator loses type information > > > Key: GROOVY-10628 > URL: https://issues.apache.org/jira/browse/GROOVY-10628 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker >Affects Versions: 4.0.2 >Reporter: Christopher Smith >Assignee: Eric Milles >Priority: Major > > This class works as expected: > {code} > class RoutingInfo { > String to > void hello() { this.to ?= 'alice' } > } > {code} > Trying to use Elvis assignment from a class _in another file_ (it must be > another file) causes the STC to lose track of the type of the RHS and > complain that it can't assign Object to String: > {code} > class Other { > void world() { > new RoutingInfo().to ?= 'bob' > } > } > {code} > {code} > Groovy:[Static type checking] - Cannot assign value of type java.lang.Object > to variable of type java.lang.String > {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Comment Edited] (GROOVY-10628) Elvis assignment operator loses type information
[ https://issues.apache.org/jira/browse/GROOVY-10628?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17539750#comment-17539750 ] Eric Milles edited comment on GROOVY-10628 at 5/19/22 7:09 PM: --- If you change "String to" to "public String to" or "void setTo(String to) { ... }" do you get the same thing? There is some special property node handling and I'm trying to see if that is where the problem lies. Update: field works fine. Must have something to do with property. was (Author: emilles): If you change "String to" to "public String to" or "void setTo(String to) { ... }" do you get the same thing? There is some special property node handling and I'm trying to see if that is where the problem lies. > Elvis assignment operator loses type information > > > Key: GROOVY-10628 > URL: https://issues.apache.org/jira/browse/GROOVY-10628 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker >Affects Versions: 4.0.2 >Reporter: Christopher Smith >Assignee: Eric Milles >Priority: Major > > This class works as expected: > {code} > class RoutingInfo { > String to > void hello() { this.to ?= 'alice' } > } > {code} > Trying to use Elvis assignment from a class _in another file_ (it must be > another file) causes the STC to lose track of the type of the RHS and > complain that it can't assign Object to String: > {code} > class Other { > void world() { > new RoutingInfo().to ?= 'bob' > } > } > {code} > {code} > Groovy:[Static type checking] - Cannot assign value of type java.lang.Object > to variable of type java.lang.String > {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Commented] (GROOVY-10628) Elvis assignment operator loses type information
[ https://issues.apache.org/jira/browse/GROOVY-10628?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17539750#comment-17539750 ] Eric Milles commented on GROOVY-10628: -- If you change "String to" to "public String to" or "void setTo(String to) { ... }" do you get the same thing? There is some special property node handling and I'm trying to see if that is where the problem lies. > Elvis assignment operator loses type information > > > Key: GROOVY-10628 > URL: https://issues.apache.org/jira/browse/GROOVY-10628 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker >Affects Versions: 4.0.2 >Reporter: Christopher Smith >Priority: Major > > This class works as expected: > {code} > class RoutingInfo { > String to > void hello() { this.to ?= 'alice' } > } > {code} > Trying to use Elvis assignment from a class _in another file_ (it must be > another file) causes the STC to lose track of the type of the RHS and > complain that it can't assign Object to String: > {code} > class Other { > void world() { > new RoutingInfo().to ?= 'bob' > } > } > {code} > {code} > Groovy:[Static type checking] - Cannot assign value of type java.lang.Object > to variable of type java.lang.String > {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Assigned] (GROOVY-10628) Elvis assignment operator loses type information
[ https://issues.apache.org/jira/browse/GROOVY-10628?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eric Milles reassigned GROOVY-10628: Assignee: Eric Milles > Elvis assignment operator loses type information > > > Key: GROOVY-10628 > URL: https://issues.apache.org/jira/browse/GROOVY-10628 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker >Affects Versions: 4.0.2 >Reporter: Christopher Smith >Assignee: Eric Milles >Priority: Major > > This class works as expected: > {code} > class RoutingInfo { > String to > void hello() { this.to ?= 'alice' } > } > {code} > Trying to use Elvis assignment from a class _in another file_ (it must be > another file) causes the STC to lose track of the type of the RHS and > complain that it can't assign Object to String: > {code} > class Other { > void world() { > new RoutingInfo().to ?= 'bob' > } > } > {code} > {code} > Groovy:[Static type checking] - Cannot assign value of type java.lang.Object > to variable of type java.lang.String > {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Created] (GROOVY-10628) Elvis assignment operator loses type information
Christopher Smith created GROOVY-10628: -- Summary: Elvis assignment operator loses type information Key: GROOVY-10628 URL: https://issues.apache.org/jira/browse/GROOVY-10628 Project: Groovy Issue Type: Bug Components: Static Type Checker Affects Versions: 4.0.2 Reporter: Christopher Smith This class works as expected: {code} class RoutingInfo { String to void hello() { this.to ?= 'alice' } } {code} Trying to use Elvis assignment from a class _in another file_ (it must be another file) causes the STC to lose track of the type of the RHS and complain that it can't assign Object to String: {code} class Other { void world() { new RoutingInfo().to ?= 'bob' } } {code} {code} Groovy:[Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.lang.String {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Updated] (GROOVY-9853) ClassFormatError using method reference on interface target
[ https://issues.apache.org/jira/browse/GROOVY-9853?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Christopher Smith updated GROOVY-9853: -- Affects Version/s: 4.0.2 > ClassFormatError using method reference on interface target > --- > > Key: GROOVY-9853 > URL: https://issues.apache.org/jira/browse/GROOVY-9853 > Project: Groovy > Issue Type: Bug >Affects Versions: 3.0.7, 4.0.2 >Reporter: Christopher Smith >Priority: Major > > After upgrading to 3.0.7, using {{interfaceField::method}} is resulting in > bytecode output containing an InterfaceMethodref that looks as expected. When > running it in the Eclipse JUnit runner, however (which I think is > unimportant), I'm getting a loading error from the JVM: > {code} > Caused by: java.lang.ClassFormatError: Invalid constant pool index 130 in > class file com/example/sendgrid/SendgridMailSender (not a method) > {code} > where the offending constant is > {code} > #130 = InterfaceMethodref #126.#129 // > com/sendgrid/SendGridAPI.api:(Lcom/sendgrid/Request;)Lcom/sendgrid/Response; > {code} > from the 4.6.8 SendGrid SDK. > Compiling with 3.0.6 seems to work. Replacing {{::}} with {{.&}} seems to > work. > The JVM is 11.0.9-hs-adpt. -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Resolved] (GROOVY-10272) Wrong inference when using ternary operator with lambdas
[ https://issues.apache.org/jira/browse/GROOVY-10272?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eric Milles resolved GROOVY-10272. -- Fix Version/s: 5.0.0-alpha-1 Resolution: Fixed https://github.com/apache/groovy/commit/16f6be8639c15e227efc0154604b6bd8f8ffe1ae > Wrong inference when using ternary operator with lambdas > > > Key: GROOVY-10272 > URL: https://issues.apache.org/jira/browse/GROOVY-10272 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker >Affects Versions: 4.0.0-alpha-3, 4.0.0-beta-1, 3.0.9 >Reporter: Stefanos Chaliasos >Assignee: Eric Milles >Priority: Major > Fix For: 5.0.0-alpha-1 > > > I have the following Groovy program. > {code:groovy} > import java.util.function.Function; > @groovy.transform.TypeChecked > class Main { > public static final void main() { > Function x > // Works > if (true) { > x = {Long a -> (Double) a} > } else { > x = {Long b -> (Double) b} > } > // Fails > Function y = ((true) ? {Long a -> (Double) a} : {Long b > -> (Double) b}) > } > } > {code} > h2. Actual Behavior > The program does not compile, and I get the following error. > {code:java} > 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 > @ line 16, column 36. >Function y = ((true) ? {Long a -> (Double) a} : > {Long b -> (Double) b}) > ^ > 1 error > {code} > Note that the computed type is the return type of the lambdas. > h2. Expected Behavior > Compile successfully. > h2. Comment > Tested against 4-beta-1, 4-alpha-3, 3.0.9, and master (commit: > b26dbbeabe1e3d27d30c936701b1a571e24d5ab2). Maybe similar to GROOVY-10271. -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Resolved] (GROOVY-10271) Wrong inference when using ternary operator with closure and variable
[ https://issues.apache.org/jira/browse/GROOVY-10271?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eric Milles resolved GROOVY-10271. -- Fix Version/s: 5.0.0-alpha-1 Resolution: Fixed https://github.com/apache/groovy/commit/16f6be8639c15e227efc0154604b6bd8f8ffe1ae > Wrong inference when using ternary operator with closure and variable > - > > Key: GROOVY-10271 > URL: https://issues.apache.org/jira/browse/GROOVY-10271 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker >Affects Versions: 4.0.0-alpha-3, 4.0.0-beta-1, 3.0.9 >Reporter: Stefanos Chaliasos >Assignee: Eric Milles >Priority: Major > Fix For: 5.0.0-alpha-1 > > > I have the following Groovy program. > {code:groovy} > import java.util.function.Supplier; > @groovy.transform.TypeChecked > class Main { > static final void foo(Supplier x) {} > public static final void main() { > Supplier y = { -> 5 } > Supplier z = (true) ? y : {-> 5} > } > } > {code} > h2. Actual Behavior > The program does not compile, and I get the following error. > {code:java} > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup > failed: > Main.groovy: 11: [Static type checking] - Cannot assign value of type > java.lang.Object to variable of type > java.util.function.Supplier > @ line 11, column 29. > Supplier z = (true) ? y : {-> 5} >^ > 1 error > {code} > h2. Expected Behavior > Compile successfully. > h2. Comment > Tested against 4-beta-1, 4-alpha-3, 3.0.9, and master (commit: > b26dbbeabe1e3d27d30c936701b1a571e24d5ab2). Maybe similar to GROOVY-10114, but > with function types. -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Updated] (GROOVY-10342) STC is unable to infer type parameter of parameterized method call
[ https://issues.apache.org/jira/browse/GROOVY-10342?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eric Milles updated GROOVY-10342: - Fix Version/s: 4.0.3 > STC is unable to infer type parameter of parameterized method call > -- > > Key: GROOVY-10342 > URL: https://issues.apache.org/jira/browse/GROOVY-10342 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker >Reporter: Thodoris Sotiropoulos >Assignee: Eric Milles >Priority: Major > Fix For: 5.0.0-alpha-1, 4.0.3 > > > I have the following program > {code:java} > class A { > T f; > } > class Test { > static T m() { return null; } > static void test() { > String x = m(); // works > A y = new A<>(); > y.f = m(); // works > A z = new A(); > z.f = m(); // does not work > } > } > {code} > h3. Actual behaviour > {code} > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup > failed: > test.groovy: 15: [Static type checking] - Cannot assign value of type #T to > variable of type T > @ line 15, column 11. >z.f = m(); > ^ > 1 error > {code} > h3. Expected behavior > Compile successfully > *NOTE*: Replacing `T extends Number` with `T` compiles code successfully. > Tested against master. -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Updated] (GROOVY-10092) Compiler crash when trying to cast a boolean to float variable
[ https://issues.apache.org/jira/browse/GROOVY-10092?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eric Milles updated GROOVY-10092: - Fix Version/s: 4.0.3 > Compiler crash when trying to cast a boolean to float variable > -- > > Key: GROOVY-10092 > URL: https://issues.apache.org/jira/browse/GROOVY-10092 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker >Affects Versions: 4.0.0-alpha-2, 3.0.8 >Reporter: Stefanos Chaliasos >Assignee: Eric Milles >Priority: Major > Fix For: 5.0.0-alpha-1, 4.0.3 > > > I have the following Groovy program. > {code:groovy} > @groovy.transform.CompileStatic > class Main { > void foo() { > float x = true > } > } > {code} > h2. Actual Behavior > The compiler crashes, with the following stacktrace. > {code:java} > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup > failed: > General error during canonicalization: class java.lang.Boolean cannot be cast > to class java.lang.Number (java.lang.Boolean and java.lang.Number are in > module java.base of loader 'bootstrap') > java.lang.ClassCastException: class java.lang.Boolean cannot be cast to class > java.lang.Number (java.lang.Boolean and java.lang.Number are in module > java.base of loader 'bootstrap') > at > org.codehaus.groovy.transform.sc.transformers.BinaryExpressionTransformer.optimizeConstantInitialization(BinaryExpressionTransformer.java:368) > at > org.codehaus.groovy.transform.sc.transformers.BinaryExpressionTransformer.transformBinaryExpression(BinaryExpressionTransformer.java:107) > at > org.codehaus.groovy.transform.sc.transformers.StaticCompilationTransformer.transform(StaticCompilationTransformer.java:113) > at > org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:108) > at > org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:41) > at > org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:164) > at > org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:70) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:138) > at > org.codehaus.groovy.transform.sc.transformers.StaticCompilationTransformer.visitClassCodeContainer(StaticCompilationTransformer.java:104) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:111) > at > org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitConstructorOrMethod(ClassCodeExpressionTransformer.java:66) > at > org.codehaus.groovy.transform.sc.transformers.StaticCompilationTransformer.visitConstructorOrMethod(StaticCompilationTransformer.java:166) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:106) > at org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1110) > at > org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1103) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52) > at > org.codehaus.groovy.transform.sc.transformers.StaticCompilationTransformer.visitClass(StaticCompilationTransformer.java:153) > at > org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:90) > at > org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:146) > at > org.codehaus.groovy.transform.ASTTransformationVisitor.lambda$addPhaseOperations$2(ASTTransformationVisitor.java:229) > at > org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:928) > at > org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:657) > at > org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:634) > at > org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:609) > at > org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:311) > at > org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:240) > at > org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:165) > at > org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:205) > at >
[jira] [Resolved] (GROOVY-10342) STC is unable to infer type parameter of parameterized method call
[ https://issues.apache.org/jira/browse/GROOVY-10342?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eric Milles resolved GROOVY-10342. -- Fix Version/s: 5.0.0-alpha-1 Resolution: Fixed https://github.com/apache/groovy/commit/006b5987a7d91c4a4754d9e4a1191484e43f9868 > STC is unable to infer type parameter of parameterized method call > -- > > Key: GROOVY-10342 > URL: https://issues.apache.org/jira/browse/GROOVY-10342 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker >Reporter: Thodoris Sotiropoulos >Assignee: Eric Milles >Priority: Major > Fix For: 5.0.0-alpha-1 > > > I have the following program > {code:java} > class A { > T f; > } > class Test { > static T m() { return null; } > static void test() { > String x = m(); // works > A y = new A<>(); > y.f = m(); // works > A z = new A(); > z.f = m(); // does not work > } > } > {code} > h3. Actual behaviour > {code} > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup > failed: > test.groovy: 15: [Static type checking] - Cannot assign value of type #T to > variable of type T > @ line 15, column 11. >z.f = m(); > ^ > 1 error > {code} > h3. Expected behavior > Compile successfully > *NOTE*: Replacing `T extends Number` with `T` compiles code successfully. > Tested against master. -- This message was sent by Atlassian Jira (v8.20.7#820007)
[jira] [Commented] (GROOVY-10561) @NamedVariant self referential default values are not correctly resolved
[ https://issues.apache.org/jira/browse/GROOVY-10561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17539386#comment-17539386 ] Leonard Brünings commented on GROOVY-10561: --- [~paulk],[~emilles] will this also be fixed in 2.x. and 3.x? > @NamedVariant self referential default values are not correctly resolved > > > Key: GROOVY-10561 > URL: https://issues.apache.org/jira/browse/GROOVY-10561 > Project: Groovy > Issue Type: Bug >Affects Versions: 2.5.16, 3.0.10, 4.0.1 >Reporter: Leonard Brünings >Assignee: Paul King >Priority: Major > Labels: named-parameters > Fix For: 5.0.0-alpha-1, 4.0.2 > > Time Spent: 1h > Remaining Estimate: 0h > > If a default parameter refers to another parameter ( {{String language = > 'java', String extension = language}} ) it will fail, when the named variant > is used. > {code:groovy} > import groovy.transform.NamedVariant > import spock.lang.Specification > class Demo { > @NamedVariant > String fileInSourceSet(String language = 'java', String extension = > language) { > return "$language -> .$extension" > } > > def test() { > assert fileInSourceSet() == 'java -> .java' > assert fileInSourceSet('groovy') == 'groovy -> .groovy' > assert fileInSourceSet(language: 'kotlin', extension: 'kt') == > 'kotlin -> .kt' > // fails > assert fileInSourceSet(language: 'groovy') == 'groovy -> > .groovy' > } > > static main(args) { > new Demo().test() > } > } > {code} > See on > [WebConsole|https://gwc-experiment.appspot.com/?g=groovy_3_0=eJyNUU1rwzAMPTe_QpRCEujS-6Bjh1126SWwu0iV4C2Wh610G6P_ff5KWAtl00HgJ72nJ1npd2MFBmvM6asRi-x6Y3VzQE3HF7QKWYqiG9E5eCJt4LsAH48X9YC0YhUP0KuRnrk1k-2oJakyPCIPEw4Eeyhf8YTldibQpxA7ZdiX5q46TwlhSSbLsN4sEncP0GwW2jp2nmOO6Ug9CDmpgspq5Y2TX_DaVw37bCXqRU-3u8t0nzKx0iPyMn6bObu-h_LNyKjYb754D6Bk0VSNoh5b1t_toEc1un9N-Mvl1aWcoKgONCqu0A7u99lDMH3EP6_qJh80KUSBc1FcNP8AgUKxrg] > (as long as deployed version is 3.0.10) > {noformat} > groovy.lang.MissingPropertyException: No such property: language for class: > Demo > at Demo.fileInSourceSet(Script1.groovy) > at Demo$fileInSourceSet$2.callCurrent(Unknown Source) > at Demo.test(Script1.groovy:14) > at Demo$test.call(Unknown Source) > at Demo.main(Script1.groovy:18) > {noformat} > It generates > {code:java} > @groovy.transform.Generated > public java.lang.String > fileInSourceSet(@groovy.transform.NamedParams(value = > [@groovy.transform.NamedParam(value = 'language', type = java.lang.String, > required = false), @groovy.transform.NamedParam(value = 'extension', type = > java.lang.String, required = false)]) java.util.Map namedArgs) { > if ( namedArgs == null) { > throw new java.lang.IllegalArgumentException('Named parameter map > cannot be null') > } > for (java.lang.String namedArgKey : namedArgs.keySet()) { > assert ['language', 'extension'].contains( namedArgKey ) : > 'Unrecognized namedArgKey: ' + namedArgKey } > return this.fileInSourceSet(namedArgs.containsKey('language') ? > namedArgs.language : 'java', namedArgs.containsKey('extension') ? > namedArgs.extension : language ) > }{code} > The problematic line is {{namedArgs.containsKey('extension') ? > namedArgs.extension : language which either would have to duplicate the logic > for {{language or use a local variable for it. > Relates to GROOVY-10261 -- This message was sent by Atlassian Jira (v8.20.7#820007)