Skip to content

Allow easily using variables such as type that are already defined by Stdlib #1241

@same-id

Description

@same-id

Change
Today it is not possible to add a variable that is contained in the following list:

	stdTypes = []*decls.VariableDecl{
		decls.TypeVariable(types.BoolType),
		decls.TypeVariable(types.BytesType),
		decls.TypeVariable(types.DoubleType),
		decls.TypeVariable(types.DurationType),
		decls.TypeVariable(types.IntType),
		decls.TypeVariable(listOfA),
		decls.TypeVariable(mapOfAB),
		decls.TypeVariable(types.NullType),
		decls.TypeVariable(types.StringType),
		decls.TypeVariable(types.TimestampType),
		decls.TypeVariable(types.TypeType),
		decls.TypeVariable(types.UintType),
	}

It could have been nice to allow, for example, adding type as a variable - it should work since if it is not used as a function type() CEL knows to differentiate between the two.

Example
type == 'my-variable'

Alternatives considered

  1. Use NewCustomEnv - I tried this, but this was very complicated since it disabled many functions such as _==_ for all types. I basically just want to free the above types as variables.
  2. Use //go:linkname stdTypes github.com/google/cel-go/common/stdlib.stdTypes and set it to an empty list stdTypes = []*decls.VariableDecl{} - this works but affects all CEL usages and generally should be avoided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions