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: def roundtrip breaks for zero width bound #1340

Open
antong opened this issue Oct 27, 2021 · 5 comments
Open

cmd/cue: def roundtrip breaks for zero width bound #1340

antong opened this issue Oct 27, 2021 · 5 comments
Labels
Discuss Requires maintainer discussion NeedsDesign Functionality seems desirable, but not sure how it should look like. NeedsFix roadmap/language-changes Specific tag for roadmap issue #339

Comments

@antong
Copy link
Contributor

antong commented Oct 27, 2021

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

$ cue version
cue version 0.4.0 windows/amd64

Does this issue reproduce with the latest release?

Yes, with v0.4.0.

What did you do?

$ cue def - <<EOF | cue def -
a: >=5 & <=5
b: a
b: float
EOF

What did you expect to see?

Not an error.

What did you see instead?

b: conflicting values 5 and float (mismatched types int and float):
    -:1:4
    -:2:8

The output of the first cue def is:

a: 5
b: a & float

I bumped into this when looking at #1310 . What I think goes on here is that >= 5 & <= 5 resolves to a concrete value of type number and magnitude 5 (both int 5 and float 5.0 are instances of this value). When exporting (cue def), value.Syntax() outputs this number as "5". This when taken as input is a literal 5 and is an int only (not a more general number,) so doesn't unify with float.

As far as I know there are only float and int literals, no way to directly specify a number literal. I guess the meaning of 5 | 5.0 would be close, but is that then that much better than >= 5 & <= 5.

For completeness sake, cue export :

$ cue export --out=cue - <<EOF
a: >=5 & <=5
b: a
b: float
EOF
a: 5
b: 5

and even

$ cue export --out=cue - <<EOF
a: >=5 & <=5
b: a
b: float & 5.0
EOF
a: 5
b: 5
@antong antong added NeedsInvestigation Triage Requires triage/attention labels Oct 27, 2021
@verdverm
Copy link

verdverm commented Oct 27, 2021

number is probably what you are looking for. It is essentially int | float

$ cue def - <<EOF | cue def -
a: >=5 & <=5
b: a
b: number
EOF
a: 5
b: a & number

This is where I am finding the inconsistencies for what various literal values are cast to. Sometimes it is a number other times it is the more specific int or float.


Note that the int version also works

$ cue def - <<EOF | cue def -
a: >=5 & <=5
b: a
b: int   
EOF
a: 5
b: a & int

@antong
Copy link
Contributor Author

antong commented Oct 28, 2021

number is probably what you are looking for. It is essentially int | float

No, I'm sorry that I was unclear. I wanted to demonstrate the bug that when cue def exports >=5 & <= 5 (which unifies with float), then the CUE output is 5 (which doesn't unify with float). So information is lost and the output is more concrete than the input. The demo was to show how this can break stuff. The original CUE input is valid and can be exported. The output from cue def is no longer valid (unification error) and can't be exported, even though it should have identical meaning.

@myitcv
Copy link
Member

myitcv commented Oct 28, 2021

So information is lost and the output is more concrete than the input

Agreed. This therefore looks like a bug to me.

Linking to #253.

@myitcv myitcv added NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Oct 28, 2021
@myitcv
Copy link
Member

myitcv commented Oct 28, 2021

For completeness a txtar repro (tested against e8550b8):

exec cue def x.cue
stdin stdout
exec cue def -

-- x.cue --
a: >=5 & <=5
b: a
b: float

gives:

> exec cue def -
[stderr]
b: conflicting values 5 and float (mismatched types int and float):
    -:1:4
    -:2:8

@myitcv myitcv changed the title cue def roundtrip breaks for zero width bound cmd/cue: def roundtrip breaks for zero width bound Oct 29, 2021
@myitcv
Copy link
Member

myitcv commented Oct 29, 2021

Noting also that we should ensure the spec examples mentioned in #1339 are accurate with respect to whatever we decide here.

@mpvl mpvl added NeedsDesign Functionality seems desirable, but not sure how it should look like. roadmap/language-changes Specific tag for roadmap issue #339 labels Nov 19, 2021
@myitcv myitcv added Discuss Requires maintainer discussion and removed pre v1.0 labels Oct 14, 2022
@myitcv myitcv added the zGarden label Jun 13, 2023
@mvdan mvdan removed the zGarden label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discuss Requires maintainer discussion NeedsDesign Functionality seems desirable, but not sure how it should look like. NeedsFix roadmap/language-changes Specific tag for roadmap issue #339
Projects
None yet
Development

No branches or pull requests

5 participants