Skip to content

Commit 8aeee17

Browse files
committed
Merge pull request #1063 from dotty-staging/fix-#803
Handle "missing args" case when expected type is a singleton type.
2 parents d005613 + 37c877d commit 8aeee17

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
13431343

13441344
def methodStr = err.refStr(methPart(tree).tpe)
13451345

1346+
def missingArgs = errorTree(tree,
1347+
d"""missing arguments for $methodStr
1348+
|follow this method with `_' if you want to treat it as a partially applied function""".stripMargin)
1349+
13461350
def adaptOverloaded(ref: TermRef) = {
13471351
val altDenots = ref.denot.alternatives
13481352
typr.println(i"adapt overloaded $ref with alternatives ${altDenots map (_.info)}%, %")
@@ -1475,12 +1479,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
14751479
else if (wtp.isImplicit)
14761480
err.typeMismatch(tree, pt)
14771481
else
1478-
errorTree(tree,
1479-
d"""missing arguments for $methodStr
1480-
|follow this method with `_' if you want to treat it as a partially applied function""".stripMargin)
1482+
missingArgs
14811483
case _ =>
14821484
if (tree.tpe <:< pt) tree
14831485
else if (ctx.mode is Mode.Pattern) tree // no subtype check for pattern
1486+
else if (wtp.isInstanceOf[MethodType]) missingArgs
14841487
else {
14851488
typr.println(i"adapt to subtype ${tree.tpe} !<:< $pt")
14861489
//typr.println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt))

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class tests extends CompilerTest {
158158
@Test def neg_i941 = compileFile(negDir, "i941", xerrors = 3)
159159
@Test def neg_finalSealed = compileFile(negDir, "final-sealed", xerrors = 2)
160160
@Test def neg_i705 = compileFile(negDir, "i705-inner-value-class", xerrors = 7)
161+
@Test def neg_i803 = compileFile(negDir, "i803", xerrors = 2)
161162
@Test def neg_i866 = compileFile(negDir, "i866", xerrors = 2)
162163
@Test def neg_i974 = compileFile(negDir, "i974", xerrors = 2)
163164
@Test def neg_moduleSubtyping = compileFile(negDir, "moduleSubtyping", xerrors = 4)

tests/neg/i803.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Foo{
2+
val default = this
3+
def foo(a: Int)(b: Foo = default): b.type = b
4+
5+
def bar(b: Foo = default): b.type = b
6+
val x: Foo = bar() // ok
7+
val x2: Foo = foo(1)() // ok
8+
9+
val s: Foo = foo(1) // error
10+
val s2: default.type = foo(1) // error
11+
}

0 commit comments

Comments
 (0)