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

pkg/list: UniqueItems doesn't check properly for uniqueness #2192

Open
rogpeppe opened this issue Dec 16, 2022 · 0 comments
Open

pkg/list: UniqueItems doesn't check properly for uniqueness #2192

rogpeppe opened this issue Dec 16, 2022 · 0 comments

Comments

@rogpeppe
Copy link
Member

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

$ cue version
cue version v0.0.0-20221216062120-45aa5c093e71

       -compiler gc
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
             vcs git
    vcs.revision 45aa5c093e71660b341fa15a8a41d77eb64a0121
        vcs.time 2022-12-16T06:21:20Z
    vcs.modified false

Does this issue reproduce with the latest release?

Yes

What did you do?

! exec cue vet struct.cue
! exec cue vet numeric.cue
exec cue vet noncrete.cue

-- struct.cue --
import "list"

// Should fail.
list.UniqueItems & [{
	b: 1
	a: 0
}, {
	a: 0
	b: 1
}]

-- numeric.cue --
import "list"

// Should fail.
list.UniqueItems & [1.00, 1.0]

-- noncrete.cue --
import "list"
x: int
y: int

// Should succeed (x and y could become become different).
list.UniqueItems & [x, y]

What did you expect to see?

A passing test.

What did you see instead?

% testscript -continue /tmp/x.txtar
> ! exec cue vet struct.cue
FAIL: /tmp/testscript3815040590/x.txtar/script.txtar:1: unexpected command success
> ! exec cue vet numeric.cue
FAIL: /tmp/testscript3815040590/x.txtar/script.txtar:2: unexpected command success
> exec cue vet noncrete.cue
[stderr]
conflicting values list.UniqueItems() and {x:int,y:int,(list.UniqueItems & [x,y])} (mismatched types list and struct):
    ./noncrete.cue:1:1

The implementation of list.UniqueItems is overly simplistic. It should be fixed to respect equality (and perhaps we should define equality of objects as part of the CUE language specification).

Note that jsonschema has a uniqueItems property, so it would probably be a good idea to align with that specification for the definition of equality: https://json-schema.org/draft/2020-12/json-schema-core.html#name-instance-equality

@rogpeppe rogpeppe added NeedsInvestigation Triage Requires triage/attention NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Dec 16, 2022
@rogpeppe rogpeppe changed the title pkg/list: UniqueItems has a flawed implementation pkg/list: UniqueItems doesn't check properly for uniqueness Dec 16, 2022
@myitcv myitcv added zGarden and removed zGarden labels Jun 13, 2023
@myitcv myitcv added this to the v0.8.0: semantic adjustments milestone Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants