Skip to content

Commit 7beb507

Browse files
authored
Merge pull request #7568 from dotty-staging/add-end-given
Allow `end given` as an end marker
2 parents 2bf5eb0 + a5dc7ab commit 7beb507

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3412,7 +3412,7 @@ object Parsers {
34123412
else
34133413
(EmptyTermName, isIdent(nme.extension))
34143414

3415-
val gdef = indentRegion(name) {
3415+
val gdef = indentRegion(if name.isEmpty then GIVEN else name) {
34163416
if isExtension then
34173417
if (in.token == COLON) in.nextToken()
34183418
assert(ident() == nme.extension)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ object Scanners {
345345

346346
lookahead.token match {
347347
case IDENTIFIER | BACKQUOTED_IDENT => handle(lookahead.name)
348-
case IF | WHILE | FOR | MATCH | TRY | NEW => handle(lookahead.token)
348+
case IF | WHILE | FOR | MATCH | TRY | NEW | GIVEN => handle(lookahead.token)
349349
case _ =>
350350
}
351351
}

docs/docs/reference/other-new-features/indentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ end largeMethod
109109
```
110110
An `end` marker consists of the identifier `end` which follows an `<outdent>` token, and is in turn followed on the same line by exactly one other token, which is either an identifier or one of the reserved words
111111
```scala
112-
if while for match try new
112+
if while for match try new given
113113
```
114114
If `end` is followed by a reserved word, the compiler checks that the marker closes an indentation region belonging to a construct that starts with the reserved word. If it is followed by an identifier _id_, the compiler checks that the marker closes a definition
115115
that defines _id_ or a package clause that refers to _id_.

tests/pos/end-given.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
given Conversion[Int, String] with
2+
def apply(x: Int) = ""
3+
end given

0 commit comments

Comments
 (0)