File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
org/codehaus/groovy/classgen/asm/sc Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -211,6 +211,21 @@ class CoercionSTCTest extends StaticTypeCheckingTestCase {
211
211
'''
212
212
}
213
213
214
+ void testCastObjectToInterface () {
215
+ assertScript '''
216
+ List<Object> m(object) {
217
+ if (object == null) return new ArrayList<>()
218
+ if (object instanceof Collection) return new ArrayList<Object>((Collection) object)
219
+ return [object]
220
+ }
221
+ def item = 0
222
+ def list = [1,2]
223
+ assert m(null).size() == 0
224
+ assert m(item).size() == 1
225
+ assert m(list).size() == 2
226
+ '''
227
+ }
228
+
214
229
void testCastInterfaceToSubclass () {
215
230
assertScript '''
216
231
interface A {
Original file line number Diff line number Diff line change @@ -24,4 +24,12 @@ import groovy.transform.stc.CoercionSTCTest
24
24
* Unit tests for static compilation : coercions.
25
25
*/
26
26
final class CoercionStaticCompileTests extends CoercionSTCTest implements StaticCompilationTestSupport {
27
+
28
+ @Override // GROOVY-11769
29
+ void testCastObjectToInterface () {
30
+ super . testCastObjectToInterface()
31
+ String bytecode = astTrees. values()[0 ][1 ]
32
+ bytecode = bytecode. substring(bytecode. indexOf(' m(Ljava/lang/Object;)' ))
33
+ assert bytecode. count(' CHECKCAST' ) == 1 // guarded typecast isn't groovy
34
+ }
27
35
}
You can’t perform that action at this time.
0 commit comments