Skip to content

Commit 656c248

Browse files
committed
Fix compatibility of Java with value classes
This avoids getting a runtime error when calling a Java-defined method whose signature contains value classes. It happened because we erased the value classes in this signature even though it comes from a classfile. Amusingly, this problem also exists in scalac: <https://issues.scala-lang.org/browse/SI-9298>
1 parent c3a7f46 commit 656c248

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,15 @@ object TypeErasure {
145145
* - For companion methods : the erasure of their type with semiEraseVCs = false.
146146
* The signature of these methods are used to keep a
147147
* link between companions and should not be semi-erased.
148+
* - For Java-defined symbols: : the erasure of their type with isJava = true,
149+
* semiEraseVCs = false. Semi-erasure never happens in Java.
148150
* - For all other symbols : the semi-erasure of their types, with
149151
* isJava, isConstructor set according to symbol.
150152
*/
151153
def transformInfo(sym: Symbol, tp: Type)(implicit ctx: Context): Type = {
152-
val semiEraseVCs = !sym.isCompanionMethod
153-
val erase = erasureFn(sym is JavaDefined, semiEraseVCs, sym.isConstructor, wildcardOK = false)
154+
val isJava = sym is JavaDefined
155+
val semiEraseVCs = !isJava && !sym.isCompanionMethod
156+
val erase = erasureFn(isJava, semiEraseVCs, sym.isConstructor, wildcardOK = false)
154157

155158
def eraseParamBounds(tp: PolyType): Type =
156159
tp.derivedPolyType(

0 commit comments

Comments
 (0)