Skip to content

Commit b27e044

Browse files
authored
Merge pull request #9963 from dotty-staging/fix-varargs-applicability
2 parents 1306911 + 90d968a commit b27e044

File tree

7 files changed

+33
-2
lines changed

7 files changed

+33
-2
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import util.Stats.record
99
import util.{SrcPos, NoSourcePosition, SourceFile}
1010
import Trees.Untyped
1111
import Contexts._
12+
import Phases._
1213
import Flags._
1314
import Symbols._
1415
import Denotations.Denotation
@@ -539,6 +540,8 @@ trait Applications extends Compatibility {
539540
* in the remaining formal parameters.
540541
*/
541542
def addTyped(arg: Arg, formal: Type): List[Type] =
543+
if !ctx.isAfterTyper && isVarArg(arg) && !formal.isRepeatedParam then
544+
fail(i"Sequence argument type annotation `: _*` cannot be used here: the corresponding parameter has type $formal which is not a repeated parameter type", arg)
542545
addArg(typedArg(arg, formal), formal)
543546
if methodType.isParamDependent && typeOfArg(arg).exists then
544547
// `typeOfArg(arg)` could be missing because the evaluation of `arg` produced type errors

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
407407
wrapArray(arg1, arg0.tpe.elemType)
408408
case _ => arg0
409409
}
410-
val argtpe = arg.tpe.dealiasKeepAnnots
410+
val argtpe = arg.tpe.dealiasKeepAnnots.translateFromRepeated(toArray = false)
411411
val isByName = paramtp.dealias.isInstanceOf[ExprType]
412412
var inlineFlags: FlagSet = InlineProxy
413413
if (paramtp.widenExpr.hasAnnotation(defn.InlineParamAnnot)) inlineFlags |= Inline

tests/neg/i9749.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A {
2+
def f(x: Any) = 1
3+
4+
def foo(x: List[String]): Unit = {
5+
f(x: _*) // error
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class JavaLogger {
2+
public void info(String format, Object arg) {}
3+
4+
public void info(String in, Object... args){}
5+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Test {
2+
val logger = new JavaLogger
3+
def log(): Unit = {
4+
logger.info(
5+
"My {} String {} with multiple args {}",
6+
Array("a", "b", "c"): _*
7+
)
8+
}
9+
}

tests/pos/i9749.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A {
2+
def f(x: Any) = 1
3+
def f(x: String*) = 1
4+
5+
def foo(x: List[String]): Unit = {
6+
f(x: _*)
7+
}
8+
}

tests/pos/test-desugar.scala

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ object desugar {
7676
val pair: Int ~ String = 1 -> "abc"
7777
def foo(xs: Int*) = xs.length
7878
foo(list: _*)
79-
println(list: _*)
8079
(list length)
8180
- desugar.x
8281
def bar(x: => Int) = x

0 commit comments

Comments
 (0)