Skip to content

Commit de2cc10

Browse files
oderskyallanrenucci
authored andcommitted
A better honeytrap for Symbol#symbol
Managed to find two more violations at compile time.
1 parent 43df1a2 commit de2cc10

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,11 @@ object Symbols {
574574

575575
/** A trap to avoid calling x.symbol on something that is already a symbol.
576576
* This would be expanded to `toDenot(x).symbol` which is guaraneteed to be
577-
* the same as `x`
577+
* the same as `x`.
578+
* With the given setup, all such calls will give implicit-not found errors
578579
*/
579-
final def symbol: Nothing = unsupported("symbol")
580+
final def symbol(implicit ev: DontUseSymbolOnSymbol): Nothing = unsupported("symbol")
581+
type DontUseSymbolOnSymbol
580582

581583
/** The source file from which this class was generated, null if not applicable. */
582584
final def sourceFile(implicit ctx: Context): AbstractFile = {
@@ -803,5 +805,4 @@ object Symbols {
803805

804806
@inline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
805807
new MutableSymbolMap(new java.util.IdentityHashMap[Symbol, T]())
806-
807808
}

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
351351
val owner = if (atEnd) loadingMirror.RootClass else readSymbolRef()
352352

353353
def adjust(denot: Denotation) = {
354-
val denot1 = denot.disambiguate(d => p(d.symbol))
354+
val denot1 = denot.disambiguate(p)
355355
val sym = denot1.symbol
356356
if (denot.exists && !denot1.exists) { // !!!DEBUG
357357
val alts = denot.alternatives map (d => d + ":" + d.info + "/" + d.signature)

compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
9292
case t @ NewCaseClassValDef(fun, args) if newFieldsMapping.contains(t.symbol) =>
9393
val newFields = newFieldsMapping(t.symbol).values.toList
9494
val newFieldsDefs = newFields.zip(args).map { case (nf, arg) =>
95-
val rhs = arg.changeOwnerAfter(t.symbol, nf.symbol, simplifyPhase)
95+
val rhs = arg.changeOwnerAfter(t.symbol, nf, simplifyPhase)
9696
ValDef(nf.asTerm, rhs)
9797
}
9898
val recreate = cpy.ValDef(t)(rhs = fun.appliedToArgs(newFields.map(x => ref(x))))

0 commit comments

Comments
 (0)