-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow single-line lambdas after :
#23821
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
Draft
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
29b3909
Allow single-line lambdas after `:`
odersky 97208f8
Small tweaks
odersky d94c344
Allow single case clauses as expressions
odersky 8665a3c
Allow single-case lambda after colon
odersky 07611bf
Put extensions under language.experimental.relaxedLambdaSyntax
odersky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
tests/neg/closure-args.check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
-- [E040] Syntax Error: tests/neg/closure-args.scala:2:25 -------------------------------------------------------------- | ||
2 |val x = List(1).map: (x: => Int) => // error | ||
| ^^ | ||
| an identifier expected, but '=>' found | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- Error: tests/neg/closure-args.scala:14:0 ---------------------------------------------------------------------------- | ||
14 | y => y > 0 // error // error | ||
|^ | ||
|indented definitions expected, end of single-line lambda found | ||
-- [E103] Syntax Error: tests/neg/closure-args.scala:14:4 -------------------------------------------------------------- | ||
14 | y => y > 0 // error // error | ||
| ^ | ||
| Illegal start of toplevel definition | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E018] Syntax Error: tests/neg/closure-args.scala:18:20 ------------------------------------------------------------- | ||
18 |val e = xs.map: y => // error | ||
| ^ | ||
| expression expected but [31mend of single-line lambda[0m found | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E040] Syntax Error: tests/neg/closure-args.scala:21:64 ------------------------------------------------------------- | ||
21 |val fs: List[List[Int] => Int] = xs.map: x => case y :: ys => y case Nil => -1 // error | ||
| ^^^^ | ||
| end of single-line lambda expected, but 'case' found | ||
-- [E008] Not Found Error: tests/neg/closure-args.scala:10:4 ----------------------------------------------------------- | ||
8 |val b: Int = xs | ||
9 | .map: x => x | ||
10 | * x // error | ||
| ^ | ||
| value * is not a member of List[Int]. | ||
| Note that `*` is treated as an infix operator in Scala 3. | ||
| If you do not want that, insert a `;` or empty line in front | ||
| or drop any spaces behind the operator. | ||
-- [E006] Not Found Error: tests/neg/closure-args.scala:16:21 ---------------------------------------------------------- | ||
16 |val c = List(xs.map: y => y + y) // error // error // error // error | ||
| ^ | ||
| Not found: type y | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E006] Not Found Error: tests/neg/closure-args.scala:16:28 ---------------------------------------------------------- | ||
16 |val c = List(xs.map: y => y + y) // error // error // error // error | ||
| ^ | ||
| Not found: type + | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E006] Not Found Error: tests/neg/closure-args.scala:16:26 ---------------------------------------------------------- | ||
16 |val c = List(xs.map: y => y + y) // error // error // error // error | ||
| ^ | ||
| Not found: type y | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E006] Not Found Error: tests/neg/closure-args.scala:16:30 ---------------------------------------------------------- | ||
16 |val c = List(xs.map: y => y + y) // error // error // error // error | ||
| ^ | ||
| Not found: type y | ||
| | ||
| longer explanation available when compiling with `-explain` |
24 changes: 11 additions & 13 deletions
tests/neg/closure-args.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
import language.`3.3` | ||
|
||
import language.experimental.relaxedLambdaSyntax | ||
val x = List(1).map: (x: => Int) => // error | ||
??? | ||
val z = List(1).map: + => // ok | ||
??? | ||
|
||
val xs = List(1) | ||
val b: Int = xs // error | ||
.map: x => x * x // error | ||
.filter: y => y > 0 // error | ||
(0) | ||
val d = xs // error | ||
val b: Int = xs | ||
.map: x => x | ||
* x // error | ||
|
||
val d = xs | ||
.map: x => x.toString + xs.dropWhile: | ||
y => y > 0 | ||
y => y > 0 // error // error | ||
|
||
val c = List(xs.map: y => y + y) // error // error // error // error | ||
val d2: String = xs // error | ||
.map: x => x.toString + xs.dropWhile: y => y > 0 // error // error | ||
.filter: z => !z.isEmpty // error | ||
(0) | ||
|
||
val fs: List[List[Int] => Int] = xs.map: x => case y :: ys => y case Nil => -1 // error // error | ||
val e = xs.map: y => // error | ||
y + 1 | ||
|
||
val fs: List[List[Int] => Int] = xs.map: x => case y :: ys => y case Nil => -1 // error |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.