-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FLIP: interface inheritance in Cadence #40
Conversation
87dfae2
to
fb4f3be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for writing this up. This is a really thorny design space so we should take care to iron out all the edge cases here. I had some specific questions below, but also some general ones:
-
How will this new feature interact with the proposed changes in Events emitted from interfaces cadence#2069 or Allow composites to inherit events from interfaces cadence#2081 ? If events can be "inherited" from interfaces, how do they resolve in cases of multiple inheritance?
-
I think this change would also benefit from a redundancy check in any places where a list of interfaces might appear. In a conformance list, for example, it would be redundant to say
MyVault: Receiver, Vault
, so we should have a static error warning that theReceiver
annotation is unnecessary in the presence of theVault
annotation. The same would go for restricted types' restriction lists.
Thanks for bringing this up! I was thinking the type definitions would also behaves similarly to the default functions. Added a section for this: d98d658 |
Yes definitely, we could add a redundancy check for conformances. Having redundant conformances can sometimes cause static errors by the current rules (i.e: when there are overridden default functions, etc.). Others can be checked at a linter phase. |
It looks like Swift's solution is to reject diamond conflicts, instead e.g. picking a certain default implementation: https://www.vadimbulavin.com/multiple-inheritance-swift/ |
We had a breakout session regarding the diamond problem today, and rejecting the default function conflicts (as proposed in this FLIP) was favored by the majority. A detailed summary of the solutions discussed in the meeting is as below.
|
@SupunS Nice! It looks like the decision needs to be reflected in this section: https://github.com/onflow/flips/pull/40/files#diff-0e651e7f8b8bd0a53ffe1e6333ac854ee0a0c7c6932d1bbcd3b51883f18161e8R190-R194 |
Updated the FLIP with the latest discussion outcomes (7127f6b). Also added a new section on how the interfaces/conditions would be linearized (9005d7f). TL;DR is, conditions are linearized in a depth-first pre-order manner, ignoring any duplicates (duplicates are cases where there are two or more paths to the same interface/condition). |
Reference implementation: onflow/cadence#2112 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great proposal!
If a user needed to access the `Foo` struct coming from the super interface `Token`, then they can | ||
access it using the fully qualified name. e.g: `let foo: Token.Foo`. | ||
|
||
However, it is not allowed to have two or more inherited type/events definitions with identical names for an interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this forbidden?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because of the type requirements. If there are types with identical names, the concrete type that implements these two interfaces might not be able to satisfy them both. So here it is taking the most restricted approach by rejecting such conflicts.
However, this can be relaxed after the type requirements are removed.
Co-authored-by: Bastian Müller <bastian@turbolent.com>
c8a1a44
to
df280d3
Compare
df280d3
to
38d5c9a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty happy with this! Just had one comment
6f86d86
to
f9737a2
Compare
f9737a2
to
2d86db5
Compare
Thanks everyone for the suggestions and feedback for this proposal so far! This FLIP has been open for a while, and it seems we are all happy with the current proposal, and seems there are no any remaining concerns. You can follow how the implementation is progressing here ➡️ onflow/cadence#2112 |
Discussion: https://forum.onflow.org/t/flip-interface-inheritance-in-cadence/3750
Reference implementation: onflow/cadence#2112