Skip to content

Commit 83bcfd6

Browse files
committed
A refactoring
1 parent 68656d4 commit 83bcfd6

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,20 +2008,21 @@ class Definitions {
20082008
vcls
20092009
}
20102010

2011+
def boxedClass(cls: Symbol): ClassSymbol =
2012+
if cls eq ByteClass then BoxedByteClass
2013+
else if cls eq ShortClass then BoxedShortClass
2014+
else if cls eq CharClass then BoxedCharClass
2015+
else if cls eq IntClass then BoxedIntClass
2016+
else if cls eq LongClass then BoxedLongClass
2017+
else if cls eq FloatClass then BoxedFloatClass
2018+
else if cls eq DoubleClass then BoxedDoubleClass
2019+
else if cls eq UnitClass then BoxedUnitClass
2020+
else if cls eq BooleanClass then BoxedBooleanClass
2021+
else sys.error(s"Not a primitive value type: $cls")
2022+
20112023
/** The type of the boxed class corresponding to primitive value type `tp`. */
2012-
def boxedType(tp: Type)(using Context): TypeRef = {
2013-
val cls = tp.classSymbol
2014-
if (cls eq ByteClass) BoxedByteClass
2015-
else if (cls eq ShortClass) BoxedShortClass
2016-
else if (cls eq CharClass) BoxedCharClass
2017-
else if (cls eq IntClass) BoxedIntClass
2018-
else if (cls eq LongClass) BoxedLongClass
2019-
else if (cls eq FloatClass) BoxedFloatClass
2020-
else if (cls eq DoubleClass) BoxedDoubleClass
2021-
else if (cls eq UnitClass) BoxedUnitClass
2022-
else if (cls eq BooleanClass) BoxedBooleanClass
2023-
else sys.error(s"Not a primitive value type: $tp")
2024-
}.typeRef
2024+
def boxedType(tp: Type)(using Context): TypeRef =
2025+
boxedClass(tp.classSymbol).typeRef
20252026

20262027
def unboxedType(tp: Type)(using Context): TypeRef = {
20272028
val cls = tp.classSymbol

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
166166

167167
def cmpWithBoxed(cls1: ClassSymbol, cls2: ClassSymbol) =
168168
cls2 == defn.NothingClass
169-
|| cls2 == defn.boxedType(cls1.typeRef).symbol
169+
|| cls2 == defn.boxedClass(cls1)
170170
|| cls1.isNumericValueClass && cls2.derivesFrom(defn.BoxedNumberClass)
171171

172172
if cls1.isPrimitiveValueClass then

0 commit comments

Comments
 (0)