-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
Milestone
Description
This is somewhat related to #23 and #60.
Consider this:
protocol A {
requires a;
}
protocol B {
[A.a] () { /* elided */ }
}Which of the following throws, if any?
class C1 implements A, B {}
class C2 implements B, A {}- Both throw
- C1 throws
- C2 throws
- None of them throw
Basically:
- Can provided members of one protocol satisfy required members of another protocol applied on the same class?
- If so, does the order of application matter?
If I’m reading things right, it appears that the current behavior is that protocols are checked+implemented sequentially, as if we were independently calling Protocol.implement(), in which case C1 would throw. While simple to spec, this does not seem optimal for authors.
I wonder if a slightly more intuitive behavior might be that protocols are first (conceptually) flattened, with provided members of one protocol being able to satisfy required members of another, and the host class only has to satisfy what remains. In that case, none of them would throw.
With that change, these would be equivalent (see #60):
protocol A {
requires a;
foo() { { /* elided */ }
}
protocol B {
[A.a] () { /* elided */ }
}
class C implements A, B {}protocol A {
requires a;
}
protocol B implements A {
[A.a] () { /* elided */ }
}
class C implements B {}