Commit 37d6d1e
committed
Avoid cycle with top-level export and trait
Previously, the following lead to a cycle (typing the extension method
requires typing its `Int` parameter, which forces completion of the
package object containing the top-level definition, which forces
completion of the extension method via the export clause):
trait MyExtensions:
extension (lhs: Int) def bash: Unit = {}
object MyExtensions extends MyExtensions
export MyExtensions.*
val fails = 1.bash
But curiously enough, simply defining `object MyExtensions` before
`trait MyExtensions` was enough to work around the issue. This happened
because typing the module val of the object forces the package object,
this in turns forces the extension method but because of the way
class completers work, this doesn't lead to a cycle.
Based on this experiment, this commit simply always forces the package
object before typing any definition in the package, so we don't run into
a cycle no matter the order in which definitions appear.1 parent eb8773e commit 37d6d1e
File tree
2 files changed
+10
-0
lines changed- compiler/src/dotty/tools/dotc/typer
- tests/pos
2 files changed
+10
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2542 | 2542 | | |
2543 | 2543 | | |
2544 | 2544 | | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
2545 | 2549 | | |
2546 | 2550 | | |
2547 | 2551 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
0 commit comments