Skip to content

Commit bada0dd

Browse files
committed
Handle implicits with default parameters.
Fixes #576. run/pending/Meter now compiles; crashes at runtime. Review by @smarter.
1 parent 13b6165 commit bada0dd

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
14471447
case ambi: AmbiguousImplicits =>
14481448
implicitArgError(s"ambiguous implicits: ${ambi.explanation} of $where")
14491449
case failure: SearchFailure =>
1450-
implicitArgError(d"no implicit argument of type $formal found for $where" + failure.postscript)
1450+
def noImplicitFound =
1451+
implicitArgError(d"no implicit argument of type $formal found for $where" + failure.postscript)
1452+
if (tree.symbol.hasDefaultParams) // try to append () to application
1453+
tryEither
1454+
{ implicit ctx => typed(untpd.Apply(untpd.TypedSplice(tree), Nil), pt) }
1455+
{ (_, _) => noImplicitFound }
1456+
else noImplicitFound
14511457
}
14521458
}
14531459
if (args.exists(_.isEmpty)) {

tests/pending/pos/i618.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class C(val f: Any*)
2+
3+
class D(override val f: Nothing) extends C(f)

tests/pos/i576.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class A
2+
3+
object Impl {
4+
def foo()(implicit x: A = null): Int = 2
5+
def test: Int = {
6+
foo()() // ok
7+
foo() // did not work before, does now
8+
}
9+
}

0 commit comments

Comments
 (0)