Skip to content

Commit f10c709

Browse files
committed
Fix #9252: Refine test for conflicting package objects
1 parent 50df4d2 commit f10c709

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ class Namer { typer: Typer =>
289289
val preExisting = owner.unforcedDecls.lookup(name)
290290
if (preExisting.isDefinedInCurrentRun || preExisting.lastKnownDenotation.is(Package))
291291
&& (!preExisting.lastKnownDenotation.is(Private) || preExisting.owner.is(Package))
292+
&& (!preExisting.lastKnownDenotation.isPackageObject
293+
|| preExisting.associatedFile != ctx.source.file)
294+
// isDefinedInCurrentRun does not work correctly for package objects, because
295+
// package objects are updated to the new run earlier than normal classes, everytime
296+
// some member of the enclosing package is accessed. Therefore, we use another
297+
// test: conflict if package objects have the same name but come from different
298+
// sources. See i9252.
292299
then conflict(preExisting)
293300

294301
def pkgObjs(pkg: Symbol) =

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ i7757.scala
4343

4444
# splice type tag dealiased in this reference
4545
i8651b.scala
46+
47+
# suspended macros need multiple runs
48+
i9252

tests/pos/i9252/Clazz.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Clazz {
2+
def foo = Macro.expand()
3+
}

tests/pos/i9252/Macro.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Macro {
2+
inline def expand(): Unit = ${impl}
3+
def impl(using scala.quoted.QuoteContext) = '{???}
4+
}

tests/pos/i9252/toplevel.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def fct: Unit = Macro.expand()

0 commit comments

Comments
 (0)