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

in append([]T, ...T), constant types are not converted to T implicitly #1149

Closed
thehowl opened this issue Sep 18, 2023 · 0 comments · Fixed by #1177
Closed

in append([]T, ...T), constant types are not converted to T implicitly #1149

thehowl opened this issue Sep 18, 2023 · 0 comments · Fixed by #1177
Assignees
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@thehowl
Copy link
Member

thehowl commented Sep 18, 2023

package main

func main() {
        const x = 118999
        y := 11
        p := []int{}
        p = append(p, x, y)
}
$ gno run a.gno
--- preprocess stack ---
stack 2: func main() { const x<VPBlock(1,0)> = (const (118999 <untyped> bigint)); y<VPBlock(1,1)> := (const (11 int)); p<VPBlock(1,2)> := [](const-type int){}; p<VPBlock(1,2)> = (const (
append func(x <X>{},args MaybeNativeType{...<X.Elem()>{}})(res <X>{})))(p<VPBlock(1,2)>, (const (118999 <untyped> bigint)), y<VPBlock(1,1)>) }
stack 1: file{ package main; func main() { const x<VPBlock(1,0)> = (const (118999 <untyped> bigint)); y<VPBlock(1,1)> := (const (11 int)); p<VPBlock(1,2)> := [](const-type int){}; p<VPBl
ock(1,2)> = (const (append func(x <X>{},args MaybeNativeType{...<X.Elem()>{}})(res <X>{})))(p<VPBlock(1,2)>, (const (118999 <untyped> bigint)), y<VPBlock(1,1)>) } }
stack 0: package(main)
------------------------
panic: incompatible varg types: expected <untyped> bigint, got int [recovered]
        panic: main/a.gno:7: incompatible varg types: expected <untyped> bigint, got int

In other words, you can't put a variable next to a constant when appending to a slice, because the constant is still considered in its untyped version.

@thehowl thehowl added 🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related labels Sep 18, 2023
@thehowl thehowl added this to the 🚀 main.gno.land (required) milestone Sep 18, 2023
@mvertes mvertes self-assigned this Sep 27, 2023
mvertes added a commit to mvertes/gno that referenced this issue Sep 27, 2023
gfanton pushed a commit to moul/gno that referenced this issue Jan 18, 2024
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: 🚀 Needed for Launch
Development

Successfully merging a pull request may close this issue.

2 participants