Skip to content

Commit

Permalink
internal/core/export: fix a recent nil pointer regression
Browse files Browse the repository at this point in the history
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 dec11d9.

Signed-off-by: Rudi Farkas <[email protected]>
Change-Id: Ic24562fee250e9efcfaaf1a0bf95a514817675a5
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1172874
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Marcel van Lohuizen <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
rudifa authored and mvdan committed Nov 30, 2023
1 parent bba2263 commit 141925a
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/core/export/adt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
100 changes: 100 additions & 0 deletions internal/core/export/testdata/main/issue2584.txtar
Original file line number Diff line number Diff line change
@@ -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: {}
}

0 comments on commit 141925a

Please sign in to comment.