-
Notifications
You must be signed in to change notification settings - Fork 138
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
Interface default implementation support #1076
Conversation
@turbolent any chance you could take a peak at this. |
Thank you again for your work here @bluesign! The review and merge will have to wait a while, as we currently have a backlog of work to integrate. Thank you for you patience |
If I have an interface that requires a method and that has a default implementation that appears to not be allowed now. In my GeneircNFT repo https://github.com/bjartek/flow-nfmt/blob/nftv2/contracts/GenericNFT.cdc i tried to make borrowNFT be default implemented but it does not work. If possible this should be fixed. |
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 work!
@turbolent thanks for the review, I am planning to jump in tomorrow. |
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
I think I managed to do all, just @SupunS's variable scope comment left, but I have no idea tbh how to approach that. |
Do we have (a) test case(s) that ensure that default implementations are only able to have the same access as non-receiver functions? It would be great to test e.g. that a default function does not have access to the members of the concrete type it is implemented by. For example, this program should be invalid: struct interface SI {
s: Int
fun default() {
self.s = 1
}
}
struct S: SI {
var s: Int
init() {
self.s = 0
}
} |
@turbolent I don't see the problem here, can you expand a bit?
default function should have access in my opinion. Otherwise they will not have any use case. For example:
|
Yes, an example would be: struct interface SI {
fun default() {
self.s = 1
}
}
struct S: SI {
var s: Int
init() {
self.s = 0
}
} Here, Refarding the other example case from my previous post: struct interface SI {
s: Int
fun default() {
self.s = 1
}
}
struct S: SI {
var s: Int
init() {
self.s = 0
}
} Here, This may already be handled, but I'm not sure, so it would be great to have this as a test case, too. |
Resolved the merge conflicts and added new conformances to the errors (they are user errors) |
Implemented the missing case for checking if type requirements have default special functions in b1ad20e |
@bluesign The first example case from my post above (field only exists in concrete type) already had a test case. The second example case (field exist, but is not Looks like everything is there now! 🎉 @SupunS could you please have a final look? I'll have a final look as well |
|
||
_, err := ParseAndCheck(t, ` | ||
struct interface IA { | ||
x: Int |
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.
oh, never knew defining a field without var/let is valid in 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.
LGTM! 👌
Added some minimal documentation |
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.
LGTM too. Thanks everyone!
Thank you so much everybody for your hard work! This is going to be a game changer in terms of composability #onFlow! |
Thanks a lot @turbolent, for explanation and all the work. I am really glad this feature finally will be out. |
This is so exciting! Great work everybody! 👏 |
Closes #989
Description
Add default implementation support to interface methods.
master
branchFiles changed
in the Github PR explorer