IsOptional() function of ExprFuncParam renamed as IdDefault(). A new IsOptional() function created to check if a param is optional without requiring a default value

This commit is contained in:
2024-06-07 09:45:02 +02:00
parent 227944b3fb
commit 115ce26ce9
12 changed files with 44 additions and 25 deletions
+10 -5
View File
@@ -91,7 +91,7 @@ func (functor *exprFunctor) Invoke(ctx ExprContext, name string, args []any) (re
ctx.UnsafeSetVar(p.Name(), nil)
}
}
result, err = functor.expr.eval(ctx, false)
result, err = functor.expr.Eval(ctx)
return
}
@@ -99,7 +99,8 @@ func (functor *exprFunctor) Invoke(ctx ExprContext, name string, args []any) (re
type paramFlags uint16
const (
PfOptional paramFlags = 1 << iota
PfDefault paramFlags = 1 << iota
PfOptional
PfRepeat
)
@@ -126,7 +127,11 @@ func (param *funcParamInfo) Name() string {
}
func (param *funcParamInfo) Type() string {
return "any"
return TypeAny
}
func (param *funcParamInfo) IsDefault() bool {
return (param.flags & PfDefault) != 0
}
func (param *funcParamInfo) IsOptional() bool {
@@ -159,7 +164,7 @@ func newFuncInfo(name string, functor Functor, returnType string, params []ExprF
if maxArgs == -1 {
return nil, fmt.Errorf("no more params can be specified after the ellipsis symbol: %q", p.Name())
}
if p.IsOptional() {
if p.IsDefault() || p.IsOptional() {
maxArgs++
} else if maxArgs == minArgs {
minArgs++
@@ -207,7 +212,7 @@ func (info *funcInfo) ToString(opt FmtOpt) string {
}
sb.WriteString(p.Name())
if p.IsOptional() {
if p.IsDefault() {
sb.WriteByte('=')
if s, ok := p.DefaultValue().(string); ok {
sb.WriteByte('"')