Skip to content
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

Don't eta expand unary varargs methods #16892

Merged
merged 1 commit into from
Feb 19, 2023
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
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3922,7 +3922,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
else defn.functionArity(ptNorm)
else
val nparams = wtp.paramInfos.length
if nparams > 0 || pt.eq(AnyFunctionProto) then nparams
if nparams > 1
|| nparams == 1 && !wtp.isVarArgsMethod
|| pt.eq(AnyFunctionProto)
then nparams
else -1 // no eta expansion in this case
adaptNoArgsUnappliedMethod(wtp, funExpected, arity)
case _ =>
Expand Down
22 changes: 22 additions & 0 deletions tests/neg/i16820.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Error: tests/neg/i16820.scala:5:11 ----------------------------------------------------------------------------------
5 | val x1 = f // error
| ^
| missing arguments for method f in object Test
-- [E100] Syntax Error: tests/neg/i16820.scala:6:11 --------------------------------------------------------------------
6 | val x2 = g // error
| ^
| method g in object Test must be called with () argument
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg/i16820.scala:8:14 ----------------------------------------------------------------------------------
8 | val x3 = "".formatted // error
| ^^^^^^^^^^^^
| missing arguments for method formatted in class String
-- Error: tests/neg/i16820.scala:9:40 ----------------------------------------------------------------------------------
9 | val x4 = java.nio.file.Paths.get(".").toRealPath // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| missing arguments for method toRealPath in trait Path
-- Error: tests/neg/i16820.scala:13:14 ---------------------------------------------------------------------------------
13 |def test = Foo(3) // error
| ^^^^^^
| missing arguments for method apply in object Foo
13 changes: 13 additions & 0 deletions tests/neg/i16820.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
object Test:
def f(xs: Int*) = xs.sum
def g() = 1

val x1 = f // error
val x2 = g // error

val x3 = "".formatted // error
val x4 = java.nio.file.Paths.get(".").toRealPath // error

// #14567
case class Foo(x: Int)(xs: String*)
def test = Foo(3) // error
2 changes: 1 addition & 1 deletion tests/pos/i14367.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def m(i: Int*) = i.sum
val f1 = m
val f1: Seq[Int] => Int = m
val f2 = i => m(i*)

def n(i: Seq[Int]) = i.sum
Expand Down
2 changes: 0 additions & 2 deletions tests/pos/i14567.scala

This file was deleted.