This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 123a00b GROOVY-10320: add test case
123a00b is described below
commit 123a00b0f32cafd6b7990fa53ee7f4be76fd5b6e
Author: Eric Milles <[email protected]>
AuthorDate: Tue Oct 19 14:08:33 2021 -0500
GROOVY-10320: add test case
---
.../groovy/transform/stc/GenericsSTCTest.groovy | 32 ++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 259a8a9..6146b98 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -2797,6 +2797,38 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase
{
}
}
+ // GROOVY-10320
+ void testPlusOverride() {
+ assertScript '''
+ interface I<T extends I> {
+ T plus(T t_aka_i)
+ }
+ @groovy.transform.TupleConstructor(defaults=false)
+ class C implements I<C> {
+ final BigDecimal n
+ @Override
+ C plus(C c) {
+ if (!c) return this
+ new C((n ?: 0.0) + (c.n ?: 0.0))
+ }
+ }
+
+ def <X extends I> X test(List<X> items) {
+ X total = null
+ for (it in items) {
+ if (!total)
+ total = it
+ else
+ total += it // Cannot call X#plus(T) with arguments [X]
+ }
+ total
+ }
+
+ def total = test([new C(1.1), new C(2.2)])
+ assert total.n == 3.3
+ '''
+ }
+
void testShouldNotCreateStackOverflow() {
assertScript '''
class Element {