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

assign imported variable get type mismatch #1000

Closed
bitholic opened this issue Jan 12, 2021 · 1 comment · Fixed by #1020
Closed

assign imported variable get type mismatch #1000

bitholic opened this issue Jan 12, 2021 · 1 comment · Fixed by #1020
Assignees
Milestone

Comments

@bitholic
Copy link

bitholic commented Jan 12, 2021

The following program sample.go triggers a panic:

package main

import (
	"fmt"
	"reflect"

	"github.com/traefik/yaegi/interp"
	"github.com/traefik/yaegi/stdlib"
)

const expression = `test_val == 11"`

func main() {
	i := interp.New(interp.Options{})
	i.Use(stdlib.Symbols)
	i.Use(interp.Exports{
		"mytest": {
			"test_val": reflect.ValueOf(int64(11)),
		},
	})
	init := `
import "mytest"

var test_val = mytest.test_val
`
	_, err := i.Eval(init)
	if err != nil {
		panic(err)
	}
	v, err := i.Eval(expression)
	if err != nil {
		panic(err)
	}
	fmt.Println(v.Interface().(bool))
}

Expected result:

true

Got:

4:5: panic
panic: reflect.Set: value of type int64 is not assignable to type int
@easy-money-sniper
Copy link

It happens to me too...my go version is go1.14.2 darwin/amd64

@nrwiersma nrwiersma self-assigned this Jan 28, 2021
traefiker pushed a commit that referenced this issue Jan 28, 2021
When checking for untyped values, we can be sure at this stage that they must be a const value or already untyped. Checking for type string equality is no longer a good measure.

Fixes #1000
@traefiker traefiker added this to the v0.9.x milestone Jan 28, 2021
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

Successfully merging a pull request may close this issue.

4 participants