Skip to content

Commit 649e3d1

Browse files
authored
Merge pull request #37 from scala/backport-lts-3.3-21414
Backport "Avoid using the current denotation in NamedType.disambiguate" to 3.3 LTS
2 parents 63675c6 + 1664597 commit 649e3d1

File tree

7 files changed

+53
-4
lines changed

7 files changed

+53
-4
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ object Denotations {
946946
}
947947

948948
def staleSymbolError(using Context): Nothing =
949-
if symbol.isPackageObject && ctx.run != null && ctx.run.nn.isCompilingSuspended
949+
if symbol.lastKnownDenotation.isPackageObject && ctx.run != null && ctx.run.nn.isCompilingSuspended
950950
then throw StaleSymbolTypeError(symbol)
951951
else throw StaleSymbolException(staleSymbolMsg)
952952

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ enum SourceLanguage:
2424
object SourceLanguage:
2525
/** The language in which `sym` was defined. */
2626
def apply(sym: Symbol)(using Context): SourceLanguage =
27-
if sym.is(JavaDefined) then
27+
// We might be using this method while recalculating the denotation,
28+
// so let's use `lastKnownDenotation`.
29+
// This is ok as the source of the symbol and whether it is inline should
30+
// not change between runs/phases.
31+
val denot = sym.lastKnownDenotation
32+
if denot.is(JavaDefined) then
2833
SourceLanguage.Java
2934
// Scala 2 methods don't have Inline set, except for the ones injected with `patchStdlibClass`
3035
// which are really Scala 3 methods.
31-
else if sym.isClass && sym.is(Scala2x) || (sym.maybeOwner.is(Scala2x) && !sym.is(Inline)) then
36+
else if denot.isClass && denot.is(Scala2x) || (denot.maybeOwner.lastKnownDenotation.is(Scala2x) && !denot.is(Inline)) then
3237
SourceLanguage.Scala2
3338
else
3439
SourceLanguage.Scala3

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,10 @@ object Types extends TypeUtils {
24212421
}
24222422

24232423
private def disambiguate(d: Denotation)(using Context): Denotation =
2424-
disambiguate(d, currentSignature, currentSymbol.targetName)
2424+
// this method might be triggered while the denotation is already being recomputed
2425+
// in NamedType, so it's better to use lastKnownDenotation instead, as targetName
2426+
// should not change between phases/runs
2427+
disambiguate(d, currentSignature, currentSymbol.lastKnownDenotation.targetName)
24252428

24262429
private def disambiguate(d: Denotation, sig: Signature | Null, target: Name)(using Context): Denotation =
24272430
if (sig != null)

Diff for: tests/pos-macros/i20574/Exports.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Exports{
2+
export OverloadedInline.*
3+
}

Diff for: tests/pos-macros/i20574/Macros.scala

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import scala.quoted.*
2+
3+
object Macros{
4+
5+
inline def A() : String = {
6+
${ A_impl }
7+
}
8+
9+
def A_impl(using Quotes): Expr[String] = {
10+
Expr("Whatever")
11+
}
12+
13+
inline def B[T]: Int = {
14+
${ B_Impl[T] }
15+
}
16+
17+
def B_Impl[T](using Quotes): Expr[Int] = {
18+
Expr(0)
19+
}
20+
}

Diff for: tests/pos-macros/i20574/OverloadedInline.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Macros.*
2+
3+
object OverloadedInline{
4+
5+
A()
6+
inline def overloaded_inline[T]: Unit = {
7+
overloaded_inline[T](0)
8+
}
9+
10+
inline def overloaded_inline[T](dummy: Int): Unit = {
11+
val crash = B[T]
12+
}
13+
}

Diff for: tests/pos-macros/i20574/Test.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Exports.*
2+
3+
object Test {
4+
overloaded_inline[Unit]
5+
}

0 commit comments

Comments
 (0)