File tree 5 files changed +26
-14
lines changed
src/dotty/tools/dotc/typer 5 files changed +26
-14
lines changed Original file line number Diff line number Diff line change @@ -1227,8 +1227,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1227
1227
case mtpe : MethodType =>
1228
1228
val pos = paramIndex(param.name)
1229
1229
if pos < mtpe.paramInfos.length then
1230
- val ptype = mtpe.paramInfos(pos)
1231
- if ptype.isRepeatedParam then NoType else ptype
1230
+ mtpe.paramInfos(pos)
1231
+ // This works only if vararg annotations match up.
1232
+ // See neg/i14367.scala for an example where the inferred type is mispredicted.
1233
+ // Nevertheless, the alternative would be to give up completely, so this is
1234
+ // defensible.
1232
1235
else NoType
1233
1236
case _ => NoType
1234
1237
if target.exists then formal <:< target
@@ -1317,10 +1320,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1317
1320
*/
1318
1321
var fnBody = tree.body
1319
1322
1320
- def refersTo (arg : untpd.Tree , param : untpd.ValDef ): Boolean = arg match {
1323
+ def refersTo (arg : untpd.Tree , param : untpd.ValDef ): Boolean = arg match
1321
1324
case Ident (name) => name == param.name
1325
+ case Typed (arg1, _) if untpd.isWildcardStarArg(arg) => refersTo(arg1, param)
1322
1326
case _ => false
1323
- }
1324
1327
1325
1328
/** If parameter `param` appears exactly once as an argument in `args`,
1326
1329
* the singleton list consisting of its position in `args`, otherwise `Nil`.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ -- [E007] Type Mismatch Error: tests/neg/i14367.scala:2:16 -------------------------------------------------------------
2
+ 2 |val h2 = i => p(i) // error: Found (i : Seq[Int]), Required: Int
3
+ | ^
4
+ | Found: (i : Seq[Int])
5
+ | Required: Int
6
+
7
+ longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change
1
+ def p (i : Int * ) = i.sum
2
+ val h2 = i => p(i) // error: Found (i : Seq[Int]), Required: Int
3
+ // It would be more logical to fail with a "missing parameter type", however.
4
+
5
+
Original file line number Diff line number Diff line change
1
+ def m (i : Int * ) = i.sum
2
+ val f1 = m
3
+ val f2 = i => m(i* )
4
+
5
+ def n (i : Seq [Int ]) = i.sum
6
+ val g1 = n
7
+ val g2 = i => n(i)
You can’t perform that action at this time.
0 commit comments