Skip to content

Make parsing given definitions more robust #12354

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 1 commit into from
May 7, 2021
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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3573,7 +3573,7 @@ object Parsers {
ValDef(name, parents.head, subExpr())
else
DefDef(name, joinParams(tparams, vparamss), parents.head, subExpr())
else if in.token != WITH && parentsIsType then
else if (isStatSep || isStatSeqEnd) && parentsIsType then
if name.isEmpty then
syntaxError(em"anonymous given cannot be abstract")
DefDef(name, joinParams(tparams, vparamss), parents.head, EmptyTree)
Expand All @@ -3583,8 +3583,8 @@ object Parsers {
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
val constr = makeConstructor(tparams1, vparamss1)
val templ =
if in.token == WITH then withTemplate(constr, parents)
else Template(constr, parents, Nil, EmptyValDef, Nil)
if isStatSep || isStatSeqEnd then Template(constr, parents, Nil, EmptyValDef, Nil)
else withTemplate(constr, parents)
if noParams then ModuleDef(name, templ)
else TypeDef(name.toTypeName, templ)
end gdef
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i12348.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- [E040] Syntax Error: tests/neg/i12348.scala:2:15 --------------------------------------------------------------------
2 | given inline x: Int = 0 // error
| ^
| 'with' expected, but identifier found
-- [E040] Syntax Error: tests/neg/i12348.scala:3:10 --------------------------------------------------------------------
3 |} // error
| ^
| '}' expected, but eof found
3 changes: 3 additions & 0 deletions tests/neg/i12348.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object A {
given inline x: Int = 0 // error
} // error