From f10c709c338a4430f8c65478cf07eaad28dfa87c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 28 Jun 2020 22:29:30 +0200 Subject: [PATCH 1/2] Fix #9252: Refine test for conflicting package objects --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 7 +++++++ compiler/test/dotc/pos-test-pickling.blacklist | 3 +++ tests/pos/i9252/Clazz.scala | 3 +++ tests/pos/i9252/Macro.scala | 4 ++++ tests/pos/i9252/toplevel.scala | 1 + 5 files changed, 18 insertions(+) create mode 100644 tests/pos/i9252/Clazz.scala create mode 100644 tests/pos/i9252/Macro.scala create mode 100644 tests/pos/i9252/toplevel.scala 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/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index 564488b3d032..c22da066a6f9 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -43,3 +43,6 @@ i7757.scala # splice type tag dealiased in this reference i8651b.scala + +# suspended macros need multiple runs +i9252 \ No newline at end of file diff --git a/tests/pos/i9252/Clazz.scala b/tests/pos/i9252/Clazz.scala new file mode 100644 index 000000000000..083aded0e2d2 --- /dev/null +++ b/tests/pos/i9252/Clazz.scala @@ -0,0 +1,3 @@ +class Clazz { + def foo = Macro.expand() +} \ No newline at end of file diff --git a/tests/pos/i9252/Macro.scala b/tests/pos/i9252/Macro.scala new file mode 100644 index 000000000000..0ac55b57cdf2 --- /dev/null +++ b/tests/pos/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/i9252/toplevel.scala b/tests/pos/i9252/toplevel.scala new file mode 100644 index 000000000000..5e935656a345 --- /dev/null +++ b/tests/pos/i9252/toplevel.scala @@ -0,0 +1 @@ +def fct: Unit = Macro.expand() From 176f159686312769db957fd6be7c0c50e2c481ac Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 29 Jun 2020 10:45:48 +0200 Subject: [PATCH 2/2] Move tests to pos-macros --- compiler/test/dotc/pos-test-pickling.blacklist | 3 --- tests/{pos => pos-macros}/i9252/Clazz.scala | 0 tests/{pos => pos-macros}/i9252/Macro.scala | 0 tests/{pos => pos-macros}/i9252/toplevel.scala | 0 4 files changed, 3 deletions(-) rename tests/{pos => pos-macros}/i9252/Clazz.scala (100%) rename tests/{pos => pos-macros}/i9252/Macro.scala (100%) rename tests/{pos => pos-macros}/i9252/toplevel.scala (100%) diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index c22da066a6f9..564488b3d032 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -43,6 +43,3 @@ i7757.scala # splice type tag dealiased in this reference i8651b.scala - -# suspended macros need multiple runs -i9252 \ No newline at end of file diff --git a/tests/pos/i9252/Clazz.scala b/tests/pos-macros/i9252/Clazz.scala similarity index 100% rename from tests/pos/i9252/Clazz.scala rename to tests/pos-macros/i9252/Clazz.scala diff --git a/tests/pos/i9252/Macro.scala b/tests/pos-macros/i9252/Macro.scala similarity index 100% rename from tests/pos/i9252/Macro.scala rename to tests/pos-macros/i9252/Macro.scala diff --git a/tests/pos/i9252/toplevel.scala b/tests/pos-macros/i9252/toplevel.scala similarity index 100% rename from tests/pos/i9252/toplevel.scala rename to tests/pos-macros/i9252/toplevel.scala