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:
+10
-5
@@ -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('"')
|
||||
|
||||
Reference in New Issue
Block a user