Skip to content

Commit

Permalink
chore: do not enter scala 2 extension methods and let dotty generate …
Browse files Browse the repository at this point in the history
…them
  • Loading branch information
hamzaremmal committed Feb 4, 2025
1 parent 81e057a commit a641aeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,15 @@ 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) &&
// We don't enter Value Classes' extension methods from pickles, but we do
// generate in the ExtensionMethods phase, at the same time as we do for Scala 3
// 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

0 comments on commit a641aeb

Please sign in to comment.