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

fix(gnolang): fix panic when using struct as index of map #2044

Merged
merged 5 commits into from
May 9, 2024

Conversation

omarsy
Copy link
Contributor

@omarsy omarsy commented May 6, 2024

Closes #2041. Use fieldlist to get field type

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label May 6, 2024
@omarsy omarsy changed the title fix(#2041):cannot use struct as key of a map fix:cannot use struct as key of a map May 6, 2024
@omarsy omarsy changed the title fix:cannot use struct as key of a map fix: cannot use struct as key of a map May 6, 2024
Copy link

codecov bot commented May 6, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 54.96%. Comparing base (5a96926) to head (0bfc634).

Files Patch % Lines
gnovm/pkg/gnolang/values.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2044      +/-   ##
==========================================
- Coverage   54.96%   54.96%   -0.01%     
==========================================
  Files         481      481              
  Lines       67391    67390       -1     
==========================================
- Hits        37043    37040       -3     
  Misses      27329    27329              
- Partials     3019     3021       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@deelawn deelawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @omarsy 🎉. This looks like the right place for the fix. Is it necessary to declare the new bzl slice or could this be solved by referencing field's type directly?

@omarsy
Copy link
Contributor Author

omarsy commented May 7, 2024

Thanks @omarsy 🎉. This looks like the right place for the fix. Is it necessary to declare the new bzl slice or could this be solved by referencing field's type directly?

Thank you for your review @deelawn
Something like that ?

bz = append(bz, '{')
for i := 0; i < sl; i++ {
	fv := fillValueTV(store, &sv.Fields[i])
	omitTypes := FieldTypeList(bt.Fields).Types()[i].Kind() != InterfaceKind
	bz = append(bz, fv.ComputeMapKey(store, omitTypes)...)
	if i != sl-1 {
		bz = append(bz, ',')
	}
}

I use a variable for optimisation stuff, .Types() have a loop

@deelawn
Copy link
Contributor

deelawn commented May 7, 2024

Thanks @omarsy 🎉. This looks like the right place for the fix. Is it necessary to declare the new bzl slice or could this be solved by referencing field's type directly?

Thank you for your review @deelawn Something like that ?

bz = append(bz, '{')
for i := 0; i < sl; i++ {
	fv := fillValueTV(store, &sv.Fields[i])
	omitTypes := FieldTypeList(bt.Fields).Types()[i].Kind() != InterfaceKind
	bz = append(bz, fv.ComputeMapKey(store, omitTypes)...)
	if i != sl-1 {
		bz = append(bz, ',')
	}
}

I use a variable for optimisation stuff, .Types() have a loop

Would it be the same as using omitTypes := bt.Fields[i].Type.Kind() != InterfaceKind? If so, then no need to allocate a new slice for this operation.

@omarsy
Copy link
Contributor Author

omarsy commented May 7, 2024

Thanks @omarsy 🎉. This looks like the right place for the fix. Is it necessary to declare the new bzl slice or could this be solved by referencing field's type directly?

Thank you for your review @deelawn Something like that ?

bz = append(bz, '{')
for i := 0; i < sl; i++ {
	fv := fillValueTV(store, &sv.Fields[i])
	omitTypes := FieldTypeList(bt.Fields).Types()[i].Kind() != InterfaceKind
	bz = append(bz, fv.ComputeMapKey(store, omitTypes)...)
	if i != sl-1 {
		bz = append(bz, ',')
	}
}

I use a variable for optimisation stuff, .Types() have a loop

Would it be the same as using omitTypes := bt.Fields[i].Type.Kind() != InterfaceKind? If so, then no need to allocate a new slice for this operation.

My mistake, it's actually the same, no need for a new variable. Your suggestion is better.
Completed here: 0323970

@thehowl thehowl changed the title fix: cannot use struct as key of a map fix(gnolang): fix panic when using struct as index of map May 9, 2024
@thehowl thehowl merged commit 711f4d0 into gnolang:master May 9, 2024
219 of 222 checks passed
@thehowl thehowl added this to the 🏗4️⃣ test4.gno.land milestone May 9, 2024
@omarsy omarsy deleted the fix/2041 branch May 9, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

cannot use non-empty(comparable) struct as key of a map
3 participants