diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index eac39ca72120..5dd3d3d2c257 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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) @@ -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 diff --git a/tests/neg/i12348.check b/tests/neg/i12348.check new file mode 100644 index 000000000000..ccc2b9f7ed00 --- /dev/null +++ b/tests/neg/i12348.check @@ -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 diff --git a/tests/neg/i12348.scala b/tests/neg/i12348.scala new file mode 100644 index 000000000000..69fc77fb532e --- /dev/null +++ b/tests/neg/i12348.scala @@ -0,0 +1,3 @@ +object A { + given inline x: Int = 0 // error +} // error \ No newline at end of file