Skip to content
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

Do not enter Scala 2 extension methods and let dotty "generate" them #22519

Merged
merged 2 commits into from
Feb 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,14 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
true) &&
// We discard the private val representing a case accessor. We only enter the case accessor def.
// We do need to load these symbols to read properly unpickle the annotations on the symbol (see sbt-test/scala2-compat/i19421).
!flags.isAllOf(CaseAccessor | PrivateLocal, butNot = Method)
!flags.isAllOf(CaseAccessor | PrivateLocal, butNot = Method) &&
// Skip entering extension methods: they will be recreated by the ExtensionMethods phase.
// Same trick is used by tasty-query (see
//https://github.com/scalacenter/tasty-query/blob/fdefadcabb2f21d5c4b71f728b81c68f6fddcc0f/tasty-query/shared/src/main/scala/tastyquery/reader/pickles/PickleReader.scala#L261-L273
//)
// This trick is also useful when reading the Scala 2 Standard library from tasty, since
// the extension methods will not be present, and it avoid having to distinguish between Scala2 pickles and Scala2 tasty (stdlib)
!(owner.is(ModuleClass) && sym.name.endsWith("$extension"))

if (canEnter)
owner.asClass.enter(sym, symScope(owner))
Expand Down
10 changes: 4 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
sym.validFor = thisPhase.validFor
}

// Create extension methods, except if the class comes from Scala 2
// because it adds extension methods before pickling.
if !valueClass.is(Scala2x, butNot = Scala2Tasty) then
for (decl <- valueClass.classInfo.decls)
if isMethodWithExtension(decl) then
enterInModuleClass(createExtensionMethod(decl, moduleClassSym.symbol))
// Create extension methods
for (decl <- valueClass.classInfo.decls)
if isMethodWithExtension(decl) then
enterInModuleClass(createExtensionMethod(decl, moduleClassSym.symbol))

// Create synthetic methods to cast values between the underlying type
// and the ErasedValueType. These methods are removed in ElimErasedValueType.
Expand Down
Loading