diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 2176b8260c5c..03b879699957 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -945,7 +945,7 @@ object desugar { report.error(IllegalRedefinitionOfStandardKind(kind, name), errPos) name = name.errorName } - if name.isExtensionName && !mdef.mods.is(ExtensionMethod) then + if name.isExtensionName && (!mdef.mods.is(ExtensionMethod) || name.dropExtension.isExtensionName) then report.error(em"illegal method name: $name may not start with `extension_`", errPos) name } diff --git a/tests/neg/illegal-extension.scala b/tests/neg/illegal-extension.scala index 5adbc87b8f18..e1d58755f1ff 100644 --- a/tests/neg/illegal-extension.scala +++ b/tests/neg/illegal-extension.scala @@ -1,3 +1,5 @@ trait A { def extension_n: String = "illegal method" // error: illegal method name: extension_n may not start with `extension_` } + +extension (x: Any) def extension_foo: String = "foo" // error: illegal method name: extension_foo may not start with `extension_`