Skip to content

Commit

Permalink
Disentangle enum case widening from dropTransparenTrait
Browse files Browse the repository at this point in the history
Enum case widening is really about stripping the runtime.EnumValue class,
the other parts are incidental.
  • Loading branch information
odersky committed Jul 11, 2022
1 parent 0ae3f0c commit ddd9a49
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ trait ConstraintHandling {
* types (since in this case the type was not a true intersection of transparent traits
* and other types to start with).
*/
def dropTransparentTraits(tp: Type, bound: Type)(using Context): Type =
private def dropTransparentTraits(tp: Type, bound: Type)(using Context): Type =
var kept: Set[Type] = Set() // types to keep since otherwise bound would not fit
var dropped: List[Type] = List() // the types dropped so far, last one on top

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ class Definitions {
@tu lazy val EnumClass: ClassSymbol = requiredClass("scala.reflect.Enum")
@tu lazy val Enum_ordinal: Symbol = EnumClass.requiredMethod(nme.ordinal)

@tu lazy val EnumValueClass: ClassSymbol = requiredClass("scala.runtime.EnumValue")
@tu lazy val EnumValueSerializationProxyClass: ClassSymbol = requiredClass("scala.runtime.EnumValueSerializationProxy")
@tu lazy val EnumValueSerializationProxyConstructor: TermSymbol =
EnumValueSerializationProxyClass.requiredMethod(nme.CONSTRUCTOR, List(ClassType(TypeBounds.empty), IntType))
Expand Down
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2875,9 +2875,6 @@ object TypeComparer {
def widenInferred(inst: Type, bound: Type)(using Context): Type =
comparing(_.widenInferred(inst, bound))

def dropTransparentTraits(tp: Type, bound: Type)(using Context): Type =
comparing(_.dropTransparentTraits(tp, bound))

def constrainPatternType(pat: Type, scrut: Type, forceInvariantRefinement: Boolean = false)(using Context): Boolean =
comparing(_.constrainPatternType(pat, scrut, forceInvariantRefinement))

Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,8 @@ trait Applications extends Compatibility {
&& tree.tpe.classSymbol.isEnumCase
&& tree.tpe.widen.isValueType
then
val widened = TypeComparer.dropTransparentTraits(
tree.tpe.parents.reduceLeft(TypeComparer.andType(_, _)),
pt)
val widened = tree.tpe.parents.filter(_.typeSymbol != defn.EnumValueClass)
.reduceLeft(TypeComparer.andType(_, _))
if widened <:< pt then Typed(tree, TypeTree(widened))
else tree
else tree
Expand Down
File renamed without changes.

0 comments on commit ddd9a49

Please sign in to comment.