From 2c92a7c7abe6cb3c4aa883888ecafe17cf70e9b5 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 2 Apr 2024 19:18:03 +0200 Subject: [PATCH] fix: do not panic when assigning to _ (blank) var. Fix interp.isEmptyInterface to tolerate a nil type. Fixes #1619 --- .gitignore | 1 + _test/op10.go | 9 +++++++++ _test/op11.go | 10 ++++++++++ interp/type.go | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 _test/op10.go create mode 100644 _test/op11.go diff --git a/.gitignore b/.gitignore index 3a5347a17..1c088b819 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .*.swo .*.swp *.dot +*.out .idea/ /yaegi internal/cmd/extract/extract diff --git a/_test/op10.go b/_test/op10.go new file mode 100644 index 000000000..5db580944 --- /dev/null +++ b/_test/op10.go @@ -0,0 +1,9 @@ +package main + +func main() { + _ = 1 + 1 + println("ok") +} + +// Output: +// ok diff --git a/_test/op11.go b/_test/op11.go new file mode 100644 index 000000000..ab2ecfa3a --- /dev/null +++ b/_test/op11.go @@ -0,0 +1,10 @@ +package main + +func main() { + a, b := 1, 2 + _ = a + b + println("ok") +} + +// Output: +// ok diff --git a/interp/type.go b/interp/type.go index 2e7c1ffc5..b3220455b 100644 --- a/interp/type.go +++ b/interp/type.go @@ -2393,7 +2393,7 @@ func isMap(t *itype) bool { return t.TypeOf().Kind() == reflect.Map } func isPtr(t *itype) bool { return t.TypeOf().Kind() == reflect.Ptr } func isEmptyInterface(t *itype) bool { - return t.cat == interfaceT && len(t.field) == 0 + return t != nil && t.cat == interfaceT && len(t.field) == 0 } func isGeneric(t *itype) bool {