You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java
+13-9
Original file line number
Diff line number
Diff line change
@@ -1805,17 +1805,21 @@ public void testCompileStatic8176() {
1805
1805
String[] sources = {
1806
1806
"Main.groovy",
1807
1807
"@groovy.transform.CompileStatic\n" +
1808
-
"static <M extends Map> M merge(M to, Map from) {\n" +
Copy file name to clipboardExpand all lines: base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java
+194-6
Original file line number
Diff line number
Diff line change
@@ -66,19 +66,26 @@ public void testTypeChecked2() {
66
66
"Main.groovy",
67
67
"@groovy.transform.TypeChecked\n" +
68
68
"void method(String message) {\n" +
69
-
" List<Integer> ls = new ArrayList<Integer>()\n" +
70
-
" ls.add(123)\n" +
71
-
" ls.add('abc')\n" +
69
+
" List<Integer> ints = new ArrayList<>()\n" +
70
+
" ints.add(12345)\n" +
71
+
" ints.add('abc')\n" +
72
+
" ints << 'def'\n" +
72
73
"}\n",
73
74
};
74
75
//@formatter:on
75
76
76
77
runNegativeTest(sources,
77
78
"----------\n" +
78
79
"1. ERROR in Main.groovy (at line 5)\n" +
79
-
"\tls.add(\'abc\')\n" +
80
+
"\tints.add(\'abc\')\n" +
81
+
"\t^^^^^^^^^^^^^^^\n" +
82
+
"Groovy:[Static type checking] - Cannot find matching method java.util.ArrayList#add(java.lang.String)." +
83
+
" Please check if the declared type is correct and if the method exists.\n" +
84
+
"----------\n" +
85
+
"2. ERROR in Main.groovy (at line 6)\n" +
86
+
"\tints << 'def'\n" +
80
87
"\t^^^^^^^^^^^^^\n" +
81
-
"Groovy:[Static type checking] - Cannot find matching method java.util.ArrayList#add(java.lang.String). Please check if the declared type is correct and if the method exists.\n" +
88
+
"Groovy:[Static type checking] - Cannot call <T> java.util.ArrayList#leftShift(T) with arguments [java.lang.String]\n" +
82
89
"----------\n");
83
90
}
84
91
@@ -483,6 +490,23 @@ public void testTypeChecked6240() {
483
490
runConformTest(sources, "A1B2C3");
484
491
}
485
492
493
+
@Test
494
+
publicvoidtestTypeChecked6455() {
495
+
//@formatter:off
496
+
String[] sources = {
497
+
"Main.groovy",
498
+
"@groovy.transform.TypeChecked\n" +
499
+
"class IntegerList {\n" +
500
+
" @Delegate List<Integer> delegate = new ArrayList<Integer>()\n" +
501
+
"}\n" +
502
+
"def list = new IntegerList()\n" +
503
+
"assert list == []\n",
504
+
};
505
+
//@formatter:on
506
+
507
+
runConformTest(sources);
508
+
}
509
+
486
510
@Test
487
511
publicvoidtestTypeChecked6786() {
488
512
//@formatter:off
@@ -774,6 +798,35 @@ public void testTypeChecked7274() {
774
798
runConformTest(sources);
775
799
}
776
800
801
+
@Test
802
+
publicvoidtestTypeChecked7316() {
803
+
//@formatter:off
804
+
String[] sources = {
805
+
"Main.groovy",
806
+
"def <T> T blank() {\n" +
807
+
"}\n" +
808
+
"def <T extends Iterable<?>> T iter() {\n" +
809
+
"}\n" +
810
+
"def <T extends CharSequence> T seq() {\n" +
811
+
"}\n" +
812
+
"@groovy.transform.TypeChecked\n" +
813
+
"List<?> test() {\n" +
814
+
" blank()\n" +
815
+
" iter()\n" +
816
+
" seq()\n" +
817
+
"}\n",
818
+
};
819
+
//@formatter:on
820
+
821
+
runNegativeTest(sources,
822
+
"----------\n" +
823
+
"1. ERROR in Main.groovy (at line 11)\n" +
824
+
"\tseq()\n" +
825
+
"\t^^^^^\n" +
826
+
"Groovy:[Static type checking] - Cannot return value of type #T on method returning type java.util.List<?>\n" +
827
+
"----------\n");
828
+
}
829
+
777
830
@Test
778
831
publicvoidtestTypeChecked7333() {
779
832
//@formatter:off
@@ -1856,7 +1909,7 @@ public void testTypeChecked9907() {
1856
1909
1857
1910
@Test
1858
1911
publicvoidtestTypeChecked9915() {
1859
-
for (Stringtype : newString[] {"List", "Iterable", "Collection"}) {
1912
+
for (Stringtype : newString[] {"List", "Collection", "Iterable"}) {
1860
1913
//@formatter:off
1861
1914
String[] sources = {
1862
1915
"Main.groovy",
@@ -1877,6 +1930,24 @@ public void testTypeChecked9915() {
1877
1930
}
1878
1931
}
1879
1932
1933
+
@Test
1934
+
publicvoidtestTypeChecked9915a() {
1935
+
for (Stringtype : newString[] {"Set", "Collection", "Iterable"}) {
1936
+
//@formatter:off
1937
+
String[] sources = {
1938
+
"Main.groovy",
1939
+
"@groovy.transform.TypeChecked\n" +
1940
+
"class C {\n" +
1941
+
type + "<String> strings = Collections.emptySet()\n" +
1942
+
"}\n" +
1943
+
"new C()\n",
1944
+
};
1945
+
//@formatter:on
1946
+
1947
+
runConformTest(sources);
1948
+
}
1949
+
}
1950
+
1880
1951
@Test
1881
1952
publicvoidtestTypeChecked9935() {
1882
1953
for (Stringtype : newString[] {"def", "int", "Integer", "BigInteger", "BigDecimal"}) {
@@ -2556,6 +2627,34 @@ public void testTypeChecked9998b() {
2556
2627
runConformTest(sources, "null");
2557
2628
}
2558
2629
2630
+
@Test
2631
+
publicvoidtestTypeChecked10002() {
2632
+
//@formatter:off
2633
+
String[] sources = {
2634
+
"Main.groovy",
2635
+
"@groovy.transform.TypeChecked\n" +
2636
+
"void test() {\n" +
2637
+
" List<String> list = ['a','b',3]\n" +
2638
+
" Deque<String> deque = ['x','y']\n" +
2639
+
"}\n",
2640
+
};
2641
+
//@formatter:on
2642
+
2643
+
runNegativeTest(sources,
2644
+
"----------\n" +
2645
+
"1. ERROR in Main.groovy (at line 3)\n" +
2646
+
"\tList<String> list = ['a','b',3]\n" +
2647
+
"\t ^^^^^^^^^^^\n" +
2648
+
"Groovy:[Static type checking] - Incompatible generic argument types." +
2649
+
" Cannot assign java.util.ArrayList<java.io.Serializable<? extends java.lang.Object>> to: java.util.List<java.lang.String>\n" +
2650
+
"----------\n" +
2651
+
"2. ERROR in Main.groovy (at line 4)\n" +
2652
+
"\tDeque<String> deque = ['x','y']\n" +
2653
+
"\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
2654
+
"Groovy:[Static type checking] - Cannot assign value of type java.util.List<java.lang.String> to variable of type java.util.Deque<java.lang.String>\n" +
2655
+
"----------\n");
2656
+
}
2657
+
2559
2658
@Test
2560
2659
publicvoidtestTypeChecked10006() {
2561
2660
//@formatter:off
@@ -3281,6 +3380,95 @@ public void testTypeChecked10217() {
3281
3380
runConformTest(sources, "11");
3282
3381
}
3283
3382
3383
+
@Test
3384
+
publicvoidtestTypeChecked10220() {
3385
+
//@formatter:off
3386
+
String[] sources = {
3387
+
"Main.groovy",
3388
+
"class C<S, T extends Number> {\n" +
3389
+
"}\n" +
3390
+
"@groovy.transform.TypeChecked\n" +
3391
+
"class D<T> {\n" +
3392
+
" C<? extends T, Integer> f\n" +
3393
+
" D(C<? extends T, Integer> p) {\n" +
3394
+
" f = p\n" +
3395
+
" }\n" +
3396
+
"}\n" +
3397
+
"print(new D<String>(null).f)\n",
3398
+
};
3399
+
//@formatter:on
3400
+
3401
+
runConformTest(sources, "null");
3402
+
}
3403
+
3404
+
@Test
3405
+
publicvoidtestTypeChecked10222() {
3406
+
//@formatter:off
3407
+
String[] sources = {
3408
+
"Main.groovy",
3409
+
"@groovy.transform.TypeChecked\n" +
3410
+
"class C<T> {\n" +
3411
+
" def <X> X m() {\n" +
3412
+
" }\n" +
3413
+
" void test() {\n" +
3414
+
" T x = m()\n" + // Cannot assign value of type #X to variable of type T
3415
+
" print x\n" +
3416
+
" }\n" +
3417
+
"}\n" +
3418
+
"new C().test()\n",
3419
+
};
3420
+
//@formatter:on
3421
+
3422
+
runConformTest(sources, "null");
3423
+
}
3424
+
3425
+
@Test
3426
+
publicvoidtestTypeChecked10222a() {
3427
+
//@formatter:off
3428
+
String[] sources = {
3429
+
"Main.groovy",
3430
+
"class Task {\n" +
3431
+
" def <T> T exec(args) {\n" +
3432
+
" args\n" +
3433
+
" }\n" +
3434
+
"}\n" +
3435
+
"class Test {\n" +
3436
+
" Task task\n" +
3437
+
" @groovy.transform.TypeChecked\n" +
3438
+
" def <T> T exec(args) {\n" +
3439
+
" task.exec(args)\n" + // Cannot return value of type #T on method returning type T
3440
+
" }\n" +
3441
+
"}\n" +
3442
+
"print(new Test(task: new Task()).exec('works'))\n",
3443
+
};
3444
+
//@formatter:on
3445
+
3446
+
runConformTest(sources, "works");
3447
+
}
3448
+
3449
+
@Test
3450
+
publicvoidtestTypeChecked10235() {
3451
+
if (Float.parseFloat(System.getProperty("java.specification.version")) > 8)
0 commit comments