Skip to content

Commit 782f57e

Browse files
authored
Merge pull request #12354 from dotty-staging/fix-12348
Make parsing given definitions more robust
2 parents f84322e + 27c1290 commit 782f57e

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
@@ -3581,7 +3581,7 @@ object Parsers {
35813581
ValDef(name, parents.head, subExpr())
35823582
else
35833583
DefDef(name, joinParams(tparams, vparamss), parents.head, subExpr())
3584-
else if in.token != WITH && parentsIsType then
3584+
else if (isStatSep || isStatSeqEnd) && parentsIsType then
35853585
if name.isEmpty then
35863586
syntaxError(em"anonymous given cannot be abstract")
35873587
DefDef(name, joinParams(tparams, vparamss), parents.head, EmptyTree)
@@ -3591,8 +3591,8 @@ object Parsers {
35913591
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
35923592
val constr = makeConstructor(tparams1, vparamss1)
35933593
val templ =
3594-
if in.token == WITH then withTemplate(constr, parents)
3595-
else Template(constr, parents, Nil, EmptyValDef, Nil)
3594+
if isStatSep || isStatSeqEnd then Template(constr, parents, Nil, EmptyValDef, Nil)
3595+
else withTemplate(constr, parents)
35963596
if noParams then ModuleDef(name, templ)
35973597
else TypeDef(name.toTypeName, templ)
35983598
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)