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: reflect.Value.Convert: value of type error cannot be converted to type #1609

Open
iyear opened this issue Feb 15, 2024 · 0 comments
Open

Comments

@iyear
Copy link

iyear commented Feb 15, 2024

The following program sample.go triggers an unexpected result

package main

type Err struct {
	err string
}

func (e Err) Error() string {
	return e.err
}

func main() {
	var E = Err{"error"}
	var err error = E

	switch err {
	case nil:
	case E:
	}
}

Expected result

No output, but running normally

Got

e.go:12:10: panic
run: reflect.Value.Convert: value of type error cannot be converted to type struct { Xerr string }
goroutine 1 [running]:
runtime/debug.Stack()
        .../runtime/debug/stack.go:24 +0x5e
github.com/traefik/yaegi/interp.(*Interpreter).Execute.func1()
        .../github.com/traefik/yaegi@v0.15.1/interp/program.go:146 +0x7e
panic({0xfdea20?, 0xc000043f10?})
        .../runtime/panic.go:914 +0x21f
github.com/traefik/yaegi/interp.runCfg.func1()
        .../github.com/traefik/yaegi@v0.15.1/interp/run.go:205 +0x185
panic({0xfdea20?, 0xc000043f10?})
        .../runtime/panic.go:914 +0x21f
reflect.Value.Convert({0x1038aa0?, 0xc000043e90?, 0xc00008aa80?}, {0x12e6108, 0xc00008aa80})
        .../reflect/value.go:3319 +0x12c
github.com/traefik/yaegi/interp._case.func7(0xc0000ca630?)
        .../github.com/traefik/yaegi@v0.15.1/interp/run.go:3115 +0x1b7
github.com/traefik/yaegi/interp.runCfg(0xc000331b80, 0xc0000ca630, 0x4?, 0x0?)
        .../github.com/traefik/yaegi@v0.15.1/interp/run.go:213 +0x285
github.com/traefik/yaegi/interp.(*Interpreter).run(0xc0000dd440, 0xc000330dc0, 0xc0000ca420?)
        .../github.com/traefik/yaegi@v0.15.1/interp/run.go:119 +0x3c5
github.com/traefik/yaegi/interp.(*Interpreter).Execute(0xc0000dd440, 0xc000334930)
        .../github.com/traefik/yaegi@v0.15.1/interp/program.go:172 +0x225
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0000dd440, {0xc000210840?, 0xbd?}, {0xc00000a0d0?, 0x200?}, 0xc0?)
        .../github.com/traefik/yaegi@v0.15.1/interp/interp.go:565 +0x55
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc0000dd440, {0xc00000a0d0, 0x4})
        .../github.com/traefik/yaegi@v0.15.1/interp/interp.go:514 +0xa6
main.runFile(0xc00000a0d0?, {0xc00000a0d0, 0x4}, 0x0)
        .../github.com/traefik/yaegi@v0.15.1/cmd/yaegi/run.go:153 +0xd7
main.run({0xc0000880a0?, 0x1, 0x2})
        .../github.com/traefik/yaegi@v0.15.1/cmd/yaegi/run.go:116 +0xb97
main.main()
        .../github.com/traefik/yaegi@v0.15.1/cmd/yaegi/yaegi.go:133 +0xca

Yaegi Version

v0.15.1

Additional Notes

No response

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