Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Parse error on default constraints (...type) #1065

Closed
czaplicki opened this issue Jun 18, 2021 · 5 comments
Closed

Parse error on default constraints (...type) #1065

czaplicki opened this issue Jun 18, 2021 · 5 comments

Comments

@czaplicki
Copy link

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

$ cue version
cue version 0.4.0 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

$ cue eval test.cue

test.cue

type: {
	field1: int
	...string
}

What did you expect to see?

Not a parse error.

What did you see instead?

missing ',' in struct literal:
    ./test.cue:3:5
expected '}', found 'EOF':
    ./test.cue:4:3

Footnote

Correct me if I'm wrong, but from what I gathered from the spec,
it is the right syntax.

@eadlam
Copy link
Contributor

eadlam commented Jun 25, 2021

This snippet appears verbatim in the spec and results in the same error:

a: {
    foo:    string  // foo is a string
    ["^i"]: int     // all other fields starting with i are integers
    ["^b"]: bool    // all other fields starting with b are booleans
    ...string       // all other fields must be a string
}

@eadlam
Copy link
Contributor

eadlam commented Jun 25, 2021

I tried going back a few versions:

$ go get cuelang.org/go/cmd/cue@v0.4.0-beta.2
go: downloading cuelang.org/go v0.4.0-beta.2
$ cue eval ./test.cue
missing ',' in struct literal:
    ./test.cue:5:8
expected '}', found 'EOF':
    ./test.cue:6:3
$ go get cuelang.org/go/cmd/cue@v0.4.0-beta.1
go: downloading cuelang.org/go v0.4.0-beta.1
$ cue eval ./test.cue
a: conflicting values string and {foo:string,["^i"]:int,["^b"]:bool,...,string} (mismatched types string and struct):
    ./test.cue:1:4
    ./test.cue:5:8
$ go get cuelang.org/go/cmd/cue@v0.4.0-alpha.2
go: downloading cuelang.org/go v0.4.0-alpha.2
$ cue eval ./test.cue
combining bulk optional fields with other fields deprecated as of v0.2.1: try running `cue fix` using CUE v0.2.2 on the file or module to upgrade:
    ./test.cue:6:1

It looks like this syntax is deprecated. I also tried cue fix with a few different versions (including v0.2.2) but nothing actually fixed it.

@lytedev
Copy link

lytedev commented Jun 28, 2021

FWIW, I achieved this with the following:

type: {
	field1: int
	[string]: ...string
}

@eadlam
Copy link
Contributor

eadlam commented Jun 28, 2021

@lytedev, what version are you on? This fails for me on v0.4.0:

$ cue version
cue version v0.4.0 linux/amd64
$ cat test.cue 
type: {
        field1: int
        [string]: ...string
}
$ cue eval test.cue 
expected operand, found '...':
    ./test.cue:3:12
expected '}', found 'EOF':
    ./test.cue:4:2

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#1065.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

@cueckoo cueckoo closed this as completed Jul 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants