Skip to content

Commit

Permalink
Use "$direct" instead of just "$" to prevent erasure clashes
Browse files Browse the repository at this point in the history
Use "$direct" instead of just "$" to prevent erasure clashes of methods
with erased context function results.
  • Loading branch information
odersky committed Nov 3, 2021
1 parent 64db3eb commit 7e6e9ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/NameKinds.scala
Expand Up @@ -365,7 +365,7 @@ object NameKinds {
val ExtMethName: SuffixNameKind = new SuffixNameKind(EXTMETH, "$extension")
val ParamAccessorName: SuffixNameKind = new SuffixNameKind(PARAMACC, "$accessor")
val ModuleClassName: SuffixNameKind = new SuffixNameKind(OBJECTCLASS, "$", optInfoString = "ModuleClass")
val ImplMethName: SuffixNameKind = new SuffixNameKind(IMPLMETH, "$")
val DirectMethName: SuffixNameKind = new SuffixNameKind(DIRECT, "$direct")
val AdaptedClosureName: SuffixNameKind = new SuffixNameKind(ADAPTEDCLOSURE, "$adapted") { override def definesNewName = true }
val SyntheticSetterName: SuffixNameKind = new SuffixNameKind(SETTER, "_$eq")

Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/NameTags.scala
Expand Up @@ -24,8 +24,9 @@ object NameTags extends TastyFormat.NameTags {

final val ADAPTEDCLOSURE = 31 // Used in Erasure to adapt closures over primitive types.

final val IMPLMETH = 32 // Used to define methods in implementation classes
// (can probably be removed).
final val DIRECT = 32 // Used to define implementations of methods with
// erased context function results that can override some
// other method.

final val PARAMACC = 33 // Used for a private parameter alias

Expand All @@ -48,7 +49,7 @@ object NameTags extends TastyFormat.NameTags {
case INITIALIZER => "INITIALIZER"
case FIELD => "FIELD"
case EXTMETH => "EXTMETH"
case IMPLMETH => "IMPLMETH"
case DIRECT => "DIRECT"
case PARAMACC => "PARAMACC"
case ADAPTEDCLOSURE => "ADAPTEDCLOSURE"
case OBJECTCLASS => "OBJECTCLASS"
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Expand Up @@ -12,7 +12,7 @@ import core.Types._
import core.Names._
import core.StdNames._
import core.NameOps._
import core.NameKinds.{AdaptedClosureName, BodyRetainerName, ImplMethName}
import core.NameKinds.{AdaptedClosureName, BodyRetainerName, DirectMethName}
import core.Scopes.newScopeWith
import core.Decorators._
import core.Constants._
Expand Down Expand Up @@ -63,10 +63,10 @@ class Erasure extends Phase with DenotTransformer {
&& contextResultsAreErased(ref.symbol)
&& (ref.owner.is(Flags.Trait) || ref.symbol.allOverriddenSymbols.hasNext)
then
// Add a `$` to prevent this method from having the same signature
// Add a `$direct` to prevent this method from having the same signature
// as a method it overrides. We need a bridge between the
// two methods, so they are not allowed to already override after erasure.
ImplMethName(ref.targetName.asTermName)
DirectMethName(ref.targetName.asTermName)
else
ref.targetName

Expand Down

0 comments on commit 7e6e9ec

Please sign in to comment.