-
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
Enums defined in a contract interface are unusable when imported #2116
Comments
Nested types (structs, resources, enums) defined in interfaces are only "type requirements", but not concrete type definitions: (see: https://developers.flow.com/cadence/language/interfaces#nested-type-requirements). i.e: They only mandate the interface implementations to also implement the type. Moreover, since they are not concrete type definitions: they cannot be used to create a value or used as a value (enum cases are values). This can be somewhat confusing. Because of the same reason, there is a proposal to remove this "type requirement" feature: #1283. |
This works as expected, so closing. @NtTestAlert let us know if you have any questions regarding this! |
Oh, ok. The type requirement is not enforced though:
(This deploys fine with the above interface) IMO if possible the abstract type should not be allowed to be used in var declarations/typing, to reduce confusion. I assume the behavior that I was trying to achieve (allow common enum type for integration with custom contracts implementing an interface) will be added along with |
Type requirements are enforced only if a contract conforms to a contract interface. pub contract TestContract: Iface {
...
} |
Once you add the conformance like above, the enum Then you can do the assignment like: pub fun test() {
self.canUseType = TestEnum.Initialized
} Note that, if you want to compare, then you'll first need to downcast it to the intended type: return (self.canUseType! as! TestEnum) == TestEnum.Initialized |
Ok, thank you :) (indeed forgot to put the conformance in this test case, sorry) |
Tested on newest emulator
Problem
Enums defined in a contract interface are unusable in implementing contract
Steps to Reproduce
// TestContract.cdc
The text was updated successfully, but these errors were encountered: