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

Dereferencing nil pointer behaves unexpectedly #69

Open
pigpigyyy opened this issue Jan 2, 2025 · 0 comments
Open

Dereferencing nil pointer behaves unexpectedly #69

pigpigyyy opened this issue Jan 2, 2025 · 0 comments

Comments

@pigpigyyy
Copy link
Contributor

Description:

When dereferencing a nil pointer, the behavior is inconsistent with expectations. Specifically, dereferencing a nil pointer for a field does not cause a runtime error and instead returns the zero value for a field.

Steps to Reproduce:

  1. Define a struct type with a field.
  2. Create a nil pointer to the struct.
  3. Attempt to access a field via the nil pointer.

Code example:

type MyStruct: struct{
  Value: int
}

func main {
  myStruct: *MyStruct // nil pointer
  println(myStruct.Value) // print 0
}

Expected Behavior:

The program should produce a runtime error indicating an invalid memory access, similar to the behavior in Go:

package main

import "fmt"

type MyStruct struct {
  Value int
}

func main() {
  var myStruct *MyStruct // nil pointer
  fmt.Println(myStruct.Value) // panic: runtime error: invalid memory address or nil pointer dereference
}

Environment:

  • Wa-lang Version: 0.19.0

Additional Notes:

This behavior could lead to silent errors in programs, making debugging challenging. Aligning this behavior with Go would enhance developer experience and reliability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant