Skip to content

Commit 09c6471

Browse files
committed
Make ValueClass operations take Symbols, not SymDenotations
1 parent 65b3a8e commit 09c6471

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

compiler/src/dotty/tools/dotc/transform/TreeExtractors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ object TreeExtractors {
3636
object ValueClassUnbox {
3737
def unapply(t: Tree)(implicit ctx: Context): Option[Tree] = t match {
3838
case Apply(sel @ Select(ref, _), Nil) =>
39-
val d = ref.tpe.widenDealias.typeSymbol.denot
40-
if (isDerivedValueClass(d) && (sel.symbol eq valueClassUnbox(d.asClass))) {
39+
val sym = ref.tpe.widenDealias.typeSymbol
40+
if (isDerivedValueClass(sym) && (sel.symbol eq valueClassUnbox(sym.asClass))) {
4141
Some(ref)
4242
} else
4343
None

compiler/src/dotty/tools/dotc/transform/ValueClasses.scala

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package transform
44
import core._
55
import Types._
66
import Symbols._
7-
import SymDenotations._
87
import Contexts._
98
import Flags._
109
import StdNames._
@@ -13,15 +12,14 @@ import SymUtils._
1312
/** Methods that apply to user-defined value classes */
1413
object ValueClasses {
1514

16-
def isDerivedValueClass(d: SymDenotation)(implicit ctx: Context): Boolean = {
15+
def isDerivedValueClass(sym: Symbol)(implicit ctx: Context): Boolean = {
16+
val d = sym.denot
1717
!ctx.settings.XnoValueClasses.value &&
1818
!d.isRefinementClass &&
1919
d.isValueClass &&
2020
(d.initial.symbol ne defn.AnyValClass) && // Compare the initial symbol because AnyVal does not exist after erasure
2121
!d.isPrimitiveValueClass
2222
}
23-
def isDerivedValueClass(sym: Symbol)(implicit ctx: Context): Boolean =
24-
isDerivedValueClass(sym.denot)
2523

2624
def isMethodWithExtension(sym: Symbol)(implicit ctx: Context) =
2725
ctx.atPhaseNotLaterThan(ctx.extensionMethodsPhase) { implicit ctx =>
@@ -35,12 +33,9 @@ object ValueClasses {
3533
}
3634

3735
/** The member of a derived value class that unboxes it. */
38-
def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol =
39-
// (info.decl(nme.unbox)).orElse(...) uncomment once we accept unbox methods
40-
d.classInfo.decls.find(_.is(ParamAccessor))
41-
4236
def valueClassUnbox(cls: ClassSymbol)(implicit ctx: Context): Symbol =
43-
valueClassUnbox(cls.classDenot)
37+
// (info.decl(nme.unbox)).orElse(...) uncomment once we accept unbox methods
38+
cls.classInfo.decls.find(_.is(ParamAccessor))
4439

4540
/** For a value class `d`, this returns the synthetic cast from the underlying type to
4641
* ErasedValueType defined in the companion module. This method is added to the module
@@ -57,10 +52,8 @@ object ValueClasses {
5752
d.linkedClass.info.decl(nme.EVT2U).symbol
5853

5954
/** The unboxed type that underlies a derived value class */
60-
def underlyingOfValueClass(d: ClassDenotation)(implicit ctx: Context): Type =
61-
valueClassUnbox(d).info.resultType
6255
def underlyingOfValueClass(sym: ClassSymbol)(implicit ctx: Context): Type =
63-
underlyingOfValueClass(sym.classDenot)
56+
valueClassUnbox(sym).info.resultType
6457

6558
/** Whether a value class wraps itself */
6659
def isCyclic(cls: ClassSymbol)(implicit ctx: Context): Boolean = {

0 commit comments

Comments
 (0)