Skip to content

Commit

Permalink
Merge pull request scala#9256 from dotty-staging/fix-#9252
Browse files Browse the repository at this point in the history
Fix scala#9252: Refine test for conflicting package objects
  • Loading branch information
odersky authored Jun 29, 2020
2 parents bc9dcbf + 176f159 commit 4d512f0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
3 changes: 3 additions & 0 deletions tests/pos-macros/i9252/Clazz.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Clazz {
def foo = Macro.expand()
}
4 changes: 4 additions & 0 deletions tests/pos-macros/i9252/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Macro {
inline def expand(): Unit = ${impl}
def impl(using scala.quoted.QuoteContext) = '{???}
}
1 change: 1 addition & 0 deletions tests/pos-macros/i9252/toplevel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def fct: Unit = Macro.expand()

0 comments on commit 4d512f0

Please sign in to comment.