Skip to content

Eval panics which is not documented #1690

@pjebs

Description

@pjebs

The following program sample.go triggers an unexpected result

package main

import (
	"fmt"
	"github.com/traefik/yaegi/interp"
	"github.com/traefik/yaegi/stdlib"
)

func main() {
	i := interp.New(interp.Options{})
	i.Use(stdlib.Symbols)

	_ , err := i.Eval(`import "fmt"`)
	if err != nil {
		fmt.Println(err)
	}
	_ , err = i.Eval(`import dataframe "github.com/rocketlaunchr/dataframe-go"`)
	if err != nil {
		fmt.Println(err)
	}
	_ , err = i.Eval(`func X(args ...any) []string {
			typs := []string{}
			for _, v := range args {
				typs = append(typs, fmt.Sprintf("%T", v))
			}
			return typs
		}`)
	if err != nil {
		fmt.Println(err)
	}

	_, err = i.Eval(`var s1 *dataframe.SeriesInt64  = dataframe.NewSeriesInt64("day",nil,1,2,3,4,5,6,7,8)`) <======= PANICS HERE
	if err != nil {
		fmt.Println("err:", err.Error())
	}
	

	v, err := i.Eval("X(GlobalVar)")
	if err != nil {
		panic(err)
	}

	fmt.Println(v.Interface().([]string))

}

Expected result

No panic. Perhaps an error because the `import dataframe "github.com/rocketlaunchr/dataframe-go"` is not loaded.

eg. import "github.com/rocketlaunchr/dataframe-go" error: unable to find source related to: "github.com/rocketlaunchr/dataframe-go". Either the GOPATH environment variable, or the Interpreter.Options.GoPath needs to be set

Got

Panic:
runtime error: invalid memory address or nil pointer dereference

Yaegi Version

v0.16.1

Additional Notes

i.Eval is not documented to panic.
It does panic when it should return an error saying that dataframe is not recognised.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions