Skip to content

: _* is only valid when the parameter is repeated #9963

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

Merged
merged 1 commit into from
Oct 8, 2020
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
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import util.Stats.record
import util.{SrcPos, NoSourcePosition, SourceFile}
import Trees.Untyped
import Contexts._
import Phases._
import Flags._
import Symbols._
import Denotations.Denotation
Expand Down Expand Up @@ -539,6 +540,8 @@ trait Applications extends Compatibility {
* in the remaining formal parameters.
*/
def addTyped(arg: Arg, formal: Type): List[Type] =
if !ctx.isAfterTyper && isVarArg(arg) && !formal.isRepeatedParam then
fail(i"Sequence argument type annotation `: _*` cannot be used here: the corresponding parameter has type $formal which is not a repeated parameter type", arg)
addArg(typedArg(arg, formal), formal)
if methodType.isParamDependent && typeOfArg(arg).exists then
// `typeOfArg(arg)` could be missing because the evaluation of `arg` produced type errors
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
wrapArray(arg1, arg0.tpe.elemType)
case _ => arg0
}
val argtpe = arg.tpe.dealiasKeepAnnots
val argtpe = arg.tpe.dealiasKeepAnnots.translateFromRepeated(toArray = false)
val isByName = paramtp.dealias.isInstanceOf[ExprType]
var inlineFlags: FlagSet = InlineProxy
if (paramtp.widenExpr.hasAnnotation(defn.InlineParamAnnot)) inlineFlags |= Inline
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i9749.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class A {
def f(x: Any) = 1

def foo(x: List[String]): Unit = {
f(x: _*) // error
}
}
5 changes: 5 additions & 0 deletions tests/pos-java-interop/i9912/JavaLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class JavaLogger {
public void info(String format, Object arg) {}

public void info(String in, Object... args){}
}
9 changes: 9 additions & 0 deletions tests/pos-java-interop/i9912/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Test {
val logger = new JavaLogger
def log(): Unit = {
logger.info(
"My {} String {} with multiple args {}",
Array("a", "b", "c"): _*
)
}
}
8 changes: 8 additions & 0 deletions tests/pos/i9749.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class A {
def f(x: Any) = 1
def f(x: String*) = 1

def foo(x: List[String]): Unit = {
f(x: _*)
}
}
1 change: 0 additions & 1 deletion tests/pos/test-desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ object desugar {
val pair: Int ~ String = 1 -> "abc"
def foo(xs: Int*) = xs.length
foo(list: _*)
println(list: _*)
(list length)
- desugar.x
def bar(x: => Int) = x
Expand Down