Skip to content

Commit

Permalink
restore object info copy functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
deelawn committed Jan 8, 2024
1 parent bb9fb88 commit d03eec7
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty

// TODO: Should this check that tv2 type is not a reference?
if _, ok := pv.TV.V.(RefValue); ok {
*pv.TV = pv.TV.DeepCopySetRefObjectInfo(alloc, store)
*pv.TV = pv.TV.unrefCopySetRefObjectInfo(alloc, store)
}

Check warning on line 288 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L287-L288

Added lines #L287 - L288 were not covered by tests

// We need the owner to know which parent object to mark as dirty.
Expand Down Expand Up @@ -1057,16 +1057,32 @@ func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) {

// unrefCopy makes a copy of the underlying value in the case of reference values.
// It copies other values as expected using the normal Copy method.
func (tv TypedValue) unrefCopy(alloc *Allocator, store Store) (cp TypedValue) {
func (tv TypedValue) unrefCopy(alloc *Allocator, store Store) TypedValue {
return tv.unrefCopyCore(alloc, store, false)
}

func (tv TypedValue) unrefCopySetRefObjectInfo(alloc *Allocator, store Store) TypedValue {
return tv.unrefCopyCore(alloc, store, true)

Check warning on line 1065 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L1064-L1065

Added lines #L1064 - L1065 were not covered by tests
}

func (tv TypedValue) unrefCopyCore(alloc *Allocator, store Store, setRefObjectInfo bool) (cp TypedValue) {
switch tv.V.(type) {
case RefValue:
cp.T = tv.T
refObject := tv.GetFirstObject(store)
switch refObjectValue := refObject.(type) {
case *ArrayValue:
cp.V = refObjectValue.Copy(alloc)
arrayValue := refObjectValue.Copy(alloc)
if setRefObjectInfo {
arrayValue.ObjectInfo = *refObject.GetObjectInfo()
}
cp.V = arrayValue

Check warning on line 1079 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L1075-L1079

Added lines #L1075 - L1079 were not covered by tests
case *StructValue:
cp.V = refObjectValue.Copy(alloc)
structValue := refObjectValue.Copy(alloc)
if setRefObjectInfo {
structValue.ObjectInfo = *refObject.GetObjectInfo()
}
cp.V = structValue

Check warning on line 1085 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L1081-L1085

Added lines #L1081 - L1085 were not covered by tests
default:
cp = tv
}
Expand Down

0 comments on commit d03eec7

Please sign in to comment.