Skip to content

Commit 97c772b

Browse files
authored
Merge pull request #13719 from dotty-staging/toplevel-export-cycle
Avoid cycle with top-level export and trait
2 parents 1cffaa4 + 37d6d1e commit 97c772b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,10 @@ class Typer extends Namer
25462546
pid1 match
25472547
case pid1: RefTree if pkg.is(Package) =>
25482548
inContext(ctx.packageContext(tree, pkg)) {
2549+
// If it exists, complete the class containing the top-level definitions
2550+
// before typing any statement in the package to avoid cycles as in i13669.scala
2551+
val topLevelClassName = desugar.packageObjectName(ctx.source).moduleClassName
2552+
pkg.moduleClass.info.decls.lookup(topLevelClassName).ensureCompleted()
25492553
var stats1 = typedStats(tree.stats, pkg.moduleClass)._1
25502554
if (!ctx.isAfterTyper)
25512555
stats1 = stats1 ++ typedBlockStats(MainProxies.mainProxies(stats1))._1

tests/pos/i13669.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait MyExtensions:
2+
extension (lhs: Int) def bash: Unit = {}
3+
object MyExtensions extends MyExtensions
4+
5+
export MyExtensions.*
6+
val fails = 1.bash

0 commit comments

Comments
 (0)