Skip to content

Commit af6d78c

Browse files
committed
[repl] [bugfix] "var a string" returns *interface{}
This is odd. Yaegi returns last evaluated expression to the user, which is a pointer to an empty interface. But it supposed to be a string. This commit fixes the issue (hopefully).
1 parent 9462bf9 commit af6d78c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

devtools/internal/interpreter/interpreter.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,7 @@ func (i Instance) runGoCode(source string) (r EvalResult, e error) {
233233
// if source is a statement or an expression. If source is a statement and previously source was an expression
234234
// then Yaegi returns the same result again. That's why following code overrides last computed result to the value
235235
// used as a discriminator for no result.
236-
_, err := i.yaegi.Eval("interpreter.noResult{}")
237-
if err != nil {
238-
return GoCodeExecuted, fmt.Errorf("yaegi Eval failed: %w", err)
239-
}
236+
source = "interpreter.noResult{}; " + source
240237

241238
res, err := i.yaegi.Eval(source)
242239
if err != nil {

devtools/internal/interpreter/interpreter_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func TestEval(t *testing.T) {
3232
code: "pi.Spr(0,0,0)",
3333
expectedResult: interpreter.GoCodeExecuted,
3434
},
35+
"var declaration": {
36+
code: "var a string",
37+
expectedOutput: "string: \n",
38+
expectedResult: interpreter.GoCodeExecuted,
39+
},
3540
"expression returning a struct": {
3641
code: "struct{}{}",
3742
expectedOutput: "struct {}: {}\n",

0 commit comments

Comments
 (0)