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
Problem parsing anonymous functions with 2+ params #1564
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1564?orig=1
|
Geoffrey Alan Washburn (washburn) said: class Foo {
(a : Int, b : Int) => println(List(a, b))
} which fails in the compiler. The problem is how template statements are parsed. |
@lexspoon said: A partial fix is in the attachment interpAddsSemi-r16705.patch. All it does is insert a semicolon before the user code, thus avoiding any attempt by the parser to treat the user code as a this alias. This patch does not work due to issue #1565, but if #1565 can be fixed it should work. If #1565 needs to stay the way it is for some reason, then there are alternate strategies available for 1564. |
Geoffrey Alan Washburn (washburn) said: |
@lexspoon said: Here's a problem related to the initial one given above: scala> a : Int => println("hello") Without a patch, the interpreter will attempt to parse something analogous to this: object wrapper { a : Int => println("hello") } This will parse in a different way than intended. At the least that looks fragile. It should make the interpreter more robust if it didn't even try to parse such a construction, which is why I suggested putting in a semicolon. If there is a better way to eliminate the possibility of a this alias than a semicolon, that would also be great. |
Geoffrey Alan Washburn (washburn) said: |
@paulp said: scala> (a : Int, b : Int) => println(List(a, b))
res0: (Int, Int) => Unit = <function>
scala> res0(5, 10)
List(5, 10) However lex's specific example is thorny: a : Int => println("hello") That is, I think the specific case of an unparenthesized one-argument function may be best dealt with by special casing the interpreter, because I'm pretty sure disambiguating it in the parser is impossible. // is that a function or a self-type?
scala> class Foo
scala> class Bar extends Foo { self: Bar => println("hi") } I'll look at this some more but I think the lion's share of the available improvement is in the patch for 1565. |
@paulp said: |
This works fine with zero or single parameters
But when trying with 2+ parameters it failed:
The text was updated successfully, but these errors were encountered: