#1718·yaegi

Type assertion with interface fails with "interface conversion: nil is not interface{}"

Author: tom93Created Apr 2, 2026Updated Apr 2, 2026

Update: The issue is with the conversion, not the type assertion; see comment.

The following program sample.go triggers an unexpected result

go
package main

func main() {
	x := 42
	y := interface{}(x)
	println(y != nil)
	println(y.(int) == 42)
	println(y.(interface{}) != nil)
}

Expected result

bash
$ go run ./sample.go
true
true
true

Got

bash
$ yaegi ./sample.go
true
true
sample.go:4:2: panic: main.main(...)
run: sample.go:8:10: interface conversion: nil is not interface{}
goroutine 1 [running]:
runtime/debug.Stack()
	/home/user/go1.26.1/src/runtime/debug/stack.go:26 +0x5e
github.com/traefik/yaegi/interp.(*Interpreter).Execute.func1()
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/interp/program.go:146 +0x79
panic({0xf341e0?, 0x202ee8228108?})
	/home/user/go1.26.1/src/runtime/panic.go:860 +0x13a
github.com/traefik/yaegi/interp.runCfg.func1()
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/interp/run.go:226 +0x1a5
panic({0xf341e0?, 0x202ee8228108?})
	/home/user/go1.26.1/src/runtime/panic.go:860 +0x13a
github.com/traefik/yaegi/interp.typeAssert.func1(0x202ee823a0b0)
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/interp/run.go:329 +0x4b4
github.com/traefik/yaegi/interp.runCfg(0x202ee81b0780, 0x202ee823a0b0, 0x4?, 0x0?)
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/interp/run.go:234 +0x265
github.com/traefik/yaegi/interp.(*Interpreter).run(0x202ee7df1448, 0x202ee81a1cc0, 0x202ee7dda210?)
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/interp/run.go:119 +0x36d
github.com/traefik/yaegi/interp.(*Interpreter).Execute(0x202ee7df1448, 0x202ee8219650)
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/interp/program.go:172 +0x225
github.com/traefik/yaegi/interp.(*Interpreter).eval(0x202ee7df1448, {0x202ee7dbb3b0?, 0x88?}, {0x7ffc2cf0490e?, 0x202ee8103b00?}, 0x90?)
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:563 +0x55
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0x202ee7df1448, {0x7ffc2cf0490e, 0x9})
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:512 +0xa6
main.runFile(0x202ee7df1448, {0x7ffc2cf0490e, 0x9}, 0x0)
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/cmd/yaegi/run.go:153 +0xd8
main.run({0x202ee7d3c150, 0x1, 0x1})
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/cmd/yaegi/run.go:116 +0x998
main.main()
	/home/user/go/pkg/mod/github.com/traefik/[email protected]/cmd/yaegi/yaegi.go:144 +0x2d7

Yaegi Version

v0.16.1 (yeagi version outputs "devel")

Additional Notes

Hi, this is a very cool and ambitious project, but please consider weakening the claim "Complete support of Go specification" in the feature list in the README.