Commit 847530e
committed
Avoid infinite loop in type variable instantiation
Rename `checkNonCyclic` to `occursAtToplevel` and refactor it to return
a boolean, use it in `ConstraintHandling#instanceType` to make sure we
do not introduce a cycle when instantiating a type variable.
Some alternatives I considered:
- Run `widenInferred` inside frozen constraints: this prevents
`Set[A] | Set[Int]` to be widened to `Set[Int]` after instantiating
`A := Int`
- Run `widenInferred` with the upper bound of `param` instead of `param`
itself as a bound: I think this is still not safe because the upper
bound of `param` might recursively refer to `param`, it also breaks
type inference of one expression in ZIO.1 parent 59587ba commit 847530e
File tree
4 files changed
+55
-21
lines changed- compiler/src/dotty/tools/dotc/core
- tests/neg
4 files changed
+55
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
| |||
Lines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
364 | | - | |
365 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
366 | 379 | | |
367 | 380 | | |
368 | 381 | | |
| |||
Lines changed: 22 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
304 | | - | |
| 303 | + | |
| 304 | + | |
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| |||
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
597 | | - | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
598 | 605 | | |
599 | 606 | | |
600 | | - | |
601 | | - | |
| 607 | + | |
602 | 608 | | |
603 | | - | |
| 609 | + | |
604 | 610 | | |
605 | | - | |
606 | | - | |
| 611 | + | |
607 | 612 | | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
613 | 617 | | |
614 | | - | |
| 618 | + | |
615 | 619 | | |
616 | | - | |
617 | | - | |
| 620 | + | |
618 | 621 | | |
619 | 622 | | |
620 | | - | |
| 623 | + | |
621 | 624 | | |
622 | | - | |
623 | | - | |
| 625 | + | |
| 626 | + | |
624 | 627 | | |
625 | 628 | | |
626 | 629 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments