From 8590b1a2b80f6a6dd6290f4bc5a96c6e00fcfc19 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Wed, 23 Sep 2020 15:23:12 +0200 Subject: [PATCH] fix #9766: extensions cannot be extension_foo --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 2 +- tests/neg/illegal-extension.scala | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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_`