diff --git a/cue/testdata/export/004.txtar b/cue/testdata/export/004.txtar index 14a1c360f05..d201ad7bdde 100644 --- a/cue/testdata/export/004.txtar +++ b/cue/testdata/export/004.txtar @@ -17,7 +17,7 @@ _bar: int { { $type: 3 - _: int + "_": int "_foo": int _bar: int } @@ -25,7 +25,7 @@ _bar: int -- out/eval -- (struct){ $type: (int){ 3 } - _: (int){ int } + "_": (int){ int } "_foo": (int){ int } _bar: (int){ int } } diff --git a/cue/testdata/references/labels.txtar b/cue/testdata/references/labels.txtar index a79c994cf8f..81655d7fffe 100644 --- a/cue/testdata/references/labels.txtar +++ b/cue/testdata/references/labels.txtar @@ -50,6 +50,38 @@ emptyLabel: { a: emptyLabel[""] } +underscore: a: { + // Issue #1454 + foo: #Foo + foo: "_": "bar" + #Foo: [=~""]: string +} + +underscore: b: { + foo: #Foo + // TODO: we should probably disallow the hidden label `_` to avoid confusion. + foo: _: "bar" + #Foo: [=~""]: string +} + +underscore: c: { + foo: "_": "any" + foo: [=~""]: string +} + +underscore: d: { + bar: "_": "any" + #bar: [string]: string + bar: #bar +} + +underscore: e: { + baz: "_h": "any" + #baz: [=~"_"]: string + baz: #baz +} + + // TODO: support. Also not yet supported in old implementation. // c10: { // C=[string]: { @@ -104,6 +136,41 @@ emptyLabel: { "": (int){ 1 } a: (int){ 1 } } + underscore: (struct){ + a: (struct){ + foo: (#struct){ + "_": (string){ "bar" } + } + #Foo: (#struct){ + } + } + b: (struct){ + foo: (#struct){ + _: (string){ "bar" } + } + #Foo: (#struct){ + } + } + c: (struct){ + foo: (struct){ + "_": (string){ "any" } + } + } + d: (struct){ + bar: (#struct){ + "_": (string){ "any" } + } + #bar: (#struct){ + } + } + e: (struct){ + baz: (#struct){ + "_h": (string){ "any" } + } + #baz: (#struct){ + } + } + } } -- out/compile -- --- in.cue @@ -188,4 +255,58 @@ emptyLabel: { "": 1 a: 〈1;emptyLabel〉[""] } + underscore: { + a: { + foo: 〈0;#Foo〉 + foo: { + "_": "bar" + } + #Foo: { + [=~""]: string + } + } + } + underscore: { + b: { + foo: 〈0;#Foo〉 + foo: { + _: "bar" + } + #Foo: { + [=~""]: string + } + } + } + underscore: { + c: { + foo: { + "_": "any" + } + foo: { + [=~""]: string + } + } + } + underscore: { + d: { + bar: { + "_": "any" + } + #bar: { + [string]: string + } + bar: 〈0;#bar〉 + } + } + underscore: { + e: { + baz: { + "_h": "any" + } + #baz: { + [=~"_"]: string + } + baz: 〈0;#baz〉 + } + } } diff --git a/internal/core/adt/closed.go b/internal/core/adt/closed.go index 5e9d5f3f7b7..4cf7f7609f7 100644 --- a/internal/core/adt/closed.go +++ b/internal/core/adt/closed.go @@ -340,12 +340,10 @@ func Accept(ctx *OpContext, n *Vertex, f Feature) (found, required bool) { optionalTypes |= s.types } + var str Value if f.Index() == MaxIndex { f = 0 - } - - var str Value - if optionalTypes&(HasComplexPattern|HasDynamic) != 0 && f.IsString() && f > 0 { + } else if optionalTypes&(HasComplexPattern|HasDynamic) != 0 && f.IsString() { str = f.ToValue(ctx) } diff --git a/internal/core/adt/feature.go b/internal/core/adt/feature.go index a09931408bd..347ac2a4aed 100644 --- a/internal/core/adt/feature.go +++ b/internal/core/adt/feature.go @@ -68,9 +68,6 @@ type StringIndexer interface { // SelectorString reports the shortest string representation of f when used as a // selector. func (f Feature) SelectorString(index StringIndexer) string { - if f == 0 { - return "_" - } x := f.safeIndex() switch f.Typ() { case IntLabel: