Skip to content
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
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case mtpe: MethodType =>
val pos = paramIndex(param.name)
if pos < mtpe.paramInfos.length then
val ptype = mtpe.paramInfos(pos)
if ptype.isRepeatedParam then NoType else ptype
mtpe.paramInfos(pos)
// This works only if vararg annotations match up.
// See neg/i14367.scala for an example where the inferred type is mispredicted.
// Nevertheless, the alternative would be to give up completely, so this is
// defensible.
else NoType
case _ => NoType
if target.exists then formal <:< target
Expand Down Expand Up @@ -1317,10 +1320,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
*/
var fnBody = tree.body

def refersTo(arg: untpd.Tree, param: untpd.ValDef): Boolean = arg match {
def refersTo(arg: untpd.Tree, param: untpd.ValDef): Boolean = arg match
case Ident(name) => name == param.name
case Typed(arg1, _) if untpd.isWildcardStarArg(arg) => refersTo(arg1, param)
case _ => false
}

/** If parameter `param` appears exactly once as an argument in `args`,
* the singleton list consisting of its position in `args`, otherwise `Nil`.
Expand Down
10 changes: 0 additions & 10 deletions compiler/test-resources/repl/errorThenValid

This file was deleted.

7 changes: 7 additions & 0 deletions tests/neg/i14367.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E007] Type Mismatch Error: tests/neg/i14367.scala:2:16 -------------------------------------------------------------
2 |val h2 = i => p(i) // error: Found (i : Seq[Int]), Required: Int
| ^
| Found: (i : Seq[Int])
| Required: Int

longer explanation available when compiling with `-explain`
5 changes: 5 additions & 0 deletions tests/neg/i14367.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def p(i: Int*) = i.sum
val h2 = i => p(i) // error: Found (i : Seq[Int]), Required: Int
// It would be more logical to fail with a "missing parameter type", however.


7 changes: 7 additions & 0 deletions tests/pos/i14367.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def m(i: Int*) = i.sum
val f1 = m
val f2 = i => m(i*)

def n(i: Seq[Int]) = i.sum
val g1 = n
val g2 = i => n(i)