Skip to content

When I change the signature of the function, it still works normally #891

@yikakia

Description

@yikakia

Here`s the demo:
https://go.dev/play/p/3nmVM4gi7AZ

package main

import (
	"fmt"
	"time"

	"github.com/expr-lang/expr"
)

func main() {
	env := map[string]any{
		// no error return
		"foo": func(string, ...string) time.Time { return time.Time{} },
		"str": "",
	}
	prog, err := expr.Compile(`foo(str)`, expr.Env(env))
	if err != nil {
		panic(err)
	}
	// define changed
	env["foo"] = func(s string, layout ...string) (time.Time, error) {
		fmt.Println("called")
		return time.Now(), nil
	}
	_, err = expr.Run(prog, env)
	if err == nil {
		panic(fmt.Sprintf("expected error for change the function signature.but no error return."))
	}
}

If the signature of the foo function is inconsistent with the compile-time version, can it still execute normally? Is this expected behavior or a bug?

Raw Chinese: 如果 foo 函数的签名与编译时不一致,依然能够正常执行。这是预期内的么?还是一个 Bug ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions