Skip to content

Commit 7387da3

Browse files
committed
Preserve tvar bounds that represent kinds
The kinds of type variables being solved are represented by by their upper bounds. If we loose track of these then kinds will be incorrect on the RHS of inline matches and match types. Without the additional change in TypeComparer this breaks tests/pos/i5574.scala. The added fallback to fourthTry brings the higher kinded case into line with the path that's followed in the simply kinded case and restores the correct behaviour. Unfortunately I'm not able to justify it other than that it emerged from extensive trial and error and comparison with the simply kinded case. I'd also love to understand the use return in TypeComparer. Is it an optimization or does it have some semantic significance? Fixes #6014.
1 parent 8ecc927 commit 7387da3

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,10 @@ object Contexts {
929929
// - we don't want TyperState instantiating these TypeVars
930930
// - we don't want TypeComparer constraining these TypeVars
931931
val poly = PolyType(DepParamName.fresh(sym.name.toTypeName) :: Nil)(
932-
pt => TypeBounds.empty :: Nil,
932+
pt => (sym.info match {
933+
case tb @ TypeBounds(lo, hi) if (lo eq defn.NothingType) && hi.isLambdaSub => tb
934+
case _ => TypeBounds.empty
935+
}) :: Nil,
933936
pt => defn.AnyType)
934937
new TypeVar(poly.paramRefs.head, creatorState = null)
935938
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
559559
if (tparams1.nonEmpty)
560560
return recur(
561561
HKTypeLambda.fromParams(tparams1, tp1.appliedTo(tparams1.map(_.paramRef))),
562-
tp2)
562+
tp2) || fourthTry
563563
else tp2 match {
564564
case EtaExpansion(tycon2) if tycon2.symbol.isClass =>
565565
return recur(tp1, tycon2)

compiler/test/dotc/pos-from-tasty.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ t6278-synth-def.scala
2727

2828
# Need to print empty tree for implicit match
2929
i5938.scala
30+
i6014.scala

tests/pos/i6014.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import scala.compiletime._
2+
3+
object Test1 {
4+
type Foo[F[_]]
5+
type Bar[T] = T match {
6+
case Foo[f] => f[Int]
7+
}
8+
9+
val li: Bar[Foo[List]] = List(1, 2, 3)
10+
}
11+
12+
object Test2 {
13+
inline def summon[T] = implicit match {
14+
case t: T => t
15+
}
16+
17+
class Foo[F[_]]
18+
19+
inline def bar[T] = inline erasedValue[T] match {
20+
case _: Foo[f] => summon[f[Int]]
21+
}
22+
23+
implicit val li: List[Int] = List(1, 2, 3)
24+
bar[Foo[List]]
25+
}

0 commit comments

Comments
 (0)