Skip to content

Commit f8a0b63

Browse files
committed
Fix StaleSymbol for path dependent argument type in macro context
To fix we recalculate the symbol from directly from NamedType when from invalid run, instead of updating it's validity (which is impossible, as its owners do not include it in their decls).
1 parent 43c41ee commit f8a0b63

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Types.scala

+8-6
Original file line numberDiff line numberDiff line change
@@ -2743,14 +2743,16 @@ object Types {
27432743
/** A reference like this one, but with the given prefix. */
27442744
final def withPrefix(prefix: Type)(using Context): Type = {
27452745
def reload(): NamedType = {
2746-
val lastSym = lastSymbol.nn
2747-
val allowPrivate = !lastSym.exists || lastSym.is(Private)
2746+
val sym =
2747+
if lastSymbol.nn.isValidInCurrentRun then lastSymbol.nn
2748+
else computeSymbol
2749+
val allowPrivate = !sym.exists || sym.is(Private)
27482750
var d = memberDenot(prefix, name, allowPrivate)
2749-
if (d.isOverloaded && lastSym.exists)
2751+
if (d.isOverloaded && sym.exists)
27502752
d = disambiguate(d,
2751-
if (lastSym.signature == Signature.NotAMethod) Signature.NotAMethod
2752-
else lastSym.asSeenFrom(prefix).signature,
2753-
lastSym.targetName)
2753+
if (sym.signature == Signature.NotAMethod) Signature.NotAMethod
2754+
else sym.asSeenFrom(prefix).signature,
2755+
sym.targetName)
27542756
NamedType(prefix, name, d)
27552757
}
27562758
if (prefix eq this.prefix) this

Diff for: tests/pos-macros/i17294/Bar.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.quoted.*
2+
3+
class Bar[T]
4+
object Bar:
5+
transparent inline def bar[T](a: Foo, b: a.Out): Bar[T] = ${ getBarMacro[T] }
6+
def getBarMacro[T](using Quotes, Type[T]): Expr[Bar[T]] = '{ new Bar[T] }

Diff for: tests/pos-macros/i17294/Foo.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo:
2+
type Out = Int
3+
val a = Bar.bar(new Foo(), 0)

0 commit comments

Comments
 (0)