Skip to content

Allow normal parameters after given parameters #7317

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

Merged
merged 3 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2849,7 +2849,7 @@ object Parsers {
ofCaseClass: Boolean = false,
ofInstance: Boolean = false): List[List[ValDef]] =

def recur(firstClause: Boolean, nparams: Int, contextualOnly: Boolean): List[List[ValDef]] =
def recur(firstClause: Boolean, nparams: Int): List[List[ValDef]] =
newLineOptWhenFollowedBy(LPAREN)
if in.token == LPAREN then
val paramsStart = in.offset
Expand All @@ -2858,23 +2858,14 @@ object Parsers {
ofClass = ofClass,
ofCaseClass = ofCaseClass,
firstClause = firstClause)
val isGiven = params match
case param :: _ if param.mods.flags.is(Given) => true
case _ =>
if contextualOnly then
syntaxError(
if ofInstance then em"parameters of instance definitions must be `given' clauses"
else em"normal parameters cannot come after `given' clauses",
paramsStart)
false
val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit)
params :: (
if lastClause then Nil
else recur(firstClause = false, nparams + params.length, isGiven))
else recur(firstClause = false, nparams + params.length))
else Nil
end recur

recur(firstClause = true, 0, ofInstance)
recur(firstClause = true, 0)
end paramClauses

/* -------- DEFS ------------------------------------------- */
Expand Down
116 changes: 0 additions & 116 deletions docs/docs/reference/contextual-new/given-clauses.md

This file was deleted.

176 changes: 0 additions & 176 deletions docs/docs/reference/contextual-new/relationship-implicits.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/docs/reference/contextual/given-clauses.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ maximum(xs)(given descending(given ListOrd(given IntOrd)))
There can be several `given` parameter clauses in a definition and `given` parameter clauses can be freely
mixed with normal ones. Example:
```scala
def f(u: Universe)(given c: u.Context)(given s: ctx.Symbol, k: ctx.Kind) = ...
def f(u: Universe)(given ctx: u.Context)(given s: ctx.Symbol, k: ctx.Kind) = ...
```
Multiple given clauses are matched left-to-right in applications. Example:
```scala
Expand Down
Loading