Skip to content

Commit

Permalink
properly handle never type argument
Browse files Browse the repository at this point in the history
  • Loading branch information
dsainati1 committed Mar 28, 2024
1 parent d8f8309 commit cb8242d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions runtime/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ func TestRuntimeCapability_borrowAndCheck(t *testing.T) {
assert(!self.account.capabilities.exists(path))
}
access(all)
fun testNever() {
let path = /public/r
assert(self.account.capabilities.get<Never>(path) == nil)
assert(self.account.capabilities.exists(path))
}
access(all)
fun testSwap(): Int {
let ref = self.account.capabilities.get<&R>(/public/r)!.borrow()!
Expand Down Expand Up @@ -305,6 +312,11 @@ func TestRuntimeCapability_borrowAndCheck(t *testing.T) {
require.NoError(t, err)
})

t.Run("testNever", func(t *testing.T) {
_, err := invoke("testNever")
require.NoError(t, err)
})

t.Run("testSwap", func(t *testing.T) {

_, err := invoke("testSwap")
Expand Down
9 changes: 7 additions & 2 deletions runtime/stdlib/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3592,8 +3592,13 @@ func newAccountCapabilitiesGetFunction(

// Get borrow type type argument

typeParameterPair := invocation.TypeParameterTypes.Oldest()
wantedBorrowType, ok := typeParameterPair.Value.(*sema.ReferenceType)
typeParameterPairValue := invocation.TypeParameterTypes.Oldest().Value
// `Never` is never a supertype of any stored value
if typeParameterPairValue.Equal(sema.NeverType) {
return interpreter.Nil
}

wantedBorrowType, ok := typeParameterPairValue.(*sema.ReferenceType)
if !ok {
panic(errors.NewUnreachableError())
}
Expand Down

0 comments on commit cb8242d

Please sign in to comment.