Skip to content

Commit

Permalink
Improve test case
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdrag00nv2 committed Jul 19, 2023
1 parent 3960890 commit 4d42e5f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -2927,12 +2927,12 @@ func (v *ArrayValue) Reverse(
common.ZeroAddress,
uint64(count),
func() Value {
if idx < 0 {
if index < 0 {
return nil
}

value := v.Get(interpreter, locationRange, idx)
idx--
value := v.Get(interpreter, locationRange, index)
index--

return value.Transfer(
interpreter,
Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,7 @@ func ArraySliceFunctionType(elementType Type) *FunctionType {
}
}

func ArrayReverseFunctionType(arrayType sema.ArrayType) *FunctionType {
func ArrayReverseFunctionType(arrayType ArrayType) *FunctionType {
return &FunctionType{
Parameters: []Parameter{},
ReturnTypeAnnotation: NewTypeAnnotation(arrayType),
Expand Down
7 changes: 4 additions & 3 deletions runtime/tests/checker/arrays_dictionaries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,14 +1117,15 @@ func TestCheckResourceArrayReverseInvalid(t *testing.T) {
fun test(): @[X] {
let xs <- [<-create X()]
return <-xs.reverse()
let revxs <-xs.reverse()
destroy xs
return <- revxs
}
`)

errs := RequireCheckerErrors(t, err, 2)
errs := RequireCheckerErrors(t, err, 1)

assert.IsType(t, &sema.InvalidResourceArrayMemberError{}, errs[0])
assert.IsType(t, &sema.ResourceLossError{}, errs[1])
}

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

0 comments on commit 4d42e5f

Please sign in to comment.