From e9c005d9961db263b404566ec224c6850b484b10 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Wed, 16 Oct 2024 13:15:22 +0200 Subject: [PATCH] pkg/path: fix path issue Use proper accessor for Conjuncts so that all necessary conjuncts are visited. Signed-off-by: Marcel van Lohuizen Change-Id: I501335b9950556979f67c91df6f827991c12378a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202657 TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine Reviewed-by: Matthew Sackman --- internal/core/adt/composite.go | 6 +- internal/core/export/value.go | 14 +- pkg/path/testdata/join.txtar | 266 --------------------------------- 3 files changed, 11 insertions(+), 275 deletions(-) diff --git a/internal/core/adt/composite.go b/internal/core/adt/composite.go index 04a7dac5f20..76833785c81 100644 --- a/internal/core/adt/composite.go +++ b/internal/core/adt/composite.go @@ -635,14 +635,14 @@ func (v *Vertex) setParentDone() { // VisitLeafConjuncts visits all conjuncts that are leafs of the ConjunctGroup tree. func (v *Vertex) VisitLeafConjuncts(f func(Conjunct) bool) { - visitConjuncts(v.Conjuncts, f) + VisitConjuncts(v.Conjuncts, f) } -func visitConjuncts(a []Conjunct, f func(Conjunct) bool) bool { +func VisitConjuncts(a []Conjunct, f func(Conjunct) bool) bool { for _, c := range a { switch x := c.x.(type) { case *ConjunctGroup: - if !visitConjuncts(*x, f) { + if !VisitConjuncts(*x, f) { return false } default: diff --git a/internal/core/export/value.go b/internal/core/export/value.go index 8d2507c1d80..8319589c61b 100644 --- a/internal/core/export/value.go +++ b/internal/core/export/value.go @@ -245,13 +245,15 @@ func (e *exporter) bool(n *adt.Bool) (b *ast.BasicLit) { return ast.NewBool(n.B) } -func extractBasic(a []adt.Conjunct) *ast.BasicLit { - for _, v := range a { - if b, ok := v.Source().(*ast.BasicLit); ok { - return &ast.BasicLit{Kind: b.Kind, Value: b.Value} +func extractBasic(a []adt.Conjunct) (lit *ast.BasicLit) { + adt.VisitConjuncts(a, func(c adt.Conjunct) bool { + if b, ok := c.Source().(*ast.BasicLit); ok { + lit = &ast.BasicLit{Kind: b.Kind, Value: b.Value} + return false } - } - return nil + return true + }) + return lit } func (e *exporter) num(n *adt.Num, orig []adt.Conjunct) *ast.BasicLit { diff --git a/pkg/path/testdata/join.txtar b/pkg/path/testdata/join.txtar index 01cd44288e1..b7e07098603 100644 --- a/pkg/path/testdata/join.txtar +++ b/pkg/path/testdata/join.txtar @@ -57,272 +57,6 @@ Join: [_]: [ {arg: [#"C:a"#, #"b"#]}, {arg: [#"\\host\share"#, #"foo"#]}, ] --- out/path-v3 -- -joinSingle: "a/b" -Join: { - unix: [{ - arg: ["a", "b"] - out: "a/b" - }, { - arg: ["a/b", "c/d"] - out: "a/b/c/d" - }, { - arg: ["/"] - out: "/" - }, { - arg: ["a"] - out: "a" - }, { - arg: ["a", "b"] - out: "a/b" - }, { - arg: ["a", ""] - out: "a" - }, { - arg: ["", "b"] - out: "b" - }, { - arg: ["/", "a"] - out: "/a" - }, { - arg: ["/", "a/b"] - out: "/a/b" - }, { - arg: ["/", ""] - out: "/" - }, { - arg: ["//", "a"] - out: "/a" - }, { - arg: ["directory", "file"] - out: "directory/file" - }, { - arg: ["C:\\Windows\\", "System32"] - out: "C:\\Windows\\/System32" - }, { - arg: ["C:\\Windows\\", ""] - out: "C:\\Windows\\" - }, { - arg: ["C:\\", "Windows"] - out: "C:\\/Windows" - }, { - arg: ["C:", "a\\b"] - out: "C:/a\\b" - }, { - arg: ["C:", "a", "b"] - out: "C:/a/b" - }, { - arg: ["C:", "", "", "b"] - out: "C:/b" - }, { - arg: ["C:", ""] - out: "C:" - }, { - arg: ["C:", "", ""] - out: "C:" - }, { - arg: ["C:.", "a"] - out: "C:./a" - }, { - arg: ["C:a", "b"] - out: "C:a/b" - }, { - arg: ["\\\\host\\share", "foo"] - out: "\\\\host\\share/foo" - }] - windows: [{ - arg: ["a", "b"] - out: "a\\b" - }, { - arg: ["a/b", "c/d"] - out: "a\\b\\c\\d" - }, { - arg: ["/"] - out: "\\" - }, { - arg: ["a"] - out: "a" - }, { - arg: ["a", "b"] - out: "a\\b" - }, { - arg: ["a", ""] - out: "a" - }, { - arg: ["", "b"] - out: "b" - }, { - arg: ["/", "a"] - out: "\\a" - }, { - arg: ["/", "a/b"] - out: "\\a\\b" - }, { - arg: ["/", ""] - out: "\\" - }, { - arg: ["//", "a"] - out: "\\a" - }, { - arg: ["directory", "file"] - out: "directory\\file" - }, { - arg: ["C:\\Windows\\", "System32"] - out: "C:\\Windows\\System32" - }, { - arg: ["C:\\Windows\\", ""] - out: "C:\\Windows" - }, { - arg: ["C:\\", "Windows"] - out: "C:\\Windows" - }, { - arg: ["C:", "a\\b"] - out: "C:a\\b" - }, { - arg: ["C:", "a", "b"] - out: "C:a\\b" - }, { - arg: ["C:", "", "", "b"] - out: "C:b" - }, { - arg: ["C:", ""] - out: "C:." - }, { - arg: ["C:", "", ""] - out: "C:." - }, { - arg: ["C:.", "a"] - out: "C:a" - }, { - arg: ["C:a", "b"] - out: "C:a\\b" - }, { - arg: ["\\\\host\\share", "foo"] - out: "\\\\host\\share\\foo" - }] -} --- diff/-out/path-v3<==>+out/path -- -diff old new ---- old -+++ new -@@ -37,37 +37,37 @@ - arg: ["directory", "file"] - out: "directory/file" - }, { -- arg: [#"C:\Windows\"#, #"System32"#] -+ arg: ["C:\\Windows\\", "System32"] - out: "C:\\Windows\\/System32" - }, { -- arg: [#"C:\Windows\"#, #""#] -+ arg: ["C:\\Windows\\", ""] - out: "C:\\Windows\\" - }, { -- arg: [#"C:\"#, #"Windows"#] -+ arg: ["C:\\", "Windows"] - out: "C:\\/Windows" - }, { -- arg: [#"C:"#, #"a\b"#] -+ arg: ["C:", "a\\b"] - out: "C:/a\\b" - }, { -- arg: [#"C:"#, #"a"#, #"b"#] -+ arg: ["C:", "a", "b"] - out: "C:/a/b" - }, { -- arg: [#"C:"#, #""#, #""#, #"b"#] -+ arg: ["C:", "", "", "b"] - out: "C:/b" - }, { -- arg: [#"C:"#, #""#] -- out: "C:" -- }, { -- arg: [#"C:"#, #""#, #""#] -- out: "C:" -- }, { -- arg: [#"C:."#, #"a"#] -+ arg: ["C:", ""] -+ out: "C:" -+ }, { -+ arg: ["C:", "", ""] -+ out: "C:" -+ }, { -+ arg: ["C:.", "a"] - out: "C:./a" - }, { -- arg: [#"C:a"#, #"b"#] -+ arg: ["C:a", "b"] - out: "C:a/b" - }, { -- arg: [#"\\host\share"#, #"foo"#] -+ arg: ["\\\\host\\share", "foo"] - out: "\\\\host\\share/foo" - }] - windows: [{ -@@ -107,37 +107,37 @@ - arg: ["directory", "file"] - out: "directory\\file" - }, { -- arg: [#"C:\Windows\"#, #"System32"#] -+ arg: ["C:\\Windows\\", "System32"] - out: "C:\\Windows\\System32" - }, { -- arg: [#"C:\Windows\"#, #""#] -- out: "C:\\Windows" -- }, { -- arg: [#"C:\"#, #"Windows"#] -- out: "C:\\Windows" -- }, { -- arg: [#"C:"#, #"a\b"#] -- out: "C:a\\b" -- }, { -- arg: [#"C:"#, #"a"#, #"b"#] -- out: "C:a\\b" -- }, { -- arg: [#"C:"#, #""#, #""#, #"b"#] -+ arg: ["C:\\Windows\\", ""] -+ out: "C:\\Windows" -+ }, { -+ arg: ["C:\\", "Windows"] -+ out: "C:\\Windows" -+ }, { -+ arg: ["C:", "a\\b"] -+ out: "C:a\\b" -+ }, { -+ arg: ["C:", "a", "b"] -+ out: "C:a\\b" -+ }, { -+ arg: ["C:", "", "", "b"] - out: "C:b" - }, { -- arg: [#"C:"#, #""#] -- out: "C:." -- }, { -- arg: [#"C:"#, #""#, #""#] -- out: "C:." -- }, { -- arg: [#"C:."#, #"a"#] -+ arg: ["C:", ""] -+ out: "C:." -+ }, { -+ arg: ["C:", "", ""] -+ out: "C:." -+ }, { -+ arg: ["C:.", "a"] - out: "C:a" - }, { -- arg: [#"C:a"#, #"b"#] -- out: "C:a\\b" -- }, { -- arg: [#"\\host\share"#, #"foo"#] -+ arg: ["C:a", "b"] -+ out: "C:a\\b" -+ }, { -+ arg: ["\\\\host\\share", "foo"] - out: "\\\\host\\share\\foo" - }] - } --- diff/todo/p2 -- -Differing string representation of semantically identical strings. -- out/path -- joinSingle: "a/b" Join: {