Skip to content

Commit 4d512f0

Browse files
authored
Merge pull request #9256 from dotty-staging/fix-#9252
Fix #9252: Refine test for conflicting package objects
2 parents bc9dcbf + 176f159 commit 4d512f0

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-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) =

tests/pos-macros/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-macros/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-macros/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)