Skip to content

Commit fe2a943

Browse files
committed
type fully defined then typevar instantiated to other typevar
1 parent 3a4aabd commit fe2a943

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ object Inferencing {
231231
def apply(x: Boolean, tp: Type): Boolean = trace(i"isFullyDefined($tp, $force)", typr) {
232232
try {
233233
val tpd = tp.dealias
234-
if tpd ne tp then apply(x, tpd)
235-
else tp match
234+
if tpd ne tp then {
235+
(tpd.isInstanceOf[TypeVar] && tp.isInstanceOf[TypeVar])
236+
|| apply(x, tpd)
237+
} else tp match
236238
case _: WildcardType | _: ProtoType =>
237239
false
238240
case tvar: TypeVar if !tvar.isInstantiated =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ object ProtoTypes {
396396
args: List[untpd.Tree] = this.args,
397397
resultType: Type = this.resultType,
398398
typer: Typer = this.typer,
399-
constrainResultDeep: Boolean = this.constrainResultDeep): FunProto =
399+
constrainResultDeep: Boolean = this.constrainResultDeep)(using Context): FunProto =
400400
if (args eq this.args)
401401
&& (resultType eq this.resultType)
402402
&& (typer eq this.typer)

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import transform.CheckUnused.OriginalName
5454
import scala.annotation.{unchecked as _, *}
5555
import dotty.tools.dotc.util.chaining.*
5656
import dotty.tools.dotc.ast.untpd.Mod
57+
import dotty.tools.dotc.reporting.Reporter.NoReporter
5758

5859
object Typer {
5960

@@ -4357,24 +4358,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43574358
else formals1
43584359
implicitArgs(formals2, argIndex + 1, pt)
43594360

4361+
4362+
def doesntContainsWildcards = {
4363+
val newCtx = ctx.fresh.setNewScope.setReporter(new reporting.ThrowingReporter(NoReporter))
4364+
val pt1 = pt.deepenProtoTrans(using newCtx)
4365+
try {
4366+
!pt1.containsWildcardTypes(using newCtx)
4367+
} catch {
4368+
case _: UnhandledError => false
4369+
}
4370+
}
43604371
val pt1 = pt.deepenProtoTrans
4361-
val approxPt = withMode(Mode.TypevarsMissContext):
4362-
wildApprox(pt1)
4363-
var formalConstrained = false
4364-
val tm = new TypeMap:
4365-
def apply(t: Type): Type = t match
4366-
case tvar: TypeVar =>
4367-
formalConstrained |= ctx.typerState.constraint.contains(tvar) || tvar.instanceOpt.isInstanceOf[TypeVar]
4368-
tvar
4369-
case _ =>
4370-
if formalConstrained then t
4371-
else mapOver(t)
4372-
tm(formal)
43734372
if (pt1 `ne` pt)
43744373
&& (pt1 ne sharpenedPt)
4375-
&& (AvoidWildcardsMap()(approxPt) `eq` approxPt)
4374+
&& formal.typeSymbol != defn.ClassTagClass
43764375
&& !isFullyDefined(formal, ForceDegree.none)
4377-
&& !formalConstrained then
4376+
&& doesntContainsWildcards then
43784377
constrainResult(tree.symbol, wtp, pt1)
43794378
val arg = inferImplicitArg(formal, tree.span.endPos)
43804379

0 commit comments

Comments
 (0)