Skip to content

Commit

Permalink
Do match type reduction atPhaseNoLater than ElimOpaque
Browse files Browse the repository at this point in the history
If a match type pattern is an opaque type, we use its bounds when checking the validity of the pattern.
Following the ElimOpaque phase however, the pattern is beta-reduced (as normal applied type aliases), which may result in an illegal pattern.
  • Loading branch information
EugeneFlesselle committed Mar 26, 2024
1 parent 2329236 commit 2beb67e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ object Phases {
private var myPatmatPhase: Phase = uninitialized
private var myElimRepeatedPhase: Phase = uninitialized
private var myElimByNamePhase: Phase = uninitialized
private var myElimOpaquePhase: Phase = uninitialized
private var myExtensionMethodsPhase: Phase = uninitialized
private var myExplicitOuterPhase: Phase = uninitialized
private var myGettersPhase: Phase = uninitialized
Expand All @@ -245,6 +246,7 @@ object Phases {
final def patmatPhase: Phase = myPatmatPhase
final def elimRepeatedPhase: Phase = myElimRepeatedPhase
final def elimByNamePhase: Phase = myElimByNamePhase
final def elimOpaquePhase: Phase = myElimOpaquePhase
final def extensionMethodsPhase: Phase = myExtensionMethodsPhase
final def explicitOuterPhase: Phase = myExplicitOuterPhase
final def gettersPhase: Phase = myGettersPhase
Expand Down Expand Up @@ -272,6 +274,7 @@ object Phases {
myRefChecksPhase = phaseOfClass(classOf[RefChecks])
myElimRepeatedPhase = phaseOfClass(classOf[ElimRepeated])
myElimByNamePhase = phaseOfClass(classOf[ElimByName])
myElimOpaquePhase = phaseOfClass(classOf[ElimOpaque])
myExtensionMethodsPhase = phaseOfClass(classOf[ExtensionMethods])
myErasurePhase = phaseOfClass(classOf[Erasure])
myElimErasedValueTypePhase = phaseOfClass(classOf[ElimErasedValueType])
Expand Down Expand Up @@ -511,6 +514,7 @@ object Phases {
def refchecksPhase(using Context): Phase = ctx.base.refchecksPhase
def elimRepeatedPhase(using Context): Phase = ctx.base.elimRepeatedPhase
def elimByNamePhase(using Context): Phase = ctx.base.elimByNamePhase
def elimOpaquePhase(using Context): Phase = ctx.base.elimOpaquePhase
def extensionMethodsPhase(using Context): Phase = ctx.base.extensionMethodsPhase
def explicitOuterPhase(using Context): Phase = ctx.base.explicitOuterPhase
def gettersPhase(using Context): Phase = ctx.base.gettersPhase
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5026,7 +5026,7 @@ object Types extends TypeUtils {

private def thisMatchType = this

def reduced(using Context): Type = {
def reduced(using Context): Type = atPhaseNoLater(elimOpaquePhase) {

def contextInfo(tp: Type): Type = tp match {
case tp: TypeParamRef =>
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i19434.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

object Test:

object Named:
opaque type Named[name <: String & Singleton, A] >: A = A

type DropNames[T <: Tuple] = T match
case Named.Named[_, x] *: xs => x *: DropNames[xs]
case _ => T

def f[T <: Tuple]: DropNames[T] = ???

0 comments on commit 2beb67e

Please sign in to comment.