-
Notifications
You must be signed in to change notification settings - Fork 351
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
Cannot assign to variable in imported package #1623
Comments
This appears to've broken in v0.14.3. It works in v0.14.2. |
I don't know if this is the right fix, but it's a fix: % git diff interp
diff --git a/interp/cfg.go b/interp/cfg.go
index 39133a4c..c7a00eef 100644
--- a/interp/cfg.go
+++ b/interp/cfg.go
@@ -651,7 +651,7 @@ func (interp *Interpreter) cfg(root *node, sc *scope, importPath, pkgName string
var sym *symbol
var level int
- if dest.rval.IsValid() && isConstType(dest.typ) {
+ if dest.rval.IsValid() && !dest.rval.CanSet() && isConstType(dest.typ) {
err = n.cfgErrorf("cannot assign to %s (%s constant)", dest.rval, dest.typ.str)
break
} |
I confirm the issue and I think that your fix is the right solution. Well done! Feel free to submit a pull request with your proposed fix and test, so you can be properly credited. Thanks. |
Thanks, will do! |
If you (*interp.Interpreter).Use a variable, you should be able to assign to it. Fixes traefik#1623.
If you `(*interp.Interpreter).Use` a variable, you should be able to assign to it. Fixes #1623
Just a heads-up to any interested observers that this problem is not entirely fixed. I'm getting various weird panics in interpreted code when I do it. I'm still trying to nail down a test case. When I figure it out I'll open a new bug. The way to prevent the panic / allow the update is to either create the variable as a pointer to begin with // native Go
var V = new(float32)
// interpreted code where V has been imported via `interp.ImportUsed`.
*V += 5
math.Sin(*V) or do a // native Go
var V float32
// Interpreted code
*&V += 5
math.Sin(*&V) As a hint to the dev team, should you be interested in looking into this without a concrete reproducer, when I tried to update a struct I got
This might not actually be related to the problem, but I suspect that it is. |
If you `(*interp.Interpreter).Use` a variable, you should be able to assign to it. Fixes traefik#1623
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
3fbebb3
Additional Notes
In test-case form: add this to the end of interp/interp_eval_test.go:
The text was updated successfully, but these errors were encountered: