zeroValueExpr creates an expression representing the empty or zero value for the given type Note: bytes, lists, maps, and strings are supported via the `SizerType` trait.
(ctx *OptimizerContext, t *Type)
| 190 | // zeroValueExpr creates an expression representing the empty or zero value for the given type |
| 191 | // Note: bytes, lists, maps, and strings are supported via the `SizerType` trait. |
| 192 | func zeroValueExpr(ctx *OptimizerContext, t *Type) (ast.Expr, bool) { |
| 193 | // Note: bytes, strings, lists, and maps are covered by the "sizer-type" check |
| 194 | switch t.Kind() { |
| 195 | case types.BoolKind: |
| 196 | return ctx.NewLiteral(types.False), true |
| 197 | case types.DoubleKind: |
| 198 | return ctx.NewLiteral(types.Double(0)), true |
| 199 | case types.DurationKind: |
| 200 | return ctx.NewCall(overloads.TypeConvertDuration, ctx.NewLiteral(types.String("0s"))), true |
| 201 | case types.IntKind: |
| 202 | return ctx.NewLiteral(types.IntZero), true |
| 203 | case types.TimestampKind: |
| 204 | return ctx.NewCall(overloads.TypeConvertTimestamp, ctx.NewLiteral(types.Int(0))), true |
| 205 | case types.StructKind: |
| 206 | return ctx.NewStruct(t.TypeName(), []ast.EntryExpr{}), true |
| 207 | case types.UintKind: |
| 208 | return ctx.NewLiteral(types.Uint(0)), true |
| 209 | } |
| 210 | return nil, false |
| 211 | } |
| 212 | |
| 213 | // isBindable indicates whether the inlined type can be used within a cel.bind() if the expression |
| 214 | // being replaced occurs within a presence test. Value types with a size() method or field selection |
no test coverage detected