Skip to content

Commit df588f5

Browse files
authored
Merge branch 'master' into fix/issue-817
2 parents 8eb3cf1 + 73384e1 commit df588f5

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

compiler/compiler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,9 @@ func (c *compiler) BuiltinNode(node *ast.BuiltinNode) {
11031103
if f.Fast != nil {
11041104
c.emit(OpCallBuiltin1, id)
11051105
} else if f.Safe != nil {
1106-
c.emit(OpPush, c.addConstant(f.Safe))
1106+
id := c.addConstant(f.Safe)
1107+
c.emit(OpPush, id)
1108+
c.debugInfo[fmt.Sprintf("const_%d", id)] = node.Name
11071109
c.emit(OpCallSafe, len(node.Arguments))
11081110
} else if f.Func != nil {
11091111
c.emitFunction(f, len(node.Arguments))

test/issues/567/issue_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package expr_test
2+
3+
import (
4+
"bytes"
5+
"strings"
6+
"testing"
7+
8+
"github.com/expr-lang/expr"
9+
"github.com/expr-lang/expr/internal/testify/require"
10+
)
11+
12+
func TestIssue567(t *testing.T) {
13+
program, err := expr.Compile("concat(1..2, 3..4)")
14+
require.NoError(t, err)
15+
16+
var buf bytes.Buffer
17+
program.DisassembleWriter(&buf)
18+
output := buf.String()
19+
20+
// Check if "concat" is mentioned in the output
21+
require.True(t, strings.Contains(output, "concat"), "expected 'concat' in disassembly output")
22+
23+
// It should appear as a pushed constant
24+
require.True(t, strings.Contains(output, "OpPush\t<4>\tconcat"), "expected 'OpPush <4> concat' in disassembly output")
25+
}

vm/program.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ func (program *Program) DisassembleWriter(w io.Writer) {
112112
} else {
113113
c = "out of range"
114114
}
115+
if name, ok := program.debugInfo[fmt.Sprintf("const_%d", arg)]; ok {
116+
c = name
117+
}
115118
if r, ok := c.(*regexp.Regexp); ok {
116119
c = r.String()
117120
}

0 commit comments

Comments
 (0)