You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Adrien Guichard (Jira)" <ji...@apache.org> on 2021/10/19 16:08:00 UTC
[jira] [Created] (GROOVY-10320) Generics failed to compile with
Groovy 3.0.9 when overriding plus operator
Adrien Guichard created GROOVY-10320:
----------------------------------------
Summary: 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
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)