Skip to content

run: runtime error: invalid memory address or nil pointer dereference #1466

@michaelboke

Description

@michaelboke

The following program sample.go triggers an unexpected result

package main

import (
	"fmt"
)

func SomeFunc(defaultValue interface{}) interface{} {
	switch v := defaultValue.(type) {
	case string:
		return v + " abc"
	case int:
		return v - 234
	}
	panic("whoops")
}

func main() {
	fmt.Println(SomeFunc("test"))
	fmt.Println(SomeFunc(1234))
}

Expected result

go run main.go
test abc
1000

Got

yaegi main.go
main.go:8:2: panic
main.go:18:2: panic
run: runtime error: invalid memory address or nil pointer dereference

Yaegi Version

0.14.2

Additional Notes

panics when appending the string

return v + " abc"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions