Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cue: trim cannot handle ellipsis and empty list value #3140

Open
gisle opened this issue May 11, 2024 · 2 comments
Open

cmd/cue: trim cannot handle ellipsis and empty list value #3140

gisle opened this issue May 11, 2024 · 2 comments
Labels
NeedsInvestigation trim This issue is related to trim.

Comments

@gisle
Copy link

gisle commented May 11, 2024

What version of CUE are you using (cue version)?

$ cue version
cue version v0.8.2

go version go1.22.2
      -buildmode exe
       -compiler gc
       -trimpath true
     CGO_ENABLED 0
          GOARCH arm64
            GOOS darwin

Does this issue reproduce with the latest stable release?

I belive my version to be the latest stable release.

What did you do?

Ran 'cue trim' on this code:

package test

#Foo: {
	id: string
	...
}

foo: [ID=_]: #Foo & {
	id: ID
}

foo: X1: {
	id: "X1"
	alist: []
}

What did you expect to see?

No output from cue trim and that it removed the id field.

What did you see instead?

$ cue trim ./...:test
  {
      #Foo: {
      	id: string
      }
      foo: {
          X1: {
              id: "X1"
-             alist: []
          }
      }
  }
Aborting trim, output differs after trimming. This is a bug! Use -i to force trim.
You can file a bug here: https://cuelang.org/issues/new?assignees=&labels=NeedsInvestigation&template=bug_report.md&title=
@gisle gisle added NeedsInvestigation Triage Requires triage/attention labels May 11, 2024
@myitcv myitcv changed the title Aborting trim, output differs after trimming. This is a bug! (empty lists removed) cmd/cue: aborting trim, output differs after trimming. This is a bug! (empty lists removed) May 13, 2024
@myitcv myitcv added trim This issue is related to trim. and removed Triage Requires triage/attention labels May 13, 2024
@myitcv myitcv changed the title cmd/cue: aborting trim, output differs after trimming. This is a bug! (empty lists removed) cmd/cue: trim cannot handle ellipsis and empty list value May 13, 2024
@myitcv
Copy link
Member

myitcv commented May 13, 2024

Thanks for the report. This appears to be something to do with the interaction between ... and the empty list value []:

# Keep a non-trimmed backup
cp config.cue config.cue.bak

# Working
exec cue trim working.cue config.cue
cmp config.cue config.cue.golden

# Broken
exec cue trim broken.cue config.cue
cmp config.cue config.cue.golden

-- working.cue --
package test

#Foo: {
	id:     string
	alist?: _
}

foo: [ID=_]: #Foo & {
	id: ID
}
-- broken.cue --
package test

#Foo: {
	id: string
	...
}

foo: [ID=_]: #Foo & {
	id: ID
}
-- config.cue --
foo: X1: {
	id: "X1"
	alist: []
}
-- config.cue.golden --
foo: X1: {
	alist: []
}

@NoamTD
Copy link
Contributor

NoamTD commented May 13, 2024

for the record, this can be further simplified to:

# Keep a non-trimmed backup
cp config.cue config.cue.golden

# Working
exec cue trim working.cue config.cue
cmp config.cue config.cue.golden

# Broken
exec cue trim broken.cue config.cue
cmp config.cue config.cue.golden

-- working.cue --
package test

#Foo: {
	alist?: _
	aStruct?: _
}

foo: #Foo & { }
-- broken.cue --
package test

#Foo: {...}

-- config.cue --
foo: X1: {
	alist: []
        astruct: {}
}

Also worth noting that this is equally broken in the case of an empty struct ({})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation trim This issue is related to trim.
Projects
None yet
Development

No branches or pull requests

3 participants