Skip to content

Commit b9e24e6

Browse files
committed
Fix #7970: => T is not a subtupe of classtypes
It slipped through before, since baseType on ExprType is defined. This needs compensation in adapt.
1 parent 842e4c4 commit b9e24e6

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
482482
}
483483
else if (cls2.is(JavaDefined)) {
484484
// If `cls2` is parameterized, we are seeing a raw type, so we need to compare only the symbol
485-
val base = tp1.baseType(cls2)
485+
val base = nonExprBaseType(tp1, cls2)
486486
if (base.typeSymbol == cls2) return true
487487
}
488488
else if (tp1.isLambdaSub && !tp1.isRef(AnyKindClass))
@@ -706,7 +706,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
706706
}
707707

708708
def tryBaseType(cls2: Symbol) = {
709-
val base = tp1.baseType(cls2)
709+
val base = nonExprBaseType(tp1, cls2)
710710
if (base.exists && (base `ne` tp1))
711711
isSubType(base, tp2, if (tp1.isRef(cls2)) approx else approx.addLow) ||
712712
base.isInstanceOf[OrType] && fourthTry
@@ -930,8 +930,8 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
930930
val classBounds = tycon2.classSymbols
931931
def liftToBase(bcs: List[ClassSymbol]): Boolean = bcs match {
932932
case bc :: bcs1 =>
933-
classBounds.exists(bc.derivesFrom) && appOK(tp1w.baseType(bc)) ||
934-
liftToBase(bcs1)
933+
classBounds.exists(bc.derivesFrom) && appOK(nonExprBaseType(tp1, bc))
934+
|| liftToBase(bcs1)
935935
case _ =>
936936
false
937937
}
@@ -1107,6 +1107,10 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
11071107
}
11081108
}
11091109

1110+
private def nonExprBaseType(tp: Type, cls: Symbol)(given Context): Type =
1111+
if tp.isInstanceOf[ExprType] then NoType
1112+
else tp.baseType(cls)
1113+
11101114
/** If `tp` is an external reference to an enclosing module M that contains opaque types,
11111115
* convert to M.this.
11121116
* Note: It would be legal to do the lifting also if M does not contain opaque types,
@@ -1283,7 +1287,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
12831287
case bc :: bcs1 =>
12841288
(classBounds.exists(bc.derivesFrom) &&
12851289
variancesConform(bc.typeParams, tparams) &&
1286-
p(tp1.baseType(bc))
1290+
p(nonExprBaseType(tp1, bc))
12871291
||
12881292
recur(bcs1))
12891293
case nil =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2888,7 +2888,7 @@ class Typer extends Namer
28882888
|To turn this error into a warning, pass -Xignore-scala2-macros to the compiler""".stripMargin, tree.sourcePos.startPos)
28892889
tree
28902890
}
2891-
else if (tree.tpe <:< pt) {
2891+
else if (tree.tpe.widenExpr <:< pt) {
28922892
if (pt.hasAnnotation(defn.InlineParamAnnot))
28932893
checkInlineConformant(tree, isFinal = false, "argument to inline parameter")
28942894
if (ctx.typeComparer.GADTused && pt.isValueType)

tests/neg/i7970.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object O{
2+
val a: Int => Int = x => x + 1
3+
val b: (=> Int) => Int = a // error
4+
def m(i: String): String = i
5+
def x(f: String => String): (=>String)=>String = f // error
6+
def main(args: Array[String]): Unit = x(m)("X")
7+
}

0 commit comments

Comments
 (0)