Skip to content

Commit

Permalink
A refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jun 28, 2023
1 parent 68656d4 commit 83bcfd6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2008,20 +2008,21 @@ class Definitions {
vcls
}

def boxedClass(cls: Symbol): ClassSymbol =
if cls eq ByteClass then BoxedByteClass
else if cls eq ShortClass then BoxedShortClass
else if cls eq CharClass then BoxedCharClass
else if cls eq IntClass then BoxedIntClass
else if cls eq LongClass then BoxedLongClass
else if cls eq FloatClass then BoxedFloatClass
else if cls eq DoubleClass then BoxedDoubleClass
else if cls eq UnitClass then BoxedUnitClass
else if cls eq BooleanClass then BoxedBooleanClass
else sys.error(s"Not a primitive value type: $cls")

/** The type of the boxed class corresponding to primitive value type `tp`. */
def boxedType(tp: Type)(using Context): TypeRef = {
val cls = tp.classSymbol
if (cls eq ByteClass) BoxedByteClass
else if (cls eq ShortClass) BoxedShortClass
else if (cls eq CharClass) BoxedCharClass
else if (cls eq IntClass) BoxedIntClass
else if (cls eq LongClass) BoxedLongClass
else if (cls eq FloatClass) BoxedFloatClass
else if (cls eq DoubleClass) BoxedDoubleClass
else if (cls eq UnitClass) BoxedUnitClass
else if (cls eq BooleanClass) BoxedBooleanClass
else sys.error(s"Not a primitive value type: $tp")
}.typeRef
def boxedType(tp: Type)(using Context): TypeRef =
boxedClass(tp.classSymbol).typeRef

def unboxedType(tp: Type)(using Context): TypeRef = {
val cls = tp.classSymbol
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Synthesizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):

def cmpWithBoxed(cls1: ClassSymbol, cls2: ClassSymbol) =
cls2 == defn.NothingClass
|| cls2 == defn.boxedType(cls1.typeRef).symbol
|| cls2 == defn.boxedClass(cls1)
|| cls1.isNumericValueClass && cls2.derivesFrom(defn.BoxedNumberClass)

if cls1.isPrimitiveValueClass then
Expand Down

0 comments on commit 83bcfd6

Please sign in to comment.