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

type conversion and assignment bug #1543

Closed
hesining opened this issue Apr 19, 2023 · 1 comment · Fixed by #1546
Closed

type conversion and assignment bug #1543

hesining opened this issue Apr 19, 2023 · 1 comment · Fixed by #1546
Labels
area/core bug Something isn't working

Comments

@hesining
Copy link

The following program sample.go triggers an unexpected result

package main

import (
	"github.com/traefik/yaegi/interp"
	"log"
)

// Generic example.
func main() {
	// Create a new interpreter context
	i := interp.New(interp.Options{})

	// Run some code: define a new function
	_, err := i.Eval("var cc interface{}")
	if err != nil {
		log.Fatal(err)
	}

	// Access the interpreted f function with Eval
	_, err = i.Eval("cc = 1")
	if err != nil {
		log.Fatal(err)
	}

	_, err = i.Eval("dd := cc.(int)")
	if err != nil {
		log.Fatal(err)
	}
}

Expected result

nothing

Got

1:34: type definition not implemented: typeAssertExpr

Yaegi Version

v0.15.1

Additional Notes

Is the problem caused by type conversion and assignment at the same time ?

@mvertes mvertes added area/REPL area/debug bug Something isn't working and removed area/debug labels Apr 20, 2023
@mvertes
Copy link
Member

mvertes commented Apr 20, 2023

Th same program in a script sample.go works ok:

package main

func main() {
    var cc interface{}
    cc = 1
    dd := cc.(int)
    println(dd)
}
$ yaegi ./sample.go
1

The difference is that Eval() is called multiple times in your case instead of one.

mvertes added a commit to mvertes/yaegi that referenced this issue Apr 20, 2023
traefiker pushed a commit that referenced this issue Apr 26, 2023
Add the support of type assert expressions in type parsing
which allows to process type assertions in the global scope.

Fixes #1543.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants