Skip to content

Commit 38e1086

Browse files
committed
Allow normal parameters after given parameters
With the new given syntax, we can lift the restriction that normal parameters cannot follow given parameters. This restriction was introduced because with the previous syntax this looked too awkward. The added test `given-eta` shows that eta expansion works as expected for these cases.
1 parent 19b4216 commit 38e1086

File tree

6 files changed

+53
-335
lines changed

6 files changed

+53
-335
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,7 @@ object Parsers {
28492849
ofCaseClass: Boolean = false,
28502850
ofInstance: Boolean = false): List[List[ValDef]] =
28512851

2852-
def recur(firstClause: Boolean, nparams: Int, contextualOnly: Boolean): List[List[ValDef]] =
2852+
def recur(firstClause: Boolean, nparams: Int): List[List[ValDef]] =
28532853
newLineOptWhenFollowedBy(LPAREN)
28542854
if in.token == LPAREN then
28552855
val paramsStart = in.offset
@@ -2858,23 +2858,14 @@ object Parsers {
28582858
ofClass = ofClass,
28592859
ofCaseClass = ofCaseClass,
28602860
firstClause = firstClause)
2861-
val isGiven = params match
2862-
case param :: _ if param.mods.flags.is(Given) => true
2863-
case _ =>
2864-
if contextualOnly then
2865-
syntaxError(
2866-
if ofInstance then em"parameters of instance definitions must be `given' clauses"
2867-
else em"normal parameters cannot come after `given' clauses",
2868-
paramsStart)
2869-
false
28702861
val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit)
28712862
params :: (
28722863
if lastClause then Nil
2873-
else recur(firstClause = false, nparams + params.length, isGiven))
2864+
else recur(firstClause = false, nparams + params.length))
28742865
else Nil
28752866
end recur
28762867

2877-
recur(firstClause = true, 0, ofInstance)
2868+
recur(firstClause = true, 0)
28782869
end paramClauses
28792870

28802871
/* -------- DEFS ------------------------------------------- */

docs/docs/reference/contextual-new/given-clauses.md

Lines changed: 0 additions & 116 deletions
This file was deleted.

docs/docs/reference/contextual-new/relationship-implicits.md

Lines changed: 0 additions & 176 deletions
This file was deleted.

docs/docs/reference/contextual/given-clauses.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ maximum(xs)(given descending(given ListOrd(given IntOrd)))
6969
There can be several `given` parameter clauses in a definition and `given` parameter clauses can be freely
7070
mixed with normal ones. Example:
7171
```scala
72-
def f(u: Universe)(given c: u.Context)(given s: ctx.Symbol, k: ctx.Kind) = ...
72+
def f(u: Universe)(given ctx: u.Context)(given s: ctx.Symbol, k: ctx.Kind) = ...
7373
```
7474
Multiple given clauses are matched left-to-right in applications. Example:
7575
```scala

0 commit comments

Comments
 (0)