Skip to content

Commit f5a0371

Browse files
authored
Merge pull request #9220 from dotty-staging/fix-#8875
Fix #8875: Make detection of extension methods work over all phases
2 parents 518135d + be35f83 commit f5a0371

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import TypeApplications._
2222
import Decorators._
2323
import scala.internal.Chars.isOperatorPart
2424
import transform.TypeUtils._
25+
import transform.SymUtils._
2526

2627
import language.implicitConversions
2728
import dotty.tools.dotc.util.{NameTransformer, SourcePosition}
@@ -784,7 +785,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
784785
import untpd._
785786
dclTextOr(tree) {
786787
val defKeyword = modText(tree.mods, tree.symbol, keywordStr("def"), isType = false)
787-
val isExtension = tree.hasType && tree.symbol.is(Extension)
788+
val isExtension = tree.hasType && tree.symbol.isExtensionMethod
788789
withEnclosingDef(tree) {
789790
val (prefix, vparamss) =
790791
if (isExtension) (defKeyword ~~ paramsText(tree.vparamss.head) ~~ valDefText(nameIdText(tree)), tree.vparamss.tail)

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,15 @@ class SymUtils(val self: Symbol) extends AnyVal {
212212
def isSplice(implicit ctx: Context): Boolean =
213213
self == defn.InternalQuoted_exprSplice || self == defn.InternalQuoted_exprNestedSplice || self == defn.QuotedType_splice
214214

215+
/** Is symbol an extension method? Accessors are excluded since
216+
* after the getters phase collective extension objects become accessors
217+
*/
218+
def isExtensionMethod(using Context): Boolean =
219+
self.isAllOf(ExtensionMethod, butNot = Accessor)
220+
221+
/** Is symbol the module class of a collective extension object? */
215222
def isCollectiveExtensionClass(using Context): Boolean =
216-
self.is(ModuleClass) && self.sourceModule.is(Extension, butNot = Method)
223+
self.is(ModuleClass) && self.sourceModule.is(Extension) && !self.sourceModule.isExtensionMethod
217224

218225
def isScalaStatic(using Context): Boolean =
219226
self.hasAnnotation(ctx.definitions.ScalaStaticAnnot)

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class CompilationTests extends ParallelTesting {
6464
compileFile("tests/pos-special/kind-projector.scala", defaultOptions.and("-Ykind-projector")),
6565
compileFile("tests/run/i5606.scala", defaultOptions.and("-Yretain-trees")),
6666
compileFile("tests/pos-custom-args/i5498-postfixOps.scala", defaultOptions withoutLanguageFeature "postfixOps"),
67+
compileFile("tests/pos-custom-args/i8875.scala", defaultOptions.and("-Xprint:getters")),
6768
).checkCompile()
6869
}
6970

tests/pos-custom-args/i8875.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class A {
2+
extension Ext on (a: Int) {
3+
def foo: Int = 1
4+
}
5+
}

0 commit comments

Comments
 (0)