Skip to content

Fix #8875: Make detection of extension methods work over all phases #9220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
5 changes: 5 additions & 0 deletions tests/pos-custom-args/i8875.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class A {
extension Ext on (a: Int) {
def foo: Int = 1
}
}