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

Type Conversion Error When Comparing String with Constant Type #2944

Closed
omarsy opened this issue Oct 13, 2024 · 0 comments · Fixed by #2948
Closed

Type Conversion Error When Comparing String with Constant Type #2944

omarsy opened this issue Oct 13, 2024 · 0 comments · Fixed by #2948

Comments

@omarsy
Copy link
Member

omarsy commented Oct 13, 2024

Description

The following code snippet crashes in Gno instead of returning false:

package main

type Value struct {
	String string
}

type S string

const (
	s S = "hello"
	g   = "world"
)

func main() {
	v := Value{String: "hello"}
	b := v.String == g
	println(b)
}

Your environment

  • Go version: go1.22.4
  • OS and CPU architecture: linux/amd64

Steps to reproduce

Expected behaviour

The code should compile and return false

Actual behaviour

Instead of returning false, the code crashes with the following error:

cannot use string as main.S without explicit conversion:
...

Logs

runtime/debug.Stack()
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/debug/stack.go:24 +0x64
runtime/debug.PrintStack()
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/debug/stack.go:16 +0x1c
command-line-arguments.RunFileTest.func1.1()
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file.go:155 +0x1e0
panic({0x1031b5ba0?, 0x140003e26f0?})
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
github.com/gnolang/gno/gnovm/pkg/gnolang.Preprocess.func1.1()
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:442 +0x2a4
panic({0x103169580?, 0x140004cfe60?})
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
github.com/gnolang/gno/gnovm/pkg/gnolang.assertAssignableTo({0x103262950?, 0x103115650?}, {0x103262d60?, 0x14000032d20?}, 0x80?)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/type_check.go:214 +0x5c
github.com/gnolang/gno/gnovm/pkg/gnolang.(*BinaryExpr).AssertCompatible(0x14000368c80, {0x103262950, 0x103115650?}, {0x103262d60, 0x14000032d20?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/type_check.go:634 +0x474
github.com/gnolang/gno/gnovm/pkg/gnolang.Preprocess.func1({0x140003b6200, 0x3, 0x20}, 0x24, 0x0, {0x103264bf0, 0x14000368c80}, 0x3)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:1051 +0x1804
github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0x140003f96a0, {0x140003b6200, 0x3, 0x20}, 0x24, 0x0, {0x103264bf0, 0x14000368c80}, 0x140003f8e5f)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:737 +0x1930
github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0x140003f96a0, {0x140003b6200, 0x2, 0x20}, 0x46, 0x1, {0x103264a88, 0x14000032b40}, 0x140003f90df)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:372 +0x5fe4
github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0x140003f96a0, {0x140003b6200, 0x1, 0x20}, 0x4d, 0x5, {0x103265e38, 0x14000340c08}, 0x140003f935f)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:679 +0x72f0
github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0x140003f96a0, {0x140003b6200, 0x0, 0x20}, 0x0, 0x0, {0x103265fa0, 0x14000248908}, 0x140003f95d7)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:717 +0x2c6c
github.com/gnolang/gno/gnovm/pkg/gnolang.Transcribe({0x103265fa0, 0x14000248908}, 0x140003f96a0)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:133 +0xb4
github.com/gnolang/gno/gnovm/pkg/gnolang.Preprocess({0x103270928, 0x1400013c2c0}, {0x10326f458, 0x14000248308}, {0x103265fa0, 0x14000248908?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:416 +0x218
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).runFileDecls(0x14000362b48, {0x14000130b50, 0x1, 0x1})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:623 +0x254
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunFiles(0x14000362b48, {0x14000130b50?, 0x1400020e000?, 0xe0?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:570 +0x30
command-line-arguments.RunFileTest.func1(0x7?, 0x103259c38?, {0x0?, 0x0?}, 0x14000148e70, {0x102eeafd3, 0x4}, {0x102eeafd3, 0x4}, {0x103270928, ...}, ...)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file.go:172 +0x718
command-line-arguments.RunFileTest({0x140000106d0, 0x5}, {0x140004221c8, 0x11}, {0x14000314ff0, 0x4, 0x6?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file.go:247 +0x22c
command-line-arguments.runFileTest(0x140003e0340, {0x140004221c8, 0x11}, {0x1400036a860, 0x2, 0x102a1bbf8?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file_test.go:140 +0x1c8
command-line-arguments.runFileTests.func1(0x140003e0340?)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file_test.go:64 +0x38
testing.tRunner(0x140003e0340, 0x14000148e10)
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1689 +0xec
wyhaines pushed a commit that referenced this issue Mar 4, 2025
closes #2944 and #3863 
<!-- please provide a detailed description of the changes made in this
pull request. -->

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

- [ ] 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](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
Villaquiranm pushed a commit to Villaquiranm/gno that referenced this issue Mar 6, 2025
closes gnolang#2944 and gnolang#3863 
<!-- please provide a detailed description of the changes made in this
pull request. -->

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

- [ ] 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](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

1 participant