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

Panic on Type Assertion with Interface #2636

Closed
omarsy opened this issue Jul 27, 2024 · 2 comments · Fixed by #2647
Closed

Panic on Type Assertion with Interface #2636

omarsy opened this issue Jul 27, 2024 · 2 comments · Fixed by #2647
Assignees

Comments

@omarsy
Copy link
Member

omarsy commented Jul 27, 2024

Description:

Issue Summary:

A panic occurs when performing a type assertion on an interface{} in Gnolang. The following code works as expected in Go (Golang), but in Gnolang, it results in a runtime panic:

package main

import "fmt"

func main() {
	var i interface{} = 1
	var a, ok = i.(int)
	fmt.Println(a, ok)
}

Expected Behavior:

The code should execute without panic, correctly performing the type assertion. The expected output should be:

1 true

Actual Behavior:

In Gnolang, running the above code causes a panic with the message:

panic: interface conversion: gnolang.Expr is *gnolang.TypeAssertExpr, not *gnolang.CallExpr

This suggests an issue with how type assertions are being handled internally, specifically when converting types within the interface.

@omarsy omarsy changed the title Panic on Type Assertion with Interface in Gnolang Panic on Type Assertion with Interface Jul 27, 2024
@thehowl
Copy link
Member

thehowl commented Jul 27, 2024

yes; we should unify the code for DeclStmt and AssignStmt (ie. := and var x =); as they are supposed to be almost equivalent in the go spec but they do very different things in preprocess

@omarsy
Copy link
Member Author

omarsy commented Jul 27, 2024

Yes, I think too. I don't know why we didn't do that.

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.

3 participants