Skip to content

Commit ddd9a49

Browse files
committed
Disentangle enum case widening from dropTransparenTrait
Enum case widening is really about stripping the runtime.EnumValue class, the other parts are incidental.
1 parent 0ae3f0c commit ddd9a49

File tree

5 files changed

+4
-7
lines changed

5 files changed

+4
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ trait ConstraintHandling {
458458
* types (since in this case the type was not a true intersection of transparent traits
459459
* and other types to start with).
460460
*/
461-
def dropTransparentTraits(tp: Type, bound: Type)(using Context): Type =
461+
private def dropTransparentTraits(tp: Type, bound: Type)(using Context): Type =
462462
var kept: Set[Type] = Set() // types to keep since otherwise bound would not fit
463463
var dropped: List[Type] = List() // the types dropped so far, last one on top
464464

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ class Definitions {
740740
@tu lazy val EnumClass: ClassSymbol = requiredClass("scala.reflect.Enum")
741741
@tu lazy val Enum_ordinal: Symbol = EnumClass.requiredMethod(nme.ordinal)
742742

743+
@tu lazy val EnumValueClass: ClassSymbol = requiredClass("scala.runtime.EnumValue")
743744
@tu lazy val EnumValueSerializationProxyClass: ClassSymbol = requiredClass("scala.runtime.EnumValueSerializationProxy")
744745
@tu lazy val EnumValueSerializationProxyConstructor: TermSymbol =
745746
EnumValueSerializationProxyClass.requiredMethod(nme.CONSTRUCTOR, List(ClassType(TypeBounds.empty), IntType))

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,9 +2875,6 @@ object TypeComparer {
28752875
def widenInferred(inst: Type, bound: Type)(using Context): Type =
28762876
comparing(_.widenInferred(inst, bound))
28772877

2878-
def dropTransparentTraits(tp: Type, bound: Type)(using Context): Type =
2879-
comparing(_.dropTransparentTraits(tp, bound))
2880-
28812878
def constrainPatternType(pat: Type, scrut: Type, forceInvariantRefinement: Boolean = false)(using Context): Boolean =
28822879
comparing(_.constrainPatternType(pat, scrut, forceInvariantRefinement))
28832880

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,8 @@ trait Applications extends Compatibility {
11811181
&& tree.tpe.classSymbol.isEnumCase
11821182
&& tree.tpe.widen.isValueType
11831183
then
1184-
val widened = TypeComparer.dropTransparentTraits(
1185-
tree.tpe.parents.reduceLeft(TypeComparer.andType(_, _)),
1186-
pt)
1184+
val widened = tree.tpe.parents.filter(_.typeSymbol != defn.EnumValueClass)
1185+
.reduceLeft(TypeComparer.andType(_, _))
11871186
if widened <:< pt then Typed(tree, TypeTree(widened))
11881187
else tree
11891188
else tree
File renamed without changes.

0 commit comments

Comments
 (0)