diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index d130d829d429..5d5345262520 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -22,6 +22,7 @@ import TypeApplications._ import Decorators._ import scala.internal.Chars.isOperatorPart import transform.TypeUtils._ +import transform.SymUtils._ import language.implicitConversions import dotty.tools.dotc.util.{NameTransformer, SourcePosition} @@ -784,7 +785,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { import untpd._ dclTextOr(tree) { val defKeyword = modText(tree.mods, tree.symbol, keywordStr("def"), isType = false) - val isExtension = tree.hasType && tree.symbol.is(Extension) + val isExtension = tree.hasType && tree.symbol.isExtensionMethod withEnclosingDef(tree) { val (prefix, vparamss) = if (isExtension) (defKeyword ~~ paramsText(tree.vparamss.head) ~~ valDefText(nameIdText(tree)), tree.vparamss.tail) diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index a3b55131865b..ce71c1ee3776 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -212,8 +212,15 @@ class SymUtils(val self: Symbol) extends AnyVal { def isSplice(implicit ctx: Context): Boolean = self == defn.InternalQuoted_exprSplice || self == defn.InternalQuoted_exprNestedSplice || self == defn.QuotedType_splice + /** Is symbol an extension method? Accessors are excluded since + * after the getters phase collective extension objects become accessors + */ + def isExtensionMethod(using Context): Boolean = + self.isAllOf(ExtensionMethod, butNot = Accessor) + + /** Is symbol the module class of a collective extension object? */ def isCollectiveExtensionClass(using Context): Boolean = - self.is(ModuleClass) && self.sourceModule.is(Extension, butNot = Method) + self.is(ModuleClass) && self.sourceModule.is(Extension) && !self.sourceModule.isExtensionMethod def isScalaStatic(using Context): Boolean = self.hasAnnotation(ctx.definitions.ScalaStaticAnnot) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index aeaeda4c5745..27764ea1aa4f 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -64,6 +64,7 @@ class CompilationTests extends ParallelTesting { compileFile("tests/pos-special/kind-projector.scala", defaultOptions.and("-Ykind-projector")), compileFile("tests/run/i5606.scala", defaultOptions.and("-Yretain-trees")), compileFile("tests/pos-custom-args/i5498-postfixOps.scala", defaultOptions withoutLanguageFeature "postfixOps"), + compileFile("tests/pos-custom-args/i8875.scala", defaultOptions.and("-Xprint:getters")), ).checkCompile() } diff --git a/tests/pos-custom-args/i8875.scala b/tests/pos-custom-args/i8875.scala new file mode 100644 index 000000000000..ff2c394057ae --- /dev/null +++ b/tests/pos-custom-args/i8875.scala @@ -0,0 +1,5 @@ +class A { + extension Ext on (a: Int) { + def foo: Int = 1 + } +} \ No newline at end of file