[SI-8971] REPL can't handle (A*) => A Created: 09/Nov/14  Updated: 16/Jan/17

Status: Open
Project: Scala Programming Language
Component/s: Repl / Interpreter
Affects Version/s: Scala 2.11.4
Fix Version/s: Backlog

Type: Bug Priority: Minor
Reporter: Simon Schäfer Assignee: Jason Zaugg
Resolution: Unresolved Votes: 0
Labels: repeated-parameters


There is a compilation error (only in the REPL) in the following example, where none should be:

scala> val f: (Int*) => Int = _.size
<console>:5: error: type mismatch;
 found   : Int* => Int
 required: Seq[Int] => Int
  lazy val $result = f

Comment by Jason Zaugg [ 09/Nov/14 ]

According to the spec,`*` is only allowed on method parameters. The compiler also allows them in function types, but the behaviour is unspecified. Personally, I'd like to disallow this.

Comment by Li Haoyi [ 19/Apr/15 ]

This is fixed in the Ammonite REPL

@ val f: (Int*) => Int = _.size
f: Seq[Int] => Int = <function1>
@ f(1)
res2: Int = 1
@ f(1, 3, 4)
res3: Int = 3

Comment by A. P. Marki [ 16/Jan/17 ]


$ scala
Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.
scala> val f: (Int*) => Int = _.size
f: Int* => Int = $$Lambda$1042/1092382020@1687eb01
scala> f(1,2,3)
res0: Int = 3
// the relevant definitions:
// <stable> <accessor> def f: Int* => Int = $iw.this.f
// <stable> <accessor> lazy val $result: Seq[Int] => Int = $line1.$read.$iw.$iw.f;

Generated at Fri Oct 19 11:09:37 CEST 2018 using JIRA 7.9.1#79001-sha1:60970b42586a2ec2760ed6cfe825b26961e62b9e.