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

Incomplete symbol is not fixed up by importing a package #1388

Closed
firelizzard18 opened this issue Apr 17, 2022 · 0 comments · Fixed by #1389
Closed

Incomplete symbol is not fixed up by importing a package #1388

firelizzard18 opened this issue Apr 17, 2022 · 0 comments · Fixed by #1389

Comments

@firelizzard18
Copy link
Contributor

The following program sample.go triggers an unexpected result

func TestIssueX(t *testing.T) {
	i := interp.New(interp.Options{Env: []string{"foo=bar"}})
	err := i.Use(stdlib.Symbols)
	if err != nil {
		t.Fatal(err)
	}

	_, err = i.Eval(`x := errors.New("")`)
	if err == nil {
		t.Fatal("Expected an error")
	}

	_, err = i.Eval(`import "errors"`)
	if err != nil {
		t.Fatal(err)
	}

	_, err = i.Eval(`x := errors.New("")`)
	if err != nil {
		t.Fatal(err)
	}
}

Expected result

$ go test
=== RUN   TestIssueX
Hello
--- PASS: TestIssueX (0.00s)
PASS
ok      github.com/traefik/yaegi/interp 0.007s

Got

$ go test
=== RUN   TestIssueX
    /home/firelizzard/src/yaegi-fork/interp/interp_eval_test.go:1767: <nil>
--- FAIL: TestIssueX (0.00s)
FAIL
FAIL	github.com/traefik/yaegi/interp	0.007s

Yaegi Version

5665c9a

Additional Notes

No response

mvertes pushed a commit that referenced this issue Apr 26, 2022
When a package is imported, it creates a symbol with a name like "errors/_.go". If a statement such as x := errors.New(...) is executed before import "errors", it creates an incomplete type symbol with a name like "errors". Importing the package after the incomplete type symbol has been created does not fix the compile issue because the incomplete type still exists.

To fix this, this PR deletes the incomplete type symbol, if one exists.

Closes #1388.
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.

1 participant