Skip to content

Parser tweaks #7701

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 2 commits into from
Dec 9, 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
21 changes: 13 additions & 8 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,15 @@ object Parsers {
}
else
val t = reduceStack(base, top, minPrec, leftAssoc = true, in.name, isType)
if !isType && in.token == MATCH then recur(matchClause(t))
if !isType && in.token == MATCH then recurAtMinPrec(matchClause(t))
else t

def recurAtMinPrec(top: Tree): Tree =
if isIdent && isOperator && precedence(in.name) == minInfixPrec
|| in.token == MATCH
then recur(top)
else top

recur(first)
}

Expand Down Expand Up @@ -2758,8 +2764,8 @@ object Parsers {
/** OLD: GivenTypes ::= AnnotType {‘,’ AnnotType}
* NEW: GivenTypes ::= Type {‘,’ Type}
*/
def givenTypes(newStyle: Boolean, nparams: Int, ofClass: Boolean): List[ValDef] =
val tps = commaSeparated(() => if newStyle then typ() else annotType())
def givenTypes(nparams: Int, ofClass: Boolean): List[ValDef] =
val tps = commaSeparated(typ)
var counter = nparams
def nextIdx = { counter += 1; counter }
val paramFlags = if ofClass then Private | Local | ParamAccessor else Param
Expand Down Expand Up @@ -2862,7 +2868,7 @@ object Parsers {
|| startParamTokens.contains(in.token)
|| isIdent && (in.name == nme.inline || in.lookaheadIn(BitSet(COLON)))
if isParams then commaSeparated(() => param())
else givenTypes(true, nparams, ofClass)
else givenTypes(nparams, ofClass)
checkVarArgsRules(clause)
clause
}
Expand Down Expand Up @@ -3477,12 +3483,11 @@ object Parsers {
val t = constrApp()
val ts =
if in.token == WITH then
val lookahead = in.LookaheadScanner(indent = true)
lookahead.nextToken()
if templateCanFollow && (lookahead.token == LBRACE || lookahead.token == INDENT) then
in.nextToken()
newLineOptWhenFollowedBy(LBRACE)
if templateCanFollow && (in.token == LBRACE || in.token == INDENT) then
Nil
else
in.nextToken()
checkNotWithAtEOL()
constrApps(commaOK, templateCanFollow)
else if commaOK && in.token == COMMA then
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/match-infix.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def f = 1 + 1 match {
case 2 => 3
} + 1 // error // error