Giovanni S | Flow (2024-02-02)
What's the 1.0 syntax for casting a resource as an auth reference so I can downcast? e.g.
9 Replies
I've created a thread for your message. Please continue any relevant discussion in this thread.
You can rename this thread using
/title <new title>
If this is a technical question that others may benefit from, considering also asking it on Stackoverflow: https://stackoverflow.com/questions/ask?tags=onflow-cadencereferences now always be downcast to a subtype (with equal or fewer entitlements). the
auth
modifier is for entitlements now
in your example, what are A and B and what is there relationship? A is a resource, B is a resource interface, and A implements B?Sorry, updated the example
just remove the
auth
keyword
no entitlements involved, no auth
keyword needed
we can maybe provide a better error here, could you please open an issue for that?I cleared it up - I had to create an intermediary reference. Example for reference:
you mean there's still a problem/question?
I think
a.getType().isSubtype(of: Type<@{A}>())
is always true. Did you mean to check if you can cast to B
?No problem, just posting the pattern I arrived at in case others have a similar question now/in the future
Ah right :facepalm: brain's been a little foggy
no worries!
no need for run-time type-based type checking and then force-casting, when the type value is constant (
of: Type<@{B}>()
).
you can just use static types here and optional-binding (if let
) makes it concise:
Nice, much cleaner!