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

[GnoVM] - Cannot use pointer of an array as parameters of len & cap function #2707

Closed
MikaelVallenet opened this issue Aug 17, 2024 · 3 comments · Fixed by #2709
Closed

[GnoVM] - Cannot use pointer of an array as parameters of len & cap function #2707

MikaelVallenet opened this issue Aug 17, 2024 · 3 comments · Fixed by #2709
Labels
🐞 bug Something isn't working

Comments

@MikaelVallenet
Copy link
Contributor

MikaelVallenet commented Aug 17, 2024

Cannot use pointer of an array as parameters of len & cap function

Description

While I was working on implementing a value check for constants following this documentation, I realized that this code, which works in Go 1.17, doesn't work in Gno.

package main

func main() {
	exp := [...]string{"HELLO"}
	x := len(&exp)
	println(x)
}

Now, I don't know if this is intentional behavior, but if it is, I'd be delighted to have the justification and i will close the issue then. If not, it might be worth fixing to improve Go to Gno process.

Trace

panic running expression main(): unexpected type for len(): *[1]string
Machine State:Machine:
    CheckTypes: false
    Op: [OpHalt OpExec OpBody OpDefine OpReturn]
    Values: (len: 2)
          #1 (len func(x interface{})( int))
          #0 (main func()())
    Exprs:
    Stmts:
          #1 bodyStmt[0/0/2]=(const (println func(xs ...interface{})()))(x<VPBlock(1,1)>)*
          #0 return
    Blocks:
          @(107) Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc00041e000,Source:func len(x interface {  })  int<...,Parent:0x0)
            x: (&(array[("HELLO" string)] [1]string) *[1]string)
            .res_0: (undefined)
 (s vals) @(107) Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc0003bf030,Source:func len(x interface {  })  int<...,Parent:0xc0002fd530)
            x: (undefined)
            .res_0: (0 int)
 (s typs) @(107) [interface{} int]
    Blocks (other):
          #1 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc0002fbc20,Source:func main() { exp<VPBlock(1,0)> ...,Parent:0xc0002fb860)
            exp: (array[("HELLO" string)] [1]string)
            x: (undefined)
 (static) #1 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc0003f0c30,Source:func main() { exp<VPBlock(1,0)> ...,Parent:0xc0002fdb30)
            exp: (nil [1]string)
            x: (0 int)
    Frames:
          #1 [FRAME FUNC:len RECV:(undefined) (1 args) 4/1/0/2/2 LASTPKG:main LASTRLM:Realm(nil)]
          #0 [FRAME FUNC:main RECV:(undefined) (0 args) 1/0/0/0/1 LASTPKG:main LASTRLM:Realm(nil)]
    Exceptions:

Stacktrace: func(x interface{})( int)(&exp<VPBlock(1,0)>)
    .uverse/:5
main<VPBlock(1,0)>()
    main/const.gno:5

Your environment

  • Go version (go1.17)

P.S: I also think it's a first good issue and i will see to fix it after i finish with const verification if no one fixed it before.

@leohhhn
Copy link
Contributor

leohhhn commented Aug 17, 2024

cc @deelawn @petar-dambovaliev

@notJoon
Copy link
Member

notJoon commented Aug 19, 2024

Currently, the GetLength method does not handle the PointerValue type in TypedValue internally. It seemes the main cause of the problem.

https://github.com/gnolang/gno/blob/master/gnovm/pkg/gnolang/values.go#L2123-L2156

@zivkovicmilos zivkovicmilos added 🐞 bug Something isn't working 🌟 must have 🌟 labels Sep 11, 2024
thehowl added a commit that referenced this issue Sep 13, 2024
# Description

closes #2707

The `GetLength()`, `GetCapacity()` method in `TypedValue` has been
updated to handle pointer type.

<details><summary>Contributors' checklist...</summary>

- [x] 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
- [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 Bazalgette <[email protected]>
@linear linear bot reopened this Nov 1, 2024
@thehowl
Copy link
Member

thehowl commented Nov 6, 2024

Linear re-opened this, but it's incorrect.

@thehowl thehowl closed this as completed Nov 6, 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
Development

Successfully merging a pull request may close this issue.

5 participants