Commit ba624b5
committed
Complete owners of type parameters before parameters themselves
Fixes #10967
I minimized #10967 further to:
```scala
trait SomeTrait
trait CollBase[CC1[A2 <: SomeTrait]] {
val companion: CollCompanion[CC1]
}
trait CollCompanion[CC2[A <: SomeTrait]]
```
What happened was:
1. the compiler tries to typecheck `companion`
2. this means needs to check `CollCompanion[CC1]`
3. this means it needs to complete the type parameter `CC2` of CollCompanion in order to make sure the argument is CC1 is kind correct.
4. this means we complete type parameter `A` of `CC2`
4. checking the type parameter requires checking the owner class `CollCompanion`.
5. And this leads back to `CC2`, hence the cycle.
Note that if the definitions of `CollBase` and `CollCompanion` appear in reverse order,
no cycle results, since then `CollCompanion` and its type parameters were completed before
completing `companion`.
To break the cycle, we can complete the owner of a type parameter before starting
completion of the parameter. Furthermore, we need to do this only in Namer, which is
where the complex checking patterns are. I have not tried to also treat symbols that
are not type definitions that way. It's not necessary to fix #10967 but it might help
for other cycles (or it might cause them, these things are tricky!). I did try to
make the behavior universal for all completers, not just Namers, but that caused
crashes immediately.1 parent 141bf9e commit ba624b5
File tree
4 files changed
+60
-25
lines changed- compiler/src/dotty/tools/dotc
- core
- typer
- tests/pos
4 files changed
+60
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
157 | 163 | | |
158 | | - | |
159 | | - | |
160 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
161 | 168 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
| |||
2517 | 2518 | | |
2518 | 2519 | | |
2519 | 2520 | | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
2520 | 2528 | | |
2521 | 2529 | | |
2522 | 2530 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
215 | | - | |
216 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
217 | 221 | | |
218 | 222 | | |
219 | 223 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
841 | 841 | | |
842 | 842 | | |
843 | 843 | | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
844 | 858 | | |
845 | 859 | | |
846 | 860 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments