Skip to content

evaluator: order of disjunction with default case seems to affect if comprehensions #2354

@prahaladramji

Description

@prahaladramji

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

cue version 0.5.0

go version go1.20.3
      -buildmode exe
       -compiler gc
       -trimpath true
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin

Does this issue reproduce with the latest stable release?

Yes

What did you do?

Given the below input, I would like to conditionally add the source.path field only if the source type _type is helm. However as you can see in the cue playground, even though X._type resolves to the right string inside the object the condition is incorrectly always matching helm.

I've also noticed that if you change the order of #ApplicationSourceType then it switches to match what's the first element, it’s like the order of this decides what the X._type is during the condition evaluation.

Application: X={
	spec: #ArgoApplicationSpec

	argoApplication: _Application & {_X: {
		spec:     X.spec
	}}
}

#ArgoApplicationSpec: source:  X={
	#ApplicationSourceType
	
	repoURL: string | *"https://github.com/foo/bar.git"
	targetRevision: string | *"main"

	// This has no meaning for Helm charts pulled directly from a Helm repo instead of git.
	if X._type != "helm" {
		path: *X._type | string
	}
}

#ApplicationSourceType:
	#SourceHelm |
	*#SourcePlugin
	
#SourceHelm: {
	_type: "helm"

	// helm specific config
	chart?: string

	helm: {
		// Values file as block file
		values?: string
	}
}

#SourcePlugin: {
	_type: "plugin"

	plugin: name?: string
}

_Application: {
	_X: _

	apiVersion: "argoproj.io/v1alpha1"
	kind:       "Application"

	metadata: namespace: "argocd"

	spec: source: _X.spec.source
}

What did you expect to see?

// if _type == "plugin"
// snip ...
source: {
  repoURL:        "https://github.com/foo/bar.git"
  targetRevision: "main"
  path: "plugin"
  plugin: {}
}

// snip ...

// if _type == "helm"
source: {
  repoURL:        "https://github.com/foo/bar.git"
  targetRevision: "main"
  helm: {}
}

What did you see instead?

// if _type == "plugin"
// snip ...
source: {
  repoURL:        "https://github.com/foo/bar.git"
  targetRevision: "main"
  path: "plugin"
  plugin: {}
}

// snip ...

// if _type == "helm"
source: {
  repoURL:        "https://github.com/foo/bar.git"
  targetRevision: "main"
  path: "helm"  // this shouldn't exist. 
  helm: {}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationdisjunctionsorderingBugs where the evaluator behaves differently depending on the order of fields, files, etc.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions