Skip to content

Commit

Permalink
Fix StaleSymbol for path dependent argument type in macro context
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jchyb committed Jun 27, 2023
1 parent 43c41ee commit f8a0b63
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2743,14 +2743,16 @@ object Types {
/** A reference like this one, but with the given prefix. */
final def withPrefix(prefix: Type)(using Context): Type = {
def reload(): NamedType = {
val lastSym = lastSymbol.nn
val allowPrivate = !lastSym.exists || lastSym.is(Private)
val sym =
if lastSymbol.nn.isValidInCurrentRun then lastSymbol.nn
else computeSymbol
val allowPrivate = !sym.exists || sym.is(Private)
var d = memberDenot(prefix, name, allowPrivate)
if (d.isOverloaded && lastSym.exists)
if (d.isOverloaded && sym.exists)
d = disambiguate(d,
if (lastSym.signature == Signature.NotAMethod) Signature.NotAMethod
else lastSym.asSeenFrom(prefix).signature,
lastSym.targetName)
if (sym.signature == Signature.NotAMethod) Signature.NotAMethod
else sym.asSeenFrom(prefix).signature,
sym.targetName)
NamedType(prefix, name, d)
}
if (prefix eq this.prefix) this
Expand Down
6 changes: 6 additions & 0 deletions tests/pos-macros/i17294/Bar.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.quoted.*

class Bar[T]
object Bar:
transparent inline def bar[T](a: Foo, b: a.Out): Bar[T] = ${ getBarMacro[T] }
def getBarMacro[T](using Quotes, Type[T]): Expr[Bar[T]] = '{ new Bar[T] }
3 changes: 3 additions & 0 deletions tests/pos-macros/i17294/Foo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo:
type Out = Int
val a = Bar.bar(new Foo(), 0)

0 comments on commit f8a0b63

Please sign in to comment.