Skip to content

Commit 81f32c2

Browse files
committed
GROOVY-6912, GROOVY-7106, GROOVY-7128, GROOVY-7274, GROOVY-8001,
GROOVY-8909, GROOVY-9844, GROOVY-10002
1 parent 3a033f0 commit 81f32c2

File tree

5 files changed

+736
-25
lines changed

5 files changed

+736
-25
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java

+277
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,52 @@ public void testTypeChecked6882() {
316316
runConformTest(sources, "CC");
317317
}
318318

319+
@Test
320+
public void testTypeChecked6912() {
321+
//@formatter:off
322+
String[] sources = {
323+
"Main.groovy",
324+
"@groovy.transform.TypeChecked\n" +
325+
"void test() {\n" +
326+
" def a = []\n" +
327+
" assert a instanceof List\n" +
328+
" List b = []\n" +
329+
" assert b instanceof List\n" +
330+
" Object c = []\n" +
331+
" assert c instanceof List\n" +
332+
" Iterable d = []\n" +
333+
" assert d instanceof Iterable\n" +
334+
" ArrayList e = []\n" +
335+
" assert e instanceof ArrayList\n" +
336+
"}\n" +
337+
"test()\n",
338+
};
339+
//@formatter:on
340+
341+
runConformTest(sources, "");
342+
}
343+
344+
@Test
345+
public void testTypeChecked6912a() {
346+
//@formatter:off
347+
String[] sources = {
348+
"Main.groovy",
349+
"@groovy.transform.TypeChecked\n" +
350+
"void test() {\n" +
351+
" Set a = []\n" +
352+
" assert a instanceof Set\n" +
353+
" HashSet b = []\n" +
354+
" assert b instanceof HashSet\n" +
355+
" LinkedHashSet c = []\n" +
356+
" assert c instanceof LinkedHashSet\n" +
357+
"}\n" +
358+
"test()\n",
359+
};
360+
//@formatter:on
361+
362+
runConformTest(sources, "");
363+
}
364+
319365
@Test
320366
public void testTypeChecked6938() {
321367
//@formatter:off
@@ -357,6 +403,151 @@ public void testTypeChecked6938() {
357403
runConformTest(sources, "null");
358404
}
359405

406+
@Test
407+
public void testTypeChecked7106() {
408+
//@formatter:off
409+
String[] sources = {
410+
"Main.groovy",
411+
"void m(Map<String,Object> map) {\n" +
412+
"}\n" +
413+
"@groovy.transform.TypeChecked\n" +
414+
"void test() {\n" +
415+
" ['x'].each {\n" +
416+
" m([(it): it.toLowerCase()])\n" +
417+
" }\n" +
418+
"}\n" +
419+
"test()\n",
420+
};
421+
//@formatter:on
422+
423+
runConformTest(sources, "");
424+
}
425+
426+
@Test
427+
public void testTypeChecked7128() {
428+
//@formatter:off
429+
String[] sources = {
430+
"Main.groovy",
431+
"@groovy.transform.TypeChecked\n" +
432+
"void test() {\n" +
433+
" List<Number> list = [1,2,3]\n" +
434+
" Set<Number> set = [1,2,3,3]\n" +
435+
"}\n" +
436+
"test()\n",
437+
};
438+
//@formatter:on
439+
440+
runConformTest(sources, "");
441+
}
442+
443+
@Test
444+
public void testTypeChecked7128a() {
445+
//@formatter:off
446+
String[] sources = {
447+
"Main.groovy",
448+
"@groovy.transform.TypeChecked\n" +
449+
"void test() {\n" +
450+
" def a = [:]\n" +
451+
" assert a instanceof Map\n" +
452+
" Map b = [:]\n" +
453+
" assert b instanceof Map\n" +
454+
" Object c = [:]\n" +
455+
" assert c instanceof Map\n" +
456+
" HashMap d = [:]\n" +
457+
" assert d instanceof HashMap\n" +
458+
" LinkedHashMap e = [:]\n" +
459+
" assert e instanceof LinkedHashMap\n" +
460+
"}\n" +
461+
"test()\n",
462+
};
463+
//@formatter:on
464+
465+
runConformTest(sources, "");
466+
}
467+
468+
@Test
469+
public void testTypeChecked7128b() {
470+
for (String spec : new String[] {"CharSequence,Integer", "String,Number", "CharSequence,Number"}) {
471+
//@formatter:off
472+
String[] sources = {
473+
"Main.groovy",
474+
"@groovy.transform.TypeChecked\n" +
475+
"void test() {\n" +
476+
" Map<" + spec + "> map = [a:1,b:2,c:3]\n" +
477+
" assert map.size() == 3\n" +
478+
" assert map['c'] == 3\n" +
479+
" assert !('x' in map)\n" +
480+
"}\n" +
481+
"test()\n",
482+
};
483+
//@formatter:on
484+
485+
runConformTest(sources, "");
486+
}
487+
}
488+
489+
@Test
490+
public void testTypeChecked7128c() {
491+
//@formatter:off
492+
String[] sources = {
493+
"Main.groovy",
494+
"@groovy.transform.TypeChecked\n" +
495+
"void test() {\n" +
496+
" Map<String,Integer> map = [1:2]\n" +
497+
"}\n" +
498+
"test()\n",
499+
};
500+
//@formatter:on
501+
502+
runNegativeTest(sources,
503+
"----------\n" +
504+
"1. ERROR in Main.groovy (at line 3)\n" +
505+
"\tMap<String,Integer> map = [1:2]\n" +
506+
"\t ^^^^^\n" +
507+
"Groovy:[Static type checking] - Incompatible generic argument types. Cannot assign java.util.LinkedHashMap <java.lang.Integer, java.lang.Integer> to: java.util.Map <String, Integer>\n" +
508+
"----------\n");
509+
}
510+
511+
@Test
512+
public void testTypeChecked7128d() {
513+
//@formatter:off
514+
String[] sources = {
515+
"Main.groovy",
516+
"class A<B,C> {\n" +
517+
" int x\n" +
518+
" int y\n" +
519+
"}\n" +
520+
"@groovy.transform.TypeChecked\n" +
521+
"void test() {\n" +
522+
" A<Number,String> a = [x:100, y:200]\n" +
523+
" assert a.x == 100\n" +
524+
" assert a.y == 200\n" +
525+
"}\n" +
526+
"test()\n",
527+
};
528+
//@formatter:on
529+
530+
runConformTest(sources, "");
531+
}
532+
533+
@Test
534+
public void testTypeChecked7274() {
535+
//@formatter:off
536+
String[] sources = {
537+
"Main.groovy",
538+
"void m(Map<String,Object> map) {\n" +
539+
"}\n" +
540+
"@groovy.transform.TypeChecked\n" +
541+
"void test() {\n" +
542+
" m([d:new Date(), i:1, s:''])\n" +
543+
"}\n" +
544+
"test()\n",
545+
};
546+
//@formatter:on
547+
548+
runConformTest(sources, "");
549+
}
550+
360551
@Test
361552
public void testTypeChecked7333() {
362553
//@formatter:off
@@ -437,6 +628,28 @@ public void testTypeChecked7945() {
437628
"----------\n");
438629
}
439630

631+
@Test
632+
public void testTypeChecked8001() {
633+
//@formatter:off
634+
String[] sources = {
635+
"Main.groovy",
636+
"class C {\n" +
637+
" Map<String,Object> map\n" +
638+
"}\n" +
639+
"@groovy.transform.TypeChecked\n" +
640+
"void test() {\n" +
641+
" int value = 42\n" +
642+
" def c = new C()\n" +
643+
" c.map = [key:\"$value\"]\n" +
644+
" print c.map\n" +
645+
"}\n" +
646+
"test()\n",
647+
};
648+
//@formatter:on
649+
650+
runConformTest(sources, "[key:42]");
651+
}
652+
440653
@Test
441654
public void testTypeChecked8034() {
442655
//@formatter:off
@@ -510,6 +723,49 @@ public void testTypeChecked8103() {
510723
runNegativeTest(sources, "");
511724
}
512725

726+
@Test
727+
public void testTypeChecked8909() {
728+
//@formatter:off
729+
String[] sources = {
730+
"Main.groovy",
731+
"void m(List<Object> list) {\n" +
732+
" assert list.size() == 3\n" +
733+
"}\n" +
734+
"@groovy.transform.TypeChecked\n" +
735+
"void test() {\n" +
736+
" m([1,2,3])\n" +
737+
"}\n" +
738+
"test()\n",
739+
};
740+
//@formatter:on
741+
742+
runConformTest(sources, "");
743+
}
744+
745+
@Test
746+
public void testTypeChecked8909a() {
747+
//@formatter:off
748+
String[] sources = {
749+
"Main.groovy",
750+
"void m(Set<Integer> set) {\n" +
751+
"}\n" +
752+
"@groovy.transform.TypeChecked\n" +
753+
"void test() {\n" +
754+
" m([1,2,3])\n" +
755+
"}\n" +
756+
"test()\n",
757+
};
758+
//@formatter:on
759+
760+
runNegativeTest(sources,
761+
"----------\n" +
762+
"1. ERROR in Main.groovy (at line 5)\n" +
763+
"\tm([1,2,3])\n" +
764+
"\t^^^^^^^^^^\n" +
765+
"Groovy:[Static type checking] - Cannot find matching method Main#m(java.util.List <java.lang.Integer>). Please check if the declared type is correct and if the method exists.\n" +
766+
"----------\n");
767+
}
768+
513769
@Test
514770
public void testTypeChecked9460() {
515771
//@formatter:off
@@ -785,6 +1041,27 @@ public void testTypeChecked9822() {
7851041
runNegativeTest(sources, "");
7861042
}
7871043

1044+
@Test
1045+
public void testTypeChecked9844() {
1046+
//@formatter:off
1047+
String[] sources = {
1048+
"Main.groovy",
1049+
"void m(Map<String, Object> map) {\n" +
1050+
" print map\n" +
1051+
"}\n" +
1052+
"@groovy.transform.TypeChecked\n" +
1053+
"void test() {\n" +
1054+
" Map<String, Object> map = [key: 'val']\n" +
1055+
" m([key: 'val'])\n" +
1056+
" m(key: 'val')\n" +
1057+
"}\n" +
1058+
"test()\n",
1059+
};
1060+
//@formatter:on
1061+
1062+
runConformTest(sources, "[key:val][key:val]");
1063+
}
1064+
7881065
@Ignore @Test
7891066
public void testTypeChecked9873() {
7901067
Map<String, String> options = getCompilerOptions();

0 commit comments

Comments
 (0)