| 1 | // Copyright 2018 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package checkerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/ |
| 16 | |
| 17 | import ( |
| 18 | "github.com/google/cel-go/common/typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/" |
| 19 | ) |
| 20 | |
| 21 | // isDyn returns true if the input t is either type DYN or a well-known ANY message. |
| 22 | func isDynscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isDyn().(t *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 23 | // Note: object type values that are well-known and map to a DYN value in practice |
| 24 | // are sanitized prior to being added to the environment. |
| 25 | switch t.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() { |
| 26 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DynKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DynKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.AnyKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/AnyKind.: |
| 27 | return true |
| 28 | default: |
| 29 | return false |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // isDynOrError returns true if the input is either an Error, DYN, or well-known ANY message. |
| 34 | func isDynOrErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isDynOrError().(t *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 35 | return isErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isError().(t) || isDynscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isDyn().(t) |
| 36 | } |
| 37 | |
| 38 | func isErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isError().(t *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 39 | return t.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.ErrorKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/ErrorKind. |
| 40 | } |
| 41 | |
| 42 | func isOptionalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isOptional().(t *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 43 | if t.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.OpaqueKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/OpaqueKind. { |
| 44 | return t.TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().() == "optional_type" |
| 45 | } |
| 46 | return false |
| 47 | } |
| 48 | |
| 49 | func maybeUnwrapOptionalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/maybeUnwrapOptional().(t *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) (*typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#, bool) { |
| 50 | if isOptionalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isOptional().(t) { |
| 51 | return t.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[0], true |
| 52 | } |
| 53 | return t, false |
| 54 | } |
| 55 | |
| 56 | // isEqualOrLessSpecific checks whether one type is equal or less specific than the other one. |
| 57 | // A type is less specific if it matches the other type using the DYN type. |
| 58 | func isEqualOrLessSpecificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isEqualOrLessSpecific().(t1, t2 *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 59 | kind1, kind2 := t1.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().(), t2.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() |
| 60 | // The first type is less specific. |
| 61 | if isDynscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isDyn().(t1) || kind1 == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeParamKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeParamKind. { |
| 62 | return true |
| 63 | } |
| 64 | // The first type is not less specific. |
| 65 | if isDynscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isDyn().(t2) || kind2 == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeParamKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeParamKind. { |
| 66 | return false |
| 67 | } |
| 68 | // Types must be of the same kind to be equal. |
| 69 | if kind1 != kind2 { |
| 70 | return false |
| 71 | } |
| 72 | |
| 73 | // With limited exceptions for ANY and JSON values, the types must agree and be equivalent in |
| 74 | // order to return true. |
| 75 | switch kind1 { |
| 76 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.OpaqueKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/OpaqueKind.: |
| 77 | if t1.TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().() != t2.TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().() || |
| 78 | len(t1.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()) != len(t2.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()) { |
| 79 | return false |
| 80 | } |
| 81 | for i, p1 := range t1.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().() { |
| 82 | if !isEqualOrLessSpecificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isEqualOrLessSpecific().(p1, t2.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[i]) { |
| 83 | return false |
| 84 | } |
| 85 | } |
| 86 | return true |
| 87 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.ListKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/ListKind.: |
| 88 | return isEqualOrLessSpecificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isEqualOrLessSpecific().(t1.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[0], t2.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[0]) |
| 89 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.MapKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/MapKind.: |
| 90 | return isEqualOrLessSpecificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isEqualOrLessSpecific().(t1.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[0], t2.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[0]) && |
| 91 | isEqualOrLessSpecificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isEqualOrLessSpecific().(t1.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[1], t2.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[1]) |
| 92 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeKind.: |
| 93 | return true |
| 94 | default: |
| 95 | return t1.IsExactTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#IsExactType().(t2) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // / internalIsAssignable returns true if t1 is assignable to t2. |
| 100 | func internalIsAssignablescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignable().(m *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#, t1, t2 *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 101 | // Process type parameters. |
| 102 | kind1, kind2 := t1.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().(), t2.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() |
| 103 | if kind2 == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeParamKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeParamKind. { |
| 104 | // If t2 is a valid type substitution for t1, return true. |
| 105 | valid, t2HasSub := isValidTypeSubstitutionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isValidTypeSubstitution().(m, t1, t2) |
| 106 | if valid { |
| 107 | return true |
| 108 | } |
| 109 | // If t2 is not a valid type sub for t1, and already has a known substitution return false |
| 110 | // since it is not possible for t1 to be a substitution for t2. |
| 111 | if !valid && t2HasSub { |
| 112 | return false |
| 113 | } |
| 114 | // Otherwise, fall through to check whether t1 is a possible substitution for t2. |
| 115 | } |
| 116 | if kind1 == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeParamKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeParamKind. { |
| 117 | // Return whether t1 is a valid substitution for t2. If not, do no additional checks as the |
| 118 | // possible type substitutions have been searched in both directions. |
| 119 | valid, _ := isValidTypeSubstitutionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isValidTypeSubstitution().(m, t2, t1) |
| 120 | return valid |
| 121 | } |
| 122 | |
| 123 | // Next check for wildcard types. |
| 124 | if isDynOrErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isDynOrError().(t1) || isDynOrErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isDynOrError().(t2) { |
| 125 | return true |
| 126 | } |
| 127 | // Preserve the nullness checks of the legacy type-checker. |
| 128 | if kind1 == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NullTypeKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NullTypeKind. { |
| 129 | return internalIsAssignableNullscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignableNull().(t2) |
| 130 | } |
| 131 | if kind2 == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NullTypeKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NullTypeKind. { |
| 132 | return internalIsAssignableNullscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignableNull().(t1) |
| 133 | } |
| 134 | |
| 135 | // Test for when the types do not need to agree, but are more specific than dyn. |
| 136 | switch kind1 { |
| 137 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BoolKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BoolKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BytesKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BytesKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintKind., |
| 138 | typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.AnyKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/AnyKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DurationKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DurationKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TimestampKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TimestampKind., |
| 139 | typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StructKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StructKind.: |
| 140 | // Test whether t2 is assignable from t1. The order of this check won't usually matter; |
| 141 | // however, there may be cases where type capabilities are expanded beyond what is supported |
| 142 | // in the current common/types package. For example, an interface designation for a group of |
| 143 | // Struct types. |
| 144 | return t2.IsAssignableTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#IsAssignableType().(t1) |
| 145 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeKind.: |
| 146 | return kind2 == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeKind. |
| 147 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.OpaqueKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/OpaqueKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.ListKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/ListKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.MapKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/MapKind.: |
| 148 | return t1.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() == t2.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() && t1.TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().() == t2.TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().() && |
| 149 | internalIsAssignableListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignableList().(m, t1.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().(), t2.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()) |
| 150 | default: |
| 151 | return false |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // isValidTypeSubstitution returns whether t2 (or its type substitution) is a valid type |
| 156 | // substitution for t1, and whether t2 has a type substitution in mapping m. |
| 157 | // |
| 158 | // The type t2 is a valid substitution for t1 if any of the following statements is true |
| 159 | // - t2 has a type substitution (t2sub) equal to t1 |
| 160 | // - t2 has a type substitution (t2sub) assignable to t1 |
| 161 | // - t2 does not occur within t1. |
| 162 | func isValidTypeSubstitutionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isValidTypeSubstitution().(m *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#, t1, t2 *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) (valid, hasSub bool) { |
| 163 | // Early return if the t1 and t2 are the same instance. |
| 164 | kind1, kind2 := t1.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().(), t2.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() |
| 165 | if kind1 == kind2 && t1.IsExactTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#IsExactType().(t2) { |
| 166 | return true, true |
| 167 | } |
| 168 | if t2Sub, found := m.findscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#find().(t2); found { |
| 169 | // Early return if t1 and t2Sub are the same instance as otherwise the mapping |
| 170 | // might mark a type as being a subtitution for itself. |
| 171 | if kind1 == t2Sub.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() && t1.IsExactTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#IsExactType().(t2Sub) { |
| 172 | return true, true |
| 173 | } |
| 174 | // If the types are compatible, pick the more general type and return true |
| 175 | if internalIsAssignablescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignable().(m, t1, t2Sub) { |
| 176 | t2New := mostGeneralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mostGeneral().(t1, t2Sub) |
| 177 | // only update the type reference map if the target type does not occur within it. |
| 178 | if notReferencedInscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/notReferencedIn().(m, t2, t2New) { |
| 179 | m.addscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#add().(t2, t2New) |
| 180 | } |
| 181 | // acknowledge the type agreement, and that the substitution is already tracked. |
| 182 | return true, true |
| 183 | } |
| 184 | return false, true |
| 185 | } |
| 186 | if notReferencedInscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/notReferencedIn().(m, t2, t1) { |
| 187 | m.addscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#add().(t2, t1) |
| 188 | return true, false |
| 189 | } |
| 190 | return false, false |
| 191 | } |
| 192 | |
| 193 | // internalIsAssignableList returns true if the element types at each index in the list are |
| 194 | // assignable from l1[i] to l2[i]. The list lengths must also agree for the lists to be |
| 195 | // assignable. |
| 196 | func internalIsAssignableListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignableList().(m *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#, l1, l2 []*typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 197 | if len(l1) != len(l2) { |
| 198 | return false |
| 199 | } |
| 200 | for i, t1 := range l1 { |
| 201 | if !internalIsAssignablescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignable().(m, t1, l2[i]) { |
| 202 | return false |
| 203 | } |
| 204 | } |
| 205 | return true |
| 206 | } |
| 207 | |
| 208 | // internalIsAssignableNull returns true if the type is nullable. |
| 209 | func internalIsAssignableNullscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignableNull().(t *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 210 | return isLegacyNullablescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isLegacyNullable().(t) || t.IsAssignableTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#IsAssignableType().(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NullTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NullType.) |
| 211 | } |
| 212 | |
| 213 | // isLegacyNullable preserves the null-ness compatibility of the original type-checker implementation. |
| 214 | func isLegacyNullablescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isLegacyNullable().(t *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 215 | switch t.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() { |
| 216 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.OpaqueKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/OpaqueKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StructKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StructKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.AnyKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/AnyKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DurationKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DurationKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TimestampKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TimestampKind.: |
| 217 | return true |
| 218 | } |
| 219 | return false |
| 220 | } |
| 221 | |
| 222 | // isAssignable returns an updated type substitution mapping if t1 is assignable to t2. |
| 223 | func isAssignablescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isAssignable().(m *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#, t1, t2 *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping# { |
| 224 | mCopy := m.copyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#copy().() |
| 225 | if internalIsAssignablescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignable().(mCopy, t1, t2) { |
| 226 | return mCopy |
| 227 | } |
| 228 | return nil |
| 229 | } |
| 230 | |
| 231 | // isAssignableList returns an updated type substitution mapping if l1 is assignable to l2. |
| 232 | func isAssignableListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isAssignableList().(m *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#, l1, l2 []*typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping# { |
| 233 | mCopy := m.copyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#copy().() |
| 234 | if internalIsAssignableListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/internalIsAssignableList().(mCopy, l1, l2) { |
| 235 | return mCopy |
| 236 | } |
| 237 | return nil |
| 238 | } |
| 239 | |
| 240 | // mostGeneral returns the more general of two types which are known to unify. |
| 241 | func mostGeneralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mostGeneral().(t1, t2 *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type# { |
| 242 | if isEqualOrLessSpecificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/isEqualOrLessSpecific().(t1, t2) { |
| 243 | return t1 |
| 244 | } |
| 245 | return t2 |
| 246 | } |
| 247 | |
| 248 | // notReferencedIn checks whether the type doesn't appear directly or transitively within the other |
| 249 | // type. This is a standard requirement for type unification, commonly referred to as the "occurs |
| 250 | // check". |
| 251 | func notReferencedInscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/notReferencedIn().(m *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#, t, withinType *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) bool { |
| 252 | if t.IsExactTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#IsExactType().(withinType) { |
| 253 | return false |
| 254 | } |
| 255 | withinKind := withinType.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() |
| 256 | switch withinKind { |
| 257 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeParamKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeParamKind.: |
| 258 | wtSub, found := m.findscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#find().(withinType) |
| 259 | if !found { |
| 260 | return true |
| 261 | } |
| 262 | return notReferencedInscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/notReferencedIn().(m, t, wtSub) |
| 263 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.OpaqueKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/OpaqueKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.ListKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/ListKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.MapKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/MapKind., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeKind.: |
| 264 | for _, pt := range withinType.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().() { |
| 265 | if !notReferencedInscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/notReferencedIn().(m, t, pt) { |
| 266 | return false |
| 267 | } |
| 268 | } |
| 269 | return true |
| 270 | default: |
| 271 | return true |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | // substitute replaces all direct and indirect occurrences of bound type parameters. Unbound type |
| 276 | // parameters are replaced by DYN if typeParamToDyn is true. |
| 277 | func substitutescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/substitute().(m *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#, t *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#, typeParamToDyn bool) *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type# { |
| 278 | if tSub, found := m.findscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#find().(t); found { |
| 279 | return substitutescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/substitute().(m, tSub, typeParamToDyn) |
| 280 | } |
| 281 | kind := t.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() |
| 282 | if typeParamToDyn && kind == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeParamKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeParamKind. { |
| 283 | return typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DynTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DynType. |
| 284 | } |
| 285 | switch kind { |
| 286 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.OpaqueKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/OpaqueKind.: |
| 287 | return typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NewOpaqueTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NewOpaqueType().(t.TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().(), substituteParamsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/substituteParams().(m, t.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().(), typeParamToDyn)...) |
| 288 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.ListKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/ListKind.: |
| 289 | return typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NewListTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NewListType().(substitutescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/substitute().(m, t.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[0], typeParamToDyn)) |
| 290 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.MapKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/MapKind.: |
| 291 | return typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NewMapTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NewMapType().(substitutescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/substitute().(m, t.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[0], typeParamToDyn), |
| 292 | substitutescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/substitute().(m, t.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[1], typeParamToDyn)) |
| 293 | case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeKind.: |
| 294 | if len(t.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()) > 0 { |
| 295 | tParam := t.Parametersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Parameters().()[0] |
| 296 | return typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NewTypeTypeWithParamscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NewTypeTypeWithParam().(substitutescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/substitute().(m, tParam, typeParamToDyn)) |
| 297 | } |
| 298 | return t |
| 299 | default: |
| 300 | return t |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | func substituteParamsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/substituteParams().(m *mappingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/mapping#, typeParams []*typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#, typeParamToDyn bool) []*typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type# { |
| 305 | subParams := make([]*typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#, len(typeParams)) |
| 306 | for i, tp := range typeParams { |
| 307 | subParams[i] = substitutescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/substitute().(m, tp, typeParamToDyn) |
| 308 | } |
| 309 | return subParams |
| 310 | } |
| 311 | |
| 312 | func newFunctionTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/newFunctionType().(resultType *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#, argTypes ...*typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#) *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type# { |
| 313 | return typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NewOpaqueTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NewOpaqueType().("function", append([]*typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#{resultType}, argTypes...)...) |
| 314 | } |