Skip to content

Fix #2030: Don't chain implicit conversions #2031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
else WildcardType)
val commonFormal = defn.FunctionOf(commonParamTypes, WildcardType)
overload.println(i"pretype arg $arg with expected type $commonFormal")
pt.typedArg(arg, commonFormal)
pt.typedArg(arg, commonFormal)(ctx.addMode(Mode.ImplicitsEnabled))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ trait Implicits { self: Typer =>
|| (to isRef defn.UnitClass)
|| (from.tpe isRef defn.NothingClass)
|| (from.tpe isRef defn.NullClass)
|| !(ctx.mode is Mode.ImplicitsEnabled)
|| (from.tpe eq NoPrefix)) NoImplicitMatches
else
try inferImplicit(to.stripTypeVar.widenExpr, from, from.pos)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
// try an implicit conversion
inferView(tree, pt) match {
case SearchSuccess(inferred, _, _, _) =>
adapt(inferred, pt)
adapt(inferred, pt)(ctx.retractMode(Mode.ImplicitsEnabled))
case failure: SearchFailure =>
if (pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits]) tree
else err.typeMismatch(tree, pt, failure)
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/i2030.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This used to take ~12s, the check should be that
// it runs in reasonable time (i.e. instantaneous).
object a {
val x: String | Int = 'a // error
}
2 changes: 1 addition & 1 deletion tests/run/builder.check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Table(Row(Cell(A1), Cell(B1)), Row(Cell(A2), Cell(B2)))
Table(Row(Cell(top left), Cell(top right)), Row(Cell(botttom left), Cell(bottom right)))
12 changes: 5 additions & 7 deletions tests/run/builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class Row {
override def toString = cells.mkString("Row(", ", ", ")")
}

class Cell(elem: String) {
override def toString = s"Cell($elem)"
}
case class Cell(elem: String)

object Test {

Expand All @@ -36,12 +34,12 @@ object Test {
val data =
table {
row {
cell("A1")
cell("B1")
cell("top left")
cell("top right")
}
row {
cell("A2")
cell("B2")
cell("botttom left")
cell("bottom right")
}
}

Expand Down