Skip to content

Commit 04d309a

Browse files
committed
Allow to use (...) around GivenTypes
1 parent 62afff8 commit 04d309a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,19 @@ object Parsers {
21902190
}
21912191
val isContextual = initialMods.is(Given)
21922192
newLineOptWhenFollowedBy(LPAREN)
2193-
if (in.token == LPAREN) {
2193+
def isParamClause: Boolean =
2194+
!isContextual || {
2195+
val lookahead = in.lookaheadScanner
2196+
lookahead.nextToken()
2197+
paramIntroTokens.contains(lookahead.token) && {
2198+
lookahead.token != IDENTIFIER ||
2199+
lookahead.name == nme.inline || {
2200+
lookahead.nextToken()
2201+
lookahead.token == COLON
2202+
}
2203+
}
2204+
}
2205+
if (in.token == LPAREN && isParamClause) {
21942206
if (ofInstance && !isContextual)
21952207
syntaxError(em"parameters of instance definitions must come after `given'")
21962208
val params = paramClause(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ object Tokens extends TokensCommon {
240240

241241
final val modifierFollowers = modifierTokens | defIntroTokens
242242

243+
final val paramIntroTokens: TokenSet = modifierTokens | identifierTokens | BitSet(AT, VAL, VAR, IMPLICIT)
244+
243245
/** Is token only legal as start of statement (eof also included)? */
244246
final val mustStartStatTokens: TokenSet = defIntroTokens | modifierTokens | BitSet(IMPORT, EXPORT, PACKAGE)
245247

0 commit comments

Comments
 (0)