Skip to content

Commit

Permalink
make it possible to return booleans from custom funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
eveld committed Oct 21, 2024
1 parent d4fedda commit 472adc8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func createCtyFunctionFromGoFunc(f interface{}) (function.Function, error) {
fallthrough
case reflect.Uint:
outParam = function.StaticReturnType(cty.Number)
case reflect.Bool:
outParam = function.StaticReturnType(cty.Bool)
default:
return function.Function{}, fmt.Errorf("type %v is not a valid cyt type, only primative types like string and basic numbers are supported", rf.Out(0).Kind())
}
Expand Down Expand Up @@ -130,6 +132,8 @@ func createCtyFunctionFromGoFunc(f interface{}) (function.Function, error) {
val, _ := bf.Float64()
in = append(in, reflect.ValueOf(float64(val)))
}
case cty.Bool:
in = append(in, reflect.ValueOf(a.True()))
}
}

Expand Down Expand Up @@ -177,6 +181,12 @@ func createCtyFunctionFromGoFunc(f interface{}) (function.Function, error) {
return cty.NumberFloatVal(out[0].Float()), out[1].Interface().(error)
}
}
case cty.Bool:
if out[1].Interface() == nil {
return cty.BoolVal(out[0].Bool()), nil
} else {
return cty.BoolVal(out[0].Bool()), out[1].Interface().(error)
}
}

return cty.NullVal(retType), nil
Expand Down

0 comments on commit 472adc8

Please sign in to comment.