isBindable indicates whether the inlined type can be used within a cel.bind() if the expression being replaced occurs within a presence test. Value types with a size() method or field selection support can be bound. In future iterations, support may also be added for indexer types which can be rewr
(matches []ast.NavigableExpr, inlined ast.Expr, inlinedType *Type)
| 218 | // expression; however, this would imply a rewrite of the inlined expression that may not be necessary |
| 219 | // in most cases. |
| 220 | func isBindable(matches []ast.NavigableExpr, inlined ast.Expr, inlinedType *Type) bool { |
| 221 | if inlinedType.IsAssignableType(NullType) || |
| 222 | inlinedType.HasTrait(traits.SizerType) { |
| 223 | return true |
| 224 | } |
| 225 | for _, m := range matches { |
| 226 | if m.Kind() != ast.SelectKind { |
| 227 | continue |
| 228 | } |
| 229 | sel := m.AsSelect() |
| 230 | if sel.IsTestOnly() { |
| 231 | return false |
| 232 | } |
| 233 | } |
| 234 | return true |
| 235 | } |
| 236 | |
| 237 | // matchVariable matches simple identifiers, select expressions, and presence test expressions |
| 238 | // which match the (potentially) qualified variable name provided as input. |
no test coverage detected