Skip to content

Commit de9c1c0

Browse files
committed
Parser fixes for allowing more newlines in given instances
1 parent 4985e6e commit de9c1c0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,8 +918,14 @@ object Parsers {
918918
val lookahead = in.LookaheadScanner()
919919
if lookahead.isIdent then
920920
lookahead.nextToken()
921-
while lookahead.token == LPAREN || lookahead.token == LBRACKET do
922-
lookahead.skipParens()
921+
def skipParams(): Unit =
922+
if lookahead.token == LPAREN || lookahead.token == LBRACKET then
923+
lookahead.skipParens()
924+
skipParams()
925+
else if lookahead.isNewLine then
926+
lookahead.nextToken()
927+
skipParams()
928+
skipParams()
923929
lookahead.isIdent(nme.as)
924930

925931
def followingIsExtension() =
@@ -3483,14 +3489,21 @@ object Parsers {
34833489

34843490
val gdef = in.endMarkerScope(if name.isEmpty then GIVEN else name) {
34853491
val tparams = typeParamClauseOpt(ParamOwner.Def)
3486-
val vparamss = paramClauses(givenOnly = true)
3492+
newLineOpt()
3493+
val vparamss =
3494+
if in.token == LPAREN && in.lookaheadIn(nme.using)
3495+
then paramClauses(givenOnly = true)
3496+
else Nil
3497+
newLinesOpt()
34873498
if !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
34883499
accept(nme.as)
34893500
def givenAlias(tpt: Tree) =
34903501
accept(EQUALS)
34913502
mods1 |= Final
34923503
DefDef(name, tparams, vparamss, tpt, subExpr())
34933504
if in.token == USCORE then
3505+
if !mods.is(Inline) then
3506+
syntaxError("`_ <:` is only allowed for given with `inline` modifier")
34943507
in.nextToken()
34953508
accept(SUBTYPE)
34963509
givenAlias(TypeBoundsTree(EmptyTree, toplevelTyp()))

tests/pos/i5978.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ package p1 {
1313
(using TokenParser[Char, Position[CharSequence]]) = ???
1414

1515
given FromCharToken(using T: TokenParser[Char, Position[CharSequence]])
16-
: Conversion[Char, Position[CharSequence]] = ???
16+
17+
// skipping newlines is OK here
18+
19+
as Conversion[Char, Position[CharSequence]] = ???
1720
}
1821

1922
object Testcase {

0 commit comments

Comments
 (0)