Skip to content

Commit 024bd25

Browse files
committed
Don't implicit errors if parameters has default value
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
1 parent 4a96ce7 commit 024bd25

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,14 +3539,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
35393539
val namedArgs = wtp.paramNames.lazyZip(args).flatMap { (pname, arg) =>
35403540
if (arg.tpe.isError) Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil
35413541
}
3542-
tryEither {
3543-
val app = cpy.Apply(tree)(untpd.TypedSplice(tree), namedArgs)
3544-
if (wtp.isContextualMethod) app.setApplyKind(ApplyKind.Using)
3545-
typr.println(i"try with default implicit args $app")
3546-
typed(app, pt, locked)
3547-
} { (_, _) =>
3548-
issueErrors()
3549-
}
3542+
val app = cpy.Apply(tree)(untpd.TypedSplice(tree), namedArgs)
3543+
if (wtp.isContextualMethod) app.setApplyKind(ApplyKind.Using)
3544+
typr.println(i"try with default implicit args $app")
3545+
typed(app, pt, locked)
35503546
else issueErrors()
35513547
}
35523548
else tree match {

tests/neg/i14842.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i14842.scala:11:35 ------------------------------------------------------------
2+
11 | val x: Either[Int, Any] = node.as[Any] // error
3+
| ^^^^^^^^^^^^
4+
| Found: Either[String, Any]
5+
| Required: Either[Int, Any]
6+
|
7+
| longer explanation available when compiling with `-explain`

tests/neg/i14842.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Dummy
2+
object Dummy:
3+
val empty = new Dummy
4+
5+
sealed trait Node:
6+
def as[T](using d: Dummy = Dummy.empty): Either[String, T] = ???
7+
8+
object Sample extends App {
9+
val node: Node = ???
10+
11+
val x: Either[Int, Any] = node.as[Any] // error
12+
}

0 commit comments

Comments
 (0)