cuelang/cue

Parse error on default constraints (...type)

czaplicki opened this issue · 5 comments

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.

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
}

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.

FWIW, I achieved this with the following:

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

@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

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.