diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 550fd34fac0a..f436f782f5a7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -289,6 +289,13 @@ class Namer { typer: Typer => val preExisting = owner.unforcedDecls.lookup(name) if (preExisting.isDefinedInCurrentRun || preExisting.lastKnownDenotation.is(Package)) && (!preExisting.lastKnownDenotation.is(Private) || preExisting.owner.is(Package)) + && (!preExisting.lastKnownDenotation.isPackageObject + || preExisting.associatedFile != ctx.source.file) + // isDefinedInCurrentRun does not work correctly for package objects, because + // package objects are updated to the new run earlier than normal classes, everytime + // some member of the enclosing package is accessed. Therefore, we use another + // test: conflict if package objects have the same name but come from different + // sources. See i9252. then conflict(preExisting) def pkgObjs(pkg: Symbol) = diff --git a/tests/pos-macros/i9252/Clazz.scala b/tests/pos-macros/i9252/Clazz.scala new file mode 100644 index 000000000000..083aded0e2d2 --- /dev/null +++ b/tests/pos-macros/i9252/Clazz.scala @@ -0,0 +1,3 @@ +class Clazz { + def foo = Macro.expand() +} \ No newline at end of file diff --git a/tests/pos-macros/i9252/Macro.scala b/tests/pos-macros/i9252/Macro.scala new file mode 100644 index 000000000000..0ac55b57cdf2 --- /dev/null +++ b/tests/pos-macros/i9252/Macro.scala @@ -0,0 +1,4 @@ +object Macro { + inline def expand(): Unit = ${impl} + def impl(using scala.quoted.QuoteContext) = '{???} +} \ No newline at end of file diff --git a/tests/pos-macros/i9252/toplevel.scala b/tests/pos-macros/i9252/toplevel.scala new file mode 100644 index 000000000000..5e935656a345 --- /dev/null +++ b/tests/pos-macros/i9252/toplevel.scala @@ -0,0 +1 @@ +def fct: Unit = Macro.expand()