Description
Performing runtime subtype checks with <:<
sometimes fails on Java classes.
With this code
I get:
$ javac Test.java
$ scalac RunTest.scala
$ scala RunTest
Test <:< Test:true
----------------------------------------------
Test <:< Bar:illegal cyclic reference involving type T
----------------------------------------------
Bar <:< Test:illegal cyclic inheritance involving class Test
----------------------------------------------
Bar <:< Bar:true
----------------------------------------------
I tested Scala versions 2.10.6
, 2.11.8
and 2.12.2
, which all have the same problem. I'm using Java version 1.8.0_112
.
Note that turning the lambda function in Test.java into an anonymous inner class solves the issue. There is an article on InfoQ with details about the differences between lambdas and anonymous inner classes, which might be relevant.
The bug also disappears when using
class RefType<T extends RefType<?>> extends Base {}
instead of
class RefType<T extends RefType> extends Base {}
This might also be related to #3809 , but -Ybreak-cycles during compilation can and does not help here.
I ran into this bug, because of NodeWithThrownExceptions and MethodDeclaration in the current JavaParser release 3.2.3.
Here are full stacktraces for Test <: Bar
and Bar <: Test
.
Note that oddly getLocalizedMessage
for Bar <: Test
also seems to be different from the stacktrace without any try/catch block, while it is identical in the Test <: Bar
case.