From 141925a62c4b579ff6e7399f5948da4935fddb94 Mon Sep 17 00:00:00 2001 From: Rudi Farkas Date: Fri, 10 Nov 2023 21:25:20 +0100 Subject: [PATCH] internal/core/export: fix a recent nil pointer regression Before the fix, the added test fails with a panic due a nil pointer. The fix prevents accessing the offending pointer. After the fix, the new test passes. Note that we might find a better fix down the line for the root cause; a TODO is added as a reminder. Fixes #2584. Closes #2690 as merged as of commit dec11d94. Signed-off-by: Rudi Farkas Change-Id: Ic24562fee250e9efcfaaf1a0bf95a514817675a5 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1172874 TryBot-Result: CUEcueckoo Reviewed-by: Marcel van Lohuizen Unity-Result: CUE porcuepine --- internal/core/export/adt.go | 3 +- .../core/export/testdata/main/issue2584.txtar | 100 ++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 internal/core/export/testdata/main/issue2584.txtar diff --git a/internal/core/export/adt.go b/internal/core/export/adt.go index d91299f681f..26fcfc0d2e4 100644 --- a/internal/core/export/adt.go +++ b/internal/core/export/adt.go @@ -329,7 +329,8 @@ func (e *exporter) resolve(env *adt.Environment, r adt.Resolver) ast.Expr { // comprehensions originate from a single source and do not need to be // handled. if env != nil { // for generated stuff - if v := env.Vertex; !v.IsDynamic { + // TODO: note that env.Vertex should never be nil; investigate and replace the nil check below. + if v := env.Vertex; v != nil && !v.IsDynamic { if v = v.Lookup(x.Label); v != nil { e.linkIdentifier(v, ident) } diff --git a/internal/core/export/testdata/main/issue2584.txtar b/internal/core/export/testdata/main/issue2584.txtar new file mode 100644 index 00000000000..ac351bd5ae8 --- /dev/null +++ b/internal/core/export/testdata/main/issue2584.txtar @@ -0,0 +1,100 @@ +# issue #2584 + +-- in.cue -- +F1: sub1: sub2: L +F2: { + (string): _ + L +} +D: {} +let L = D +-- out/default -- +-- out/definition -- + +let L = D +F1: { + sub1: { + sub2: L + } +} +F2: { + (string): _ + L +} +D: {} +-- out/doc -- +[] +[F1] +[F1 sub1] +[F1 sub1 sub2] +[F2] +[F2 _] +[D] +[L] +-- out/value -- +== Simplified +{ + let L = D + F1: { + sub1: { + sub2: {} + } + } + F2: { + (string): _ + L + } + D: {} +} +== Raw +{ + let L = D + F1: { + sub1: { + sub2: {} + } + } + F2: { + (string): _ + L + } + D: {} +} +== Final +{ + F1: { + sub1: { + sub2: {} + } + } + F2: _|_ // F2: invalid non-ground value string (must be concrete string) + D: {} +} +== All +{ + let L = D + F1: { + sub1: { + sub2: {} + } + } + F2: { + (string): _ + L + } + D: {} +} +== Eval +{ + let L = D + F1: { + sub1: { + sub2: {} + } + } + F2: { + (string): _ + L + } + D: {} +}