Skip to content

Commit 576d448

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 f3c2b1d commit 576d448

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
@@ -2754,14 +2754,16 @@ object Types {
27542754
/** A reference like this one, but with the given prefix. */
27552755
final def withPrefix(prefix: Type)(using Context): Type = {
27562756
def reload(): NamedType = {
2757-
val lastSym = lastSymbol.nn
2758-
val allowPrivate = !lastSym.exists || lastSym.is(Private)
2757+
val sym =
2758+
if lastSymbol.nn.isValidInCurrentRun then lastSymbol.nn
2759+
else computeSymbol
2760+
val allowPrivate = !sym.exists || sym.is(Private)
27592761
var d = memberDenot(prefix, name, allowPrivate)
2760-
if (d.isOverloaded && lastSym.exists)
2762+
if (d.isOverloaded && sym.exists)
27612763
d = disambiguate(d,
2762-
if (lastSym.signature == Signature.NotAMethod) Signature.NotAMethod
2763-
else lastSym.asSeenFrom(prefix).signature,
2764-
lastSym.targetName)
2764+
if (sym.signature == Signature.NotAMethod) Signature.NotAMethod
2765+
else sym.asSeenFrom(prefix).signature,
2766+
sym.targetName)
27652767
NamedType(prefix, name, d)
27662768
}
27672769
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)