@@ -218,6 +218,31 @@ public void testTypeChecked9() {
218
218
runNegativeTest (sources , "" );
219
219
}
220
220
221
+ @ Test
222
+ public void testTypeChecked6786 () {
223
+ //@formatter:off
224
+ String [] sources = {
225
+ "Main.groovy" ,
226
+ "class C<X> {\n " +
227
+ " Container<X> container\n " +
228
+ " @groovy.transform.TypeChecked\n " +
229
+ " void refresh() {\n " +
230
+ " def items = findAllItems()\n " +
231
+ " container.addAll(items)\n " + // Cannot call Container#addAll(java.util.Collection<? extends X>) with arguments [java.util.Collection<X>]
232
+ " }\n " +
233
+ " Collection<X> findAllItems() {\n " +
234
+ " }\n " +
235
+ "}\n " +
236
+ "interface Container<Y> {\n " +
237
+ " void addAll(Collection<? extends Y> collection)\n " +
238
+ "}\n " +
239
+ "new C()\n " ,
240
+ };
241
+ //@formatter:on
242
+
243
+ runNegativeTest (sources , "" );
244
+ }
245
+
221
246
@ Test
222
247
public void testTypeChecked6882 () {
223
248
//@formatter:off
@@ -633,6 +658,59 @@ public void testTypeChecked9873() {
633
658
runConformTest (sources , "123" , options );
634
659
}
635
660
661
+ @ Test
662
+ public void testTypeChecked9902 () {
663
+ //@formatter:off
664
+ String [] sources = {
665
+ "Main.groovy" ,
666
+ "class Holder<Unknown> {\n " +
667
+ " TypedProperty<Number, Unknown> numberProperty = prop(Number)\n " +
668
+ " TypedProperty<String, Unknown> stringProperty = prop(String)\n " +
669
+ " def <T> TypedProperty<T, Unknown> prop(Class<T> clazz) {\n " +
670
+ " new TypedProperty<T, Unknown>(clazz: clazz)\n " +
671
+ " }\n " +
672
+ // Note: type argument of Holder cannot be supplied to value attribute of @DelegatesTo
673
+ " def <T> T of(@DelegatesTo(value=Holder, strategy=Closure.DELEGATE_FIRST) Closure<T> c) {\n " +
674
+ " this.with(c)\n " +
675
+ " }\n " +
676
+ "}\n " +
677
+ "class TypedProperty<X, Y> {\n " +
678
+ " Class<X> clazz\n " +
679
+ " void eq(X x) {\n " +
680
+ " assert x.class == clazz : \" x.class is ${x.class} not ${clazz}\" \n " +
681
+ " }\n " +
682
+ "}\n " +
683
+ "@groovy.transform.TypeChecked\n " +
684
+ "void test(Holder<Object> h) {\n " +
685
+ " h.stringProperty.eq(\" ${0}\" )\n " + // STC error
686
+ " h.of {\n " + // <-- 2nd type parameter discarded
687
+ " stringProperty.eq(1234)\n " + // expect STC error
688
+ " numberProperty.eq('xx')\n " + // expect STC error
689
+ " }\n " +
690
+ "}\n " +
691
+ "test(new Holder<Object>())\n " ,
692
+ };
693
+ //@formatter:on
694
+
695
+ runNegativeTest (sources ,
696
+ "----------\n " +
697
+ "1. ERROR in Main.groovy (at line 19)\n " +
698
+ "\t h.stringProperty.eq(\" ${0}\" )\n " +
699
+ "\t ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n " +
700
+ "Groovy:[Static type checking] - Cannot call TypedProperty <String, Object>#eq(java.lang.String) with arguments [groovy.lang.GString] \n " +
701
+ "----------\n " +
702
+ "2. ERROR in Main.groovy (at line 21)\n " +
703
+ "\t stringProperty.eq(1234)\n " +
704
+ "\t ^^^^^^^^^^^^^^^^^^^^^^^\n " +
705
+ "Groovy:[Static type checking] - Cannot call TypedProperty <String, Unknown>#eq(java.lang.String) with arguments [int] \n " +
706
+ "----------\n " +
707
+ "3. ERROR in Main.groovy (at line 22)\n " +
708
+ "\t numberProperty.eq('xx')\n " +
709
+ "\t ^^^^^^^^^^^^^^^^^^^^^^^\n " +
710
+ "Groovy:[Static type checking] - Cannot call TypedProperty <Number, Unknown>#eq(java.lang.Number) with arguments [java.lang.String] \n " +
711
+ "----------\n " );
712
+ }
713
+
636
714
@ Test
637
715
public void testTypeChecked9903 () {
638
716
//@formatter:off
0 commit comments