Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,9 @@ func (c *compiler) BuiltinNode(node *ast.BuiltinNode) {
if f.Fast != nil {
c.emit(OpCallBuiltin1, id)
} else if f.Safe != nil {
c.emit(OpPush, c.addConstant(f.Safe))
id := c.addConstant(f.Safe)
c.emit(OpPush, id)
c.debugInfo[fmt.Sprintf("const_%d", id)] = node.Name
c.emit(OpCallSafe, len(node.Arguments))
} else if f.Func != nil {
c.emitFunction(f, len(node.Arguments))
Expand Down
25 changes: 25 additions & 0 deletions test/issues/567/issue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package expr_test

import (
"bytes"
"strings"
"testing"

"github.com/expr-lang/expr"
"github.com/expr-lang/expr/internal/testify/require"
)

func TestIssue567(t *testing.T) {
program, err := expr.Compile("concat(1..2, 3..4)")
require.NoError(t, err)

var buf bytes.Buffer
program.DisassembleWriter(&buf)
output := buf.String()

// Check if "concat" is mentioned in the output
require.True(t, strings.Contains(output, "concat"), "expected 'concat' in disassembly output")

// It should appear as a pushed constant
require.True(t, strings.Contains(output, "OpPush\t<4>\tconcat"), "expected 'OpPush <4> concat' in disassembly output")
}
3 changes: 3 additions & 0 deletions vm/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func (program *Program) DisassembleWriter(w io.Writer) {
} else {
c = "out of range"
}
if name, ok := program.debugInfo[fmt.Sprintf("const_%d", arg)]; ok {
c = name
}
if r, ok := c.(*regexp.Regexp); ok {
c = r.String()
}
Expand Down
Loading