Skip to content

Commit

Permalink
Merge pull request #3317 from onflow/supun/reference-test
Browse files Browse the repository at this point in the history
Add test for untyped optional nested-reference creation
  • Loading branch information
SupunS authored May 6, 2024
2 parents dc8a27d + 83dbf30 commit 665d604
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions runtime/tests/interpreter/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,25 @@ func TestInterpretReferenceToReference(t *testing.T) {
RequireError(t, err)
require.ErrorAs(t, err, &interpreter.NestedReferenceError{})
})

t.Run("nested optional reference as AnyStruct", func(t *testing.T) {
t.Parallel()

inter := parseCheckAndInterpret(t, `
fun main() {
var array: [Foo] = []
var optionalArrayRef: (&[Foo])? = &array as &[Foo]
var anyStructValue = optionalArrayRef as AnyStruct
var ref = &anyStructValue as &AnyStruct
}
struct Foo {}
`)

_, err := inter.Invoke("main")
RequireError(t, err)
require.ErrorAs(t, err, &interpreter.NestedReferenceError{})
})
}

func TestInterpretDereference(t *testing.T) {
Expand Down

0 comments on commit 665d604

Please sign in to comment.