Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item cast to struct does not ensure/convert field type #3610

Open
carpawell opened this issue Oct 11, 2024 · 0 comments
Open

Item cast to struct does not ensure/convert field type #3610

carpawell opened this issue Oct 11, 2024 · 0 comments
Labels
bug Something isn't working compiler Go smart contract compiler I4 No visible changes S4 Routine U3 Regular

Comments

@carpawell
Copy link
Member

Tried to cast item from contract's storage and use it.

Current Behavior

	newNodes := storage.Find(ctx, newNodesPrefix, storage.None)
	for iterator.Next(newNodes) {
		newNode := iterator.Value(newNodes).(struct {
			key []byte
			val []byte
		})

		newNode.key[0] = 1
	}

leads to SETITEM: invalid item type ByteString

newNode.key[:][0] = 1 solves the issue... why?

Expected Behavior

I said (asserted/converted) that it is a []byte, i want to use it as []byte.

Possible Solution

Ensure, cast or throw an exception at .() operator, not when it is tried to be used later.

Steps to Reproduce

Code from Current Behavior.

Context

nspcc-dev/neofs-contract#438 (comment)

Regression

Not sure.

Your Environment

github.com/nspcc-dev/neo-go v0.106.3

@carpawell carpawell added bug Something isn't working compiler Go smart contract compiler U2 Seriously planned labels Oct 11, 2024
@roman-khimov roman-khimov added U3 Regular S4 Routine I4 No visible changes and removed U2 Seriously planned labels Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Go smart contract compiler I4 No visible changes S4 Routine U3 Regular
Projects
None yet
Development

No branches or pull requests

2 participants