Skip to content

Commit 27c1290

Browse files
committed
Make parsing given definitions more robust
Fixes #12348
1 parent eff4cb1 commit 27c1290

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -3573,7 +3573,7 @@ object Parsers {
35733573
ValDef(name, parents.head, subExpr())
35743574
else
35753575
DefDef(name, joinParams(tparams, vparamss), parents.head, subExpr())
3576-
else if in.token != WITH && parentsIsType then
3576+
else if (isStatSep || isStatSeqEnd) && parentsIsType then
35773577
if name.isEmpty then
35783578
syntaxError(em"anonymous given cannot be abstract")
35793579
DefDef(name, joinParams(tparams, vparamss), parents.head, EmptyTree)
@@ -3583,8 +3583,8 @@ object Parsers {
35833583
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
35843584
val constr = makeConstructor(tparams1, vparamss1)
35853585
val templ =
3586-
if in.token == WITH then withTemplate(constr, parents)
3587-
else Template(constr, parents, Nil, EmptyValDef, Nil)
3586+
if isStatSep || isStatSeqEnd then Template(constr, parents, Nil, EmptyValDef, Nil)
3587+
else withTemplate(constr, parents)
35883588
if noParams then ModuleDef(name, templ)
35893589
else TypeDef(name.toTypeName, templ)
35903590
end gdef

tests/neg/i12348.check

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- [E040] Syntax Error: tests/neg/i12348.scala:2:15 --------------------------------------------------------------------
2+
2 | given inline x: Int = 0 // error
3+
| ^
4+
| 'with' expected, but identifier found
5+
-- [E040] Syntax Error: tests/neg/i12348.scala:3:10 --------------------------------------------------------------------
6+
3 |} // error
7+
| ^
8+
| '}' expected, but eof found

tests/neg/i12348.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object A {
2+
given inline x: Int = 0 // error
3+
} // error

0 commit comments

Comments
 (0)