this repo has no description
0
fork

Configure Feed

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

cue: exempt aliases and embeddings from recursive closing

See comments in spec.

Issue #40.

Change-Id: I7e17864c649ef3576d6992eb5a2b530c76f5496e
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3043
Reviewed-by: Jonathan Amsterdam <jba@google.com>

authored by

Marcel van Lohuizen and committed by
Marcel van Lohuizen
5e8c3916 9818761a

+54
+6
cue/ast.go
··· 244 244 v1.object.addTemplate(v.ctx(), token.NoPos, template) 245 245 246 246 case *ast.EmbedDecl: 247 + old := v.ctx().inDefinition 248 + v.ctx().inDefinition = 0 247 249 e := v1.walk(x.Expr) 250 + v.ctx().inDefinition = old 248 251 if isBottom(e) { 249 252 return e 250 253 } ··· 498 501 } 499 502 500 503 if a, ok := n.Node.(*ast.Alias); ok { 504 + old := v.ctx().inDefinition 505 + v.ctx().inDefinition = 0 501 506 ret = v.walk(a.Expr) 507 + v.ctx().inDefinition = old 502 508 break 503 509 } 504 510
+25
cue/resolve_test.go
··· 1230 1230 `ctcp: <16>C{x: int}, ` + 1231 1231 `ctct: <17>{x: int, ...}}`, 1232 1232 }, { 1233 + desc: "excluded embedding from closing", 1234 + in: ` 1235 + S :: { 1236 + a: { c: int } 1237 + { 1238 + c: { d: int } 1239 + } 1240 + B = { open: int } 1241 + b: B 1242 + } 1243 + V: S & { 1244 + c e: int 1245 + b extra: int 1246 + } 1247 + `, 1248 + out: `<0>{` + 1249 + `S :: <1>C{` + 1250 + `a: <2>C{c: int}, ` + 1251 + `c: <3>{d: int}, ` + 1252 + `b: <4>{open: int}}, ` + 1253 + `V: <5>C{` + 1254 + `a: <6>C{c: int}, ` + 1255 + `c: <7>{d: int, e: int}, ` + 1256 + `b: <8>{open: int, extra: int}}}`, 1257 + }, { 1233 1258 desc: "closing with failed optional", 1234 1259 in: ` 1235 1260 k1 :: {a: int, b?: int} & {a: int} // closed({a: int})
+23
doc/ref/spec.md
··· 1198 1198 It is illegal to have a regular field and a definition with the same name 1199 1199 within the same struct. 1200 1200 Literal structs that are part of a definition's value are implicitly closed. 1201 + This excludes literals structs in embeddings and aliases. 1201 1202 An ellipsis `...` in such literal structs keeps them open, 1202 1203 as it defines `_` for all labels. 1204 + <!-- 1205 + Excluding embeddings from recursive closing allows comprehensions to be 1206 + interpreted as embeddings without some exception. For instance, 1207 + if x > 2 { 1208 + foo: string 1209 + } 1210 + should not cause any failure. It is also consistent with embeddings being 1211 + opened when included in a closed struct. 1203 1212 1213 + Finally, excluding embeddings from recursive closing allows for 1214 + a mechanism to not recursively close, without needing an additional language 1215 + construct, such as a triple colon or something else: 1216 + foo :: { 1217 + { 1218 + // not recursively closed 1219 + } 1220 + ... // include this to not close outer struct 1221 + } 1222 + 1223 + Including aliases from this exclusion, which are more a separate definition 1224 + than embedding seems sensible, and allows for an easy mechanism to avoid 1225 + closing, aside from embedding. 1226 + --> 1204 1227 1205 1228 ``` 1206 1229 // MyStruct is closed and as there is no expression label or `...`, we know