Skip to content

Changing the sublice does not change the original slice #4012

@Turalchik

Description

@Turalchik
func TestSlice(t *testing.T) {
	src := `package foo
	func Main() byte {
		a := make([]byte, 2)
		b := a[:1]
		b[0] = 42
		return a[0]
	}
	`
	eval(t, src, big.NewInt(42))
}

Current Behavior

Test returns 0.

Expected Behavior

Test should return 42.

Possible Solution

Perhaps you don't need to create a copy of the original slice when creating a subslice.

Steps to Reproduce

Run the test above.

Your Environment

v0.112.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    I4No visible changesS4RoutineU3RegularbugSomething isn't workingcompilerGo smart contract compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions