Skip to content

Commit 1aa4b56

Browse files
committed
Don't chain implicit conversions
When inferring a view, we are not allowed to use another implicit conversion to adapt its result. Fixing this revealed another problem where we have to re-enable implicit conversions when pre-typing arguments in overloading resolution.
1 parent d0162ae commit 1aa4b56

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
13751375
else WildcardType)
13761376
val commonFormal = defn.FunctionOf(commonParamTypes, WildcardType)
13771377
overload.println(i"pretype arg $arg with expected type $commonFormal")
1378-
pt.typedArg(arg, commonFormal)
1378+
pt.typedArg(arg, commonFormal)(ctx.addMode(Mode.ImplicitsEnabled))
13791379
}
13801380
}
13811381
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ trait Implicits { self: Typer =>
496496
|| (to isRef defn.UnitClass)
497497
|| (from.tpe isRef defn.NothingClass)
498498
|| (from.tpe isRef defn.NullClass)
499+
|| !(ctx.mode is Mode.ImplicitsEnabled)
499500
|| (from.tpe eq NoPrefix)) NoImplicitMatches
500501
else
501502
try inferImplicit(to.stripTypeVar.widenExpr, from, from.pos)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
20232023
// try an implicit conversion
20242024
inferView(tree, pt) match {
20252025
case SearchSuccess(inferred, _, _, _) =>
2026-
adapt(inferred, pt)
2026+
adapt(inferred, pt)(ctx.retractMode(Mode.ImplicitsEnabled))
20272027
case failure: SearchFailure =>
20282028
if (pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits]) tree
20292029
else err.typeMismatch(tree, pt, failure)

tests/neg/i2030.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This used to take ~12s, the check should be that
2+
// it runs in reasonable time (i.e. instantaneous).
3+
object a {
4+
val x: String | Int = 'a // error
5+
}

0 commit comments

Comments
 (0)