Commit 668f3eb
committed
Drop requirement that self types are closed
#702 introduced a requirement that self types are closed. This means
> If trait X has self type S and C is a class symbol of S, then S also conforms
to the self type of C.
An example that violates this requirement is
```scala
trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y
trait Y { self: Z => }
trait Z
```
But it's no longer clear what the requirement should achieve. If we let the example above
typecheck and try to implement X with something like
```scala
class C extends X, Y
```
we would at that point get an error saying that `C` does not conform to the self type Z of Y.
So it would have to be
```scala
class C extends X, Y, Z
```
and this one looks fine.
The original change in #702 was made to avoid a crash in pending/run/t7933.scala.
Unfortunately, we cannot reproduce this anymore since it depends on nsc.interpreter,
which is no longer part of Scala 2.13.
Since we are no longer sure what the restriction should achieve I think it's better to
drop it for now. If people discover problems with code that uses "open" self types, we
can try to fix those problems, and if that does not work, would fallback re-instituting
the restriction. It's not ideal, but I don't see another way.1 parent ed81385 commit 668f3eb
File tree
5 files changed
+20
-25
lines changed- compiler/src/dotty/tools/dotc
- core
- typer
- tests
- neg
- pos
5 files changed
+20
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
| 705 | + | |
| 706 | + | |
720 | 707 | | |
721 | 708 | | |
722 | 709 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 113 | + | |
117 | 114 | | |
118 | 115 | | |
119 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
0 commit comments