Skip to content

Different behavior of resolution when using let value assignments #4244

@manuelscurti

Description

@manuelscurti

Hi there!

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

Tried on:
v0.16.0-alpha.1
v0.15.4
v0.15.3
v0.14.1
v0.13.2 <- in this version, the following bug does not reproduce

Does this issue reproduce with the latest stable release?

Yes

What did you do?

The following input YAML

components:
  - id: urn:dmb:cmp:testdomain:system:0:component:subcomponent
id: urn:dmb:cmp:testdomain:system:0:component

run against this CUE script:

import "strings"

let splits = strings.Split(id, ":")
let domain = splits[3]
let majorVersion = splits[5]

let componentIdPattern = "^urn:dmb:cmp:\(domain):[a-zA-Z0-9_\\-]+:\(majorVersion):[a-zA-Z0-9_\\-]+$"
let subcomponentIdPattern = "^urn:dmb:cmp:\(domain):[a-zA-Z0-9_\\-]+:\(majorVersion):[a-zA-Z0-9_\\-]+:subcomponent$"

#Id:               string & =~"^[a-zA-Z0-9:._\\-]+$"
#ComponentId: #Id & =~componentIdPattern 
#SubcomponentId:  #Id & =~subcomponentIdPattern 

#Workload: {
  id:                       #SubcomponentId
  ...
}

id!:                       #ComponentId
components: [#Workload]

with the following command:

$ cue vet file.yaml validator.cue

returns:

$ cue vet file.yaml validator.cue       
                                                                                                                                                                                                                
components.0.id: invalid value "urn:dmb:cmp:testdomain:system:0:component:subcomponent" (out of bound =~"^urn:dmb:cmp::[a-zA-Z0-9_\\-]+:0:[a-zA-Z0-9_\\-]+:subcomponent$"):
    ./not-working.cue:12:25
    ./descriptor.yaml:2:9
    ./not-working.cue:15:29

While instead, if I now switch the order of the id field in the file.yaml like this:

id: urn:dmb:cmp:testdomain:system:0:component
components:
  - id: urn:dmb:cmp:testdomain:system:0:component:subcomponent

and run again the same command, I get:

$ cue vet file.yaml validator.cue
$ 

no output, meaning validation went through.

What did you expect to see?

Same behavior, independently of the order of input fields.

The expected behavior was happening in v0.13.2

What did you see instead?

Different behavior

Thank you

Metadata

Metadata

Assignees

Labels

NeedsFixbisectedRegression which has been bisected to one change

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions