Skip to content

Commit dab903f

Browse files
committed
Scala.js: Handle value classes in JS interop.
1 parent d8a0bf6 commit dab903f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import Symbols._
2323
import Denotations._
2424
import Phases._
2525
import StdNames._
26+
import TypeErasure.ErasedValueType
2627

27-
import dotty.tools.dotc.transform.Erasure
28+
import dotty.tools.dotc.transform.{Erasure, ValueClasses}
2829
import dotty.tools.dotc.util.SourcePosition
2930
import dotty.tools.dotc.util.Spans.Span
3031
import dotty.tools.dotc.report
@@ -2599,10 +2600,10 @@ class JSCodeGen()(using genCtx: Context) {
25992600
case tpe if isPrimitiveValueType(tpe) =>
26002601
makePrimitiveBox(expr, tpe)
26012602

2602-
/*case tpe: ErasedValueType =>
2603-
val boxedClass = tpe.valueClazz
2603+
case tpe: ErasedValueType =>
2604+
val boxedClass = tpe.tycon.typeSymbol
26042605
val ctor = boxedClass.primaryConstructor
2605-
genNew(boxedClass, ctor, List(expr))*/
2606+
js.New(encodeClassName(boxedClass), encodeMethodSym(ctor), List(expr))
26062607

26072608
case _ =>
26082609
expr
@@ -2626,15 +2627,15 @@ class JSCodeGen()(using genCtx: Context) {
26262627
case tpe if isPrimitiveValueType(tpe) =>
26272628
makePrimitiveUnbox(expr, tpe)
26282629

2629-
/*case tpe: ErasedValueType =>
2630-
val boxedClass = tpe.valueClazz
2631-
val unboxMethod = boxedClass.derivedValueClassUnbox
2630+
case tpe: ErasedValueType =>
2631+
val boxedClass = tpe.tycon.typeSymbol.asClass
2632+
val unboxMethod = ValueClasses.valueClassUnbox(boxedClass)
26322633
val content = genApplyMethod(
2633-
genAsInstanceOf(expr, tpe), unboxMethod, Nil)
2634-
if (unboxMethod.tpe.resultType <:< tpe.erasedUnderlying)
2634+
js.AsInstanceOf(expr, encodeClassType(boxedClass)), unboxMethod, Nil)
2635+
if (unboxMethod.info.resultType <:< tpe.erasedUnderlying)
26352636
content
26362637
else
2637-
fromAny(content, tpe.erasedUnderlying)*/
2638+
unbox(content, tpe.erasedUnderlying)
26382639

26392640
case tpe =>
26402641
genAsInstanceOf(expr, tpe)
@@ -3587,8 +3588,9 @@ class JSCodeGen()(using genCtx: Context) {
35873588

35883589
private def isPrimitiveValueType(tpe: Type): Boolean = {
35893590
tpe.widenDealias match {
3590-
case JavaArrayType(_) => false
3591-
case t => t.typeSymbol.asClass.isPrimitiveValueClass
3591+
case JavaArrayType(_) => false
3592+
case _: ErasedValueType => false
3593+
case t => t.typeSymbol.asClass.isPrimitiveValueClass
35923594
}
35933595
}
35943596

0 commit comments

Comments
 (0)