Skip to content

Commit 67ffb4b

Browse files
committed
A refactoring
1 parent a9574a4 commit 67ffb4b

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
@@ -2009,20 +2009,21 @@ class Definitions {
20092009
vcls
20102010
}
20112011

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

20272028
def unboxedType(tp: Type)(using Context): TypeRef = {
20282029
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)