Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid cycle with top-level export and trait #13719

Merged
merged 1 commit into from Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Expand Up @@ -2542,6 +2542,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