Skip to content

Commit 00cc25d

Browse files
committed
Fix syntax error messages for extensions
1 parent a7213cc commit 00cc25d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,8 @@ object desugar {
911911
def extMethods(ext: ExtMethods)(using Context): Tree = flatTree {
912912
for mdef <- ext.methods yield
913913
if mdef.tparams.nonEmpty then
914-
ctx.error("no type parameters allowed here", mdef.tparams.head.sourcePos)
914+
ctx.error("extension method cannot have type parameters here, all type parameters go after `extension`",
915+
mdef.tparams.head.sourcePos)
915916
defDef(
916917
cpy.DefDef(mdef)(
917918
name = mdef.name.toExtensionName,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,6 +3679,7 @@ object Parsers {
36793679
setLastStatOffset()
36803680
meths += extMethod()
36813681
acceptStatSepUnlessAtEnd(meths)
3682+
if meths.isEmpty then syntaxError("`def` expected")
36823683
meths.toList
36833684
}
36843685

0 commit comments

Comments
 (0)