Skip to content

Commit

Permalink
Merge pull request #13719 from dotty-staging/toplevel-export-cycle
Browse files Browse the repository at this point in the history
Avoid cycle with top-level export and trait
  • Loading branch information
odersky committed Oct 8, 2021
2 parents 1cffaa4 + 37d6d1e commit 97c772b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Expand Up @@ -2546,6 +2546,10 @@ class Typer extends Namer
pid1 match
case pid1: RefTree if pkg.is(Package) =>
inContext(ctx.packageContext(tree, pkg)) {
// If it exists, complete the class containing the top-level definitions
// before typing any statement in the package to avoid cycles as in i13669.scala
val topLevelClassName = desugar.packageObjectName(ctx.source).moduleClassName
pkg.moduleClass.info.decls.lookup(topLevelClassName).ensureCompleted()
var stats1 = typedStats(tree.stats, pkg.moduleClass)._1
if (!ctx.isAfterTyper)
stats1 = stats1 ++ typedBlockStats(MainProxies.mainProxies(stats1))._1
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i13669.scala
@@ -0,0 +1,6 @@
trait MyExtensions:
extension (lhs: Int) def bash: Unit = {}
object MyExtensions extends MyExtensions

export MyExtensions.*
val fails = 1.bash

0 comments on commit 97c772b

Please sign in to comment.