Skip to content

Commit

Permalink
Don't implicit errors if parameters has default value
Browse files Browse the repository at this point in the history
If implicit parameters have default values then we try to re-type the
application with default values supplied as arguments. So far we
fell back to the original errors if retyping failed, which can lead
to confusing error messages. We now stick with the retyping in all cases.

Fixes #14842
  • Loading branch information
odersky committed Apr 5, 2022
1 parent 4a96ce7 commit 024bd25
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
12 changes: 4 additions & 8 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3539,14 +3539,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
val namedArgs = wtp.paramNames.lazyZip(args).flatMap { (pname, arg) =>
if (arg.tpe.isError) Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil
}
tryEither {
val app = cpy.Apply(tree)(untpd.TypedSplice(tree), namedArgs)
if (wtp.isContextualMethod) app.setApplyKind(ApplyKind.Using)
typr.println(i"try with default implicit args $app")
typed(app, pt, locked)
} { (_, _) =>
issueErrors()
}
val app = cpy.Apply(tree)(untpd.TypedSplice(tree), namedArgs)
if (wtp.isContextualMethod) app.setApplyKind(ApplyKind.Using)
typr.println(i"try with default implicit args $app")
typed(app, pt, locked)
else issueErrors()
}
else tree match {
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i14842.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E007] Type Mismatch Error: tests/neg/i14842.scala:11:35 ------------------------------------------------------------
11 | val x: Either[Int, Any] = node.as[Any] // error
| ^^^^^^^^^^^^
| Found: Either[String, Any]
| Required: Either[Int, Any]
|
| longer explanation available when compiling with `-explain`
12 changes: 12 additions & 0 deletions tests/neg/i14842.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Dummy
object Dummy:
val empty = new Dummy

sealed trait Node:
def as[T](using d: Dummy = Dummy.empty): Either[String, T] = ???

object Sample extends App {
val node: Node = ???

val x: Either[Int, Any] = node.as[Any] // error
}

0 comments on commit 024bd25

Please sign in to comment.