Skip to content

Refine "allow basetype" criterion for match type reduction #15337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -755,21 +755,22 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
fourthTry
}

def tryBaseType(cls2: Symbol) = {
val allowBaseType = !caseLambda.exists || (tp1 match {
case tp: TypeRef if tp.symbol.isClass => true
case AppliedType(tycon: TypeRef, _) if tycon.symbol.isClass => true
case _ => false
})
def allowBaseTypeForMatchSelector(tp: Type): Boolean = tp.dealias match
case tp: TypeRef => tp.symbol.isClass
case AppliedType(tycon, _) => allowBaseTypeForMatchSelector(tycon)
case tp: TypeProxy => allowBaseTypeForMatchSelector(tp.superType)
case tp: AndOrType => allowBaseTypeForMatchSelector(tp.tp1) || allowBaseTypeForMatchSelector(tp.tp2)
case _ => false

def tryBaseType(cls2: Symbol) =
val base = nonExprBaseType(tp1, cls2)
if (base.exists && base.ne(tp1) && allowBaseType)
isSubType(base, tp2, if (tp1.isRef(cls2)) approx else approx.addLow) ||
base.isInstanceOf[OrType] && fourthTry
// if base is a disjunction, this might have come from a tp1 type that
// expands to a match type. In this case, we should try to reduce the type
// and compare the redux. This is done in fourthTry
if base.exists && base.ne(tp1) && (!caseLambda.exists || allowBaseTypeForMatchSelector(tp1)) then
isSubType(base, tp2, if (tp1.isRef(cls2)) approx else approx.addLow)
|| base.isInstanceOf[OrType] && fourthTry
// if base is a disjunction, this might have come from a tp1 type that
// expands to a match type. In this case, we should try to reduce the type
// and compare the redux. This is done in fourthTry
else fourthTry
}

def fourthTry: Boolean = tp1 match {
case tp1: TypeRef =>
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i15319.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type FAux[A0] = Object{type A = A0}

type F[t] =
t match
case FAux[a] => a

val a: F[{type A = Int}] = 10
val b: F[{type A = String}] = "asd"