this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/compile: don't panic for incorrect labels

Fixes #610

Change-Id: Icb1fc30119783b5abb519720b02e964d745fbd08
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7921
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>

+90 -4
+6
cue/ast/ast.go
··· 56 56 commentInfo() *comments 57 57 } 58 58 59 + // Name describes the type of n. 60 + func Name(n Node) string { 61 + s := fmt.Sprintf("%T", n) 62 + return strings.ToLower(s[strings.Index(s, "ast.")+4:]) 63 + } 64 + 59 65 func getPos(n Node) token.Pos { 60 66 p := n.pos() 61 67 if p == nil {
+81
cue/testdata/compile/labels.txtar
··· 1 + -- in.cue -- 2 + package compile 3 + 4 + import "list" 5 + 6 + dis1: "dev"|"prd" 7 + dis2: *"dev"|"prd" 8 + 9 + con1: string 10 + let con2 = string 11 + 12 + ok1: [string]: string 13 + ok2: [name=string]: string 14 + ok3: [con1]: string 15 + ok3: [con2]: string 16 + 17 + bad1: ["foo"]: string 18 + bad2: [1]: string 19 + bad3: [name=1]: string 20 + bad4: [dis1]: string 21 + bad5: [dis2]: string 22 + bad6: [name=dis2]: string 23 + bad7: [{foo: "bar"}]: string 24 + bad8: [list.FlattenN([string], 1)]: string 25 + bad9: [for x in [1,2,3] {x}]: string 26 + 27 + -- out/compile -- 28 + bad9: comprehension values not allowed in this position: 29 + ./in.cue:24:8 30 + --- in.cue 31 + { 32 + dis1: ("dev"|"prd") 33 + dis2: (*"dev"|"prd") 34 + con1: string 35 + ok1: { 36 + [string]: string 37 + } 38 + ok2: { 39 + [string]: string 40 + } 41 + ok3: { 42 + [〈1;con1〉]: string 43 + } 44 + ok3: { 45 + [〈1;let con2〉]: string 46 + } 47 + bad1: { 48 + ["foo"]: string 49 + } 50 + bad2: { 51 + [1]: string 52 + } 53 + bad3: { 54 + [1]: string 55 + } 56 + bad4: { 57 + [〈1;dis1〉]: string 58 + } 59 + bad5: { 60 + [〈1;dis2〉]: string 61 + } 62 + bad6: { 63 + [〈1;dis2〉]: string 64 + } 65 + bad7: { 66 + [{ 67 + foo: "bar" 68 + }]: string 69 + } 70 + bad8: { 71 + [〈import;list〉.FlattenN([ 72 + string, 73 + ], 1)]: string 74 + } 75 + bad9: { 76 + [_|_(comprehension values not allowed in this position)]: string 77 + } 78 + } 79 + -- out/eval -- 80 + bad9: comprehension values not allowed in this position: 81 + ./in.cue:24:8
+1 -3
internal/core/compile/compile.go
··· 15 15 package compile 16 16 17 17 import ( 18 - "fmt" 19 18 "strings" 20 19 21 20 "cuelang.org/go/cue/ast" ··· 938 937 } 939 938 940 939 default: 941 - panic(fmt.Sprintf("unknown expression type %T", n)) 942 - // return c.errf(n, "unknown expression type %T", n) 940 + return c.errf(n, "%s values not allowed in this position", ast.Name(n)) 943 941 } 944 942 } 945 943
+2 -1
internal/core/eval/eval_test.go
··· 55 55 56 56 v, err := r.Build(a[0]) 57 57 if err != nil { 58 - t.Fatal(err) 58 + t.WriteErrors(err) 59 + return 59 60 } 60 61 61 62 e := eval.New(r)