-
Notifications
You must be signed in to change notification settings - Fork 139
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
Reject duplicate interface conformances #2935
Comments
thanks @SupunS , the reason for this suggestion is, if we don't allow something like this: resource interface Receiver {
fun deposit(from: @FT){
// original default implementation
}
}
resource interface Vault: Receiver {
fun deposit(from: @FT){
// new default implementation
}
}
resource VaultImpl: Vault {
} |
Re-stating all interfaces in the type declaration's conformance list that the concrete type conforms to, is currently allowed and not required.
For the latter, the following pros/cons come to mind:
The sentiment in the team is that the current behaviour is a good middle ground. If there are strong opinions for changing the behaviour to either forbidding or requiring, we can discuss this further in an upcoming LDM and propose the change through a FLIP. |
I'm still leaning towards requiring it. I don't have an issue with a little more verbosity, and the issue about upstream updates updating and breaking downstream code doesn't seem like a real issue to me, because if upstream code adds new interface conformances, they're probably going to break downstream code anyway because the downstream code will still have to conform to the new interface. I don't feel super strongly about it though, so if everyone else wants to just keep the current behavior, I can accept that |
For me what is important here is that I can override a default implementation defined in something i extend. So lets say i want to compose on ViewResolver to change what the default views returned are. Currently i cannot do this, and @bluesign mentioned to me this issue would fix that. If we do not allow that, anybody that creates interfaces has to do extra work since they cannot have any default implementations in the interface they require. |
@bjartek correct me if I am wrong, but I think that is a separate issue. I think this issue is just about the conformance list, not the default implementations |
Ok, then I might be confusing things. If you publish an interface you can always add a new method and thus breaking everything relying on you regardless. |
@joshuahannan this is a requirement for that one actually Consider: resource interface Receiver {
fun deposit(from: @FT){
// original default implementation
}
}
resource interface Vault: Receiver {
fun deposit(from: @FT){
// new default implementation
}
} if I declare my resource as: resource VaultImpl: Vault, Receiver {
} there is a conflict with But if we declare it as: resource VaultImpl: Vault {
} Then we can use the |
So in your example @bluesign it is not possible to say that since Vault is defined before Receiver its implementation will superseed Receivers? |
It should be possible but I think order of interfaces makes it little confusing. But totally viable option. I think optimum solution is to look for distance even |
I see the issue now. yeah, if possible, it seems like we could say that since |
Btw this is not urgent at all, we can always say that we will implement something like java later and select interface defaults by distance. My suggestion was just disallowing now, and maybe later release when we have the complicated implementation in place, I don't have too hard opinion on this. |
potentially braking change for 1.0 |
I guess this change won't go into Cadence 1.0, so we can maybe remove it from #2642, and maybe even close it? @onflow/cadence wdyt? |
I am in favour of closing, it is not that important considering the current usage of interfaces actually. |
This would require a breaking change and we don't have consensus, closing. |
Issue to be solved
Suggestion from @bluesign (please feel free to update, add more info)
If
Vault
conforms toReceiver
i.e:
And an implementation/or another interface conforms to both
Receiver
andVault
i.e:
Then report an error, since
Vault
already conforms toReceiver
, and thus,VaultImpl
explicitly conforming toReceiver
again makes it a duplicate conformance.i.e:
Suggested Solution
See above
The text was updated successfully, but these errors were encountered: