Skip to content

Commit 761b1fd

Browse files
authored
Merge pull request #2031 from dotty-staging/fix-#2030
Fix #2030: Don't chain implicit conversions
2 parents 917a7ed + 2e33a88 commit 761b1fd

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
13841384
else WildcardType)
13851385
val commonFormal = defn.FunctionOf(commonParamTypes, WildcardType)
13861386
overload.println(i"pretype arg $arg with expected type $commonFormal")
1387-
pt.typedArg(arg, commonFormal)
1387+
pt.typedArg(arg, commonFormal)(ctx.addMode(Mode.ImplicitsEnabled))
13881388
}
13891389
}
13901390
}

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+
}

tests/run/builder.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Table(Row(Cell(A1), Cell(B1)), Row(Cell(A2), Cell(B2)))
1+
Table(Row(Cell(top left), Cell(top right)), Row(Cell(botttom left), Cell(bottom right)))

tests/run/builder.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class Row {
1212
override def toString = cells.mkString("Row(", ", ", ")")
1313
}
1414

15-
class Cell(elem: String) {
16-
override def toString = s"Cell($elem)"
17-
}
15+
case class Cell(elem: String)
1816

1917
object Test {
2018

@@ -36,12 +34,12 @@ object Test {
3634
val data =
3735
table {
3836
row {
39-
cell("A1")
40-
cell("B1")
37+
cell("top left")
38+
cell("top right")
4139
}
4240
row {
43-
cell("A2")
44-
cell("B2")
41+
cell("botttom left")
42+
cell("bottom right")
4543
}
4644
}
4745

0 commit comments

Comments
 (0)