-
Notifications
You must be signed in to change notification settings - Fork 387
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: handle untyped constant expressions in append() #1177
Conversation
This is a particular case of Go append builtin where the array type is inferred from the first argument. We detect using untyped nil as argument, then we convert it to the array type prior to proceeed further. It fixes further consistency checks and value generation. Fixes gnolang#1136.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1177 +/- ##
==========================================
- Coverage 56.08% 55.84% -0.24%
==========================================
Files 432 431 -1
Lines 65989 65768 -221
==========================================
- Hits 37007 36728 -279
- Misses 26094 26166 +72
+ Partials 2888 2874 -14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Seeing if I can make the fix even more generic and also handle any untyped constant value, as to fix also #1149. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, @piux2 can you make a complementary review, please?
Does that also fix the bug we had on gnochess #1170 ? Note that to reproduce it, you need to broadcast multiple tx, so the current test system in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👏
Issue #1136 and issue #1149 are rooted in different issues. Regarding #1136: For #1149: We will need to dig more and fix it at the root. |
I was surprised to find out you're right (because it seemed to me that this PR didn't special-case nil): package main
func main() {
var ints []int
ints = append(ints, nil, nil)
println(ints)
}
// Output: slice[(0 int),(0 int)] This executes, albeit incorrectly. However, this is actually a phenomenon caused by a root issue: we allow converting package main
func main() {
println(int(nil))
}
// Output: 0 I think the approach @mvertes has used is correct (given
This one, empirically, does not check out (for the last statement). Try this one, and playing out with changing it (from master):
It's append which is special in this case. |
For issue #1170, the root cause is located in realm.go, the underlying problem arises from the underlying array of the slice not being marked as "dirty" during the persistence of a realm object when that object is assigned to itself. I'm still evaluating the issue to identify an optimal solution. |
I think here is the right place to fix #1149 gno/gnovm/pkg/gnolang/types.go Line 1163 in ce258b1
and add following condition:
|
We will have further discussion and update the changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will dig further
Co-authored-by: Morgan <[email protected]>
This is done in ConverTo, so hopefully it works both at parsing and during execution, and for composite types. Some additional test cases have been added too.
@piux2 I examined and tried your suggestion to apply |
@piux2 |
LGTM |
@mvertes I've made a small commit to address the comment by Jae. Then I noticed a small chance for optimisation (re-using the result of If the changes look good to you, please merge. The code's been reviewed by Jae, if there are further changes requested they can be made in a separate PR :) |
@piux2 ping |
Jae reviewed and approved this. Agreed with Milos to merge it as it fixes a number of Gno issues. If you have further comments, feel free to open a new PR or issue
This is a particular case of Go append builtin where the array type is inferred from the first argument. We detect an untyped const passed as argument, then we convert it to the array type prior to proceed further. It fixes further consistency checks and value generation. Fixes gnolang#1136, fixes gnolang#1149, fixes gnolang#1341. <!-- please provide a detailed description of the changes made in this pull request. --> <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <[email protected]> Co-authored-by: Morgan <[email protected]>
This is a particular case of Go append builtin where the array type is inferred from the first argument. We detect an untyped const passed as argument, then we convert it to the array type prior to proceed further. It fixes further consistency checks and value generation.
Fixes #1136, fixes #1149, fixes #1341.
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description