github.com/solo-io/cue@v0.4.7/internal/core/adt/closed2.go (about) 1 // Copyright 2020 CUE Authors 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 adt 16 17 // CloseDef defines how individual fieldSets (corresponding to conjuncts) 18 // combine to determine whether a field is contained in a closed set. 19 // 20 // A CloseDef combines multiple conjuncts and embeddings. All CloseDefs are 21 // stored in slice. References to other CloseDefs are indices within this slice. 22 // Together they define the top of the tree of the expression tree of how 23 // conjuncts combine together (a canopy). 24 25 // isComplexStruct reports whether the Closed information should be copied as a 26 // subtree into the parent node using InsertSubtree. If not, the conjuncts can 27 // just be inserted at the current ID. 28 func isComplexStruct(ctx *OpContext, v *Vertex) bool { 29 return v.IsClosedStruct() 30 } 31 32 // TODO: cleanup code and error messages. Reduce duplication in some related 33 // code. 34 func verifyArc2(ctx *OpContext, f Feature, v *Vertex, isClosed bool) (found bool, err *Bottom) { 35 // TODO(perf): collect positions in error. 36 defer ctx.ReleasePositions(ctx.MarkPositions()) 37 38 // Note: it is okay to use parent here as this only needs to be computed 39 // for the original location. 40 if ok, required := Accept(ctx, v.Parent, f); ok || (!required && !isClosed) { 41 return true, nil 42 } 43 44 if !f.IsString() && f != InvalidLabel { 45 // if f.IsHidden() && f != InvalidLabel { Also change Accept in composite.go 46 return false, nil 47 } 48 49 if v != nil { 50 for _, c := range v.Conjuncts { 51 if pos := c.Field(); pos != nil { 52 ctx.AddPosition(pos) 53 } 54 } 55 } 56 57 for _, s := range v.Parent.Structs { 58 s.AddPositions(ctx) 59 } 60 61 label := f.SelectorString(ctx) 62 return false, ctx.NewErrf("field not allowed: %s", label) 63 }