Skip to content

Commit 4bfa6da

Browse files
committed
A better honey trap for Symbol#symbol
Managed to find two more violations at compile time.
1 parent 03e6cab commit 4bfa6da

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
@@ -598,9 +598,11 @@ object Symbols {
598598

599599
/** A trap to avoid calling x.symbol on something that is already a symbol.
600600
* This would be expanded to `toDenot(x).symbol` which is guaraneteed to be
601-
* the same as `x`
601+
* the same as `x`.
602+
* Withg the given setup, all such calls will give implicit-not found errors
602603
*/
603-
final def symbol: Nothing = unsupported("symbol")
604+
final def symbol(implicit ev: DontUseSymbolOnSymbol): Nothing = unsupported("symbol")
605+
type DontUseSymbolOnSymbol
604606

605607
/** The source file from which this class was generated, null if not applicable. */
606608
final def sourceFile(implicit ctx: Context): AbstractFile = {
@@ -827,5 +829,4 @@ object Symbols {
827829

828830
@inline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
829831
new MutableSymbolMap(new java.util.IdentityHashMap[Symbol, T]())
830-
831832
}

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)