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 2021/10/19 19:13:00 UTC

[jira] [Resolved] (GROOVY-10320) Generics failed to compile with Groovy 3.0.9 when overriding plus operator

     [ https://issues.apache.org/jira/browse/GROOVY-10320?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-10320.
----------------------------------
    Fix Version/s: 4.0.0-beta-2
       Resolution: Fixed

I will try to see exactly which change fixed this case.  It might be suitable for Groovy 3, but no guarantees...

> Generics failed to compile with Groovy 3.0.9 when overriding plus operator
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-10320
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10320
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 3.0.9
>         Environment: $ uname -a
> Linux auo4ever 5.14.13-desktop-1.mga9 #1 SMP Sun Oct 17 09:53:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
> $ java -fullversion
> openjdk full version "11.0.6+9-jvmci-19.3-b07"
>            Reporter: Adrien Guichard
>            Assignee: Eric Milles
>            Priority: Major
>              Labels: generics
>             Fix For: 4.0.0-beta-2
>
>         Attachments: generics-testcase.tar.gz
>
>
> When compiling with Groovy 3.0.9 the following test-case, I get an error:
> {noformat}
> $ ./gradlew assemble
> [ . . . ]
> startup failed:
> .../generics-testcase/src/main/groovy/test/GenericsTestCase.groovy: 37: [Static type checking] - Cannot call LC#plus(T) with arguments [LC] 
>  @ line 37, column 22.
>                    else lineContent += it
>                         ^
> 1 error
> [ . . . ]{noformat}
> No errors with previous Groovy compiler.
> {noformat}
> package test
> import groovy.transform.CompileStatic
> @CompileStatic
> class GenericsTestCase {
>     interface ILineContent<T extends ILineContent> {
>         T plus(T lineContent)
>     }
>     @CompileStatic
>     private static class LineContent implements ILineContent<LineContent> {
>         final BigDecimal sales
>         LineContent(final BigDecimal commission) {
>             this.sales = sales
>         }
>         LineContent() {
>             this.sales = 0.0
>         }
>         @Override
>         LineContent plus(LineContent lineContent) {
>             if (!lineContent) return this
>             else new LineContent((sales ?: 0.0) + (lineContent.sales ?: 0.0))
>         }
>     }
>     private static class ClassThatCauseCompilationError<LC extends ILineContent> {
>         List<LC> someLines
>         LC getTotal() {
>             LC lineContent = null
>             for (LC it in someLines) {
>                 if (!lineContent) lineContent = it
>                 else lineContent += it
>             }
>             lineContent as LC
>         }
>     }
> }
> {noformat}
>  
> I attached to this report the Gradle test-case to switch quickly between Groovy compiler releases.
>  
> Thanks for your support, 
>  Adrien



--
This message was sent by Atlassian Jira
(v8.3.4#803005)