You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a reference to an object stored in a dictionary using as?, the checker does not report a static error when trying to access a field of the optional reference.
Steps to Reproduce
Copy this contract
pub contract TestCollection {
pub resource IDRes {
pub let id: UInt32
init() {
self.id = 0
}
}
pub resource Collection {
access(self) var idResources: @{String: IDRes}
init() {
self.idResources <- {}
}
destroy() {
destroy self.idResources
}
pub fun borrowID(_ key: String, _ id: UInt32): UInt32 {
let idref = &self.idResources[key] as? &IDRes
let id = idref.id
return id
}
}
init() {
let col <- create Collection()
let del = col.borrowID("hello", 1)
destroy col
}
}
Deploy the contract and see this error:
WARN[0004] ERR [08e509] Execution failed:
error: dereference failed
--> 01cf0e2f2f715450.TestCollection:23:21
|
23 | let id = idref.id
Acceptance Criteria
It should cause a static error because it is trying to access the field of an optional, right?
The text was updated successfully, but these errors were encountered:
joshuahannan
changed the title
Should not be able to statically access the fields of a optionally casted reference
BUG: Should not be able to statically access the fields of a optionally casted reference
Mar 31, 2021
Or maybe I am misinterpreting what the result of the cast should be if the key doesn't exist in the dictionary. It seems like it should be nil, but it looks like it is still giving me an &IDRes even though it doesn't point to anything. I get the same thing when doing a force cast also.
Problem
When creating a reference to an object stored in a dictionary using
as?
, the checker does not report a static error when trying to access a field of the optional reference.Steps to Reproduce
Acceptance Criteria
It should cause a static error because it is trying to access the field of an optional, right?
The text was updated successfully, but these errors were encountered: