Skip to content

evaluator: 0.5 regression with disjunctions and comprehensions #2209

@slewiskelly

Description

@slewiskelly

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

$ cue version
cue version v0.5.0-beta.2

       -compiler gc
        -ldflags -s -w
     CGO_ENABLED 0
          GOARCH arm64
            GOOS darwin

Does this issue reproduce with the latest release?

Yes. git bisect pinpoints to 748a685 (https://review.gerrithub.io/c/cue-lang/cue/+/529524).

What did you do?

cue export with the following configuration snippet.

A similar, but larger configuration has been used for several months using v0.4.3. Upon evaluating v0.5.0, failures are encountered.

Reproducer
Foo: #Abstract & {spec: foo: {}}
Bar: #Abstract & {spec: bar: {}}

#Abstract: X={
	spec: _#Spec

	resource: _Thing & {_X: spec: X.spec}
}

_#Spec: *_#SpecFoo | _#SpecBar

_#SpecFoo: {
	foo: {
		min: int | *10
		max: int | *20
	}
}

_#SpecBar: {
	bar: {
		min: int | *30
		max: int | *40
	}
}

_Thing: #Constrained & {
	_X: _

	spec: {
		if _X.spec.foo != _|_ {
			minFoo: _X.spec.foo.min
			maxFoo: _X.spec.foo.max
		}

		if _X.spec.bar != _|_ {
			minBar: _X.spec.bar.min
			maxBar: _X.spec.bar.max
		}
	}
}

#Constrained: #Base & {
	spec: {
		minFoo:  int | *10
		maxFoo:  int | *20
		minBar?: null
		maxBar?: null
	} | {
		minBar:  int | *30
		maxBar:  int | *40
		minFoo?: null
		maxFoo?: null
	}

	spec: *{
		fuga?: null
	} | {
		hoge?: null
	}
}

#Base: {
	spec: {
		minFoo?: null | int
		maxFoo?: null | int
		minBar?: null | int
		maxBar?: null | int

		hoge?: null | bool
		fuga?: null | bool
	}
}

Forgive the length of the reproducer. I tried to maintain the spirit of what is trying to be accomplished, while removing as much as possible.

What did you expect to see?

Result v0.4.3
{
    "Foo": {
        "spec": {
            "foo": {
                "min": 10,
                "max": 20
            }
        },
        "resource": {
            "spec": {
                "minFoo": 10,
                "maxFoo": 20
            }
        }
    },
    "Bar": {
        "spec": {
            "bar": {
                "min": 30,
                "max": 40
            }
        },
        "resource": {
            "spec": {
                "minBar": 30,
                "maxBar": 40
            }
        }
    }
}

What did you see instead?

Result v0.5.0
Bar.resource.spec: 6 errors in empty disjunction:
Bar.resource.spec.minBar: 2 errors in empty disjunction:
Bar.resource.spec.minBar: conflicting values null and int (mismatched types null and int):
    ./test.cue:2:6
    ./test.cue:7:12
    ./test.cue:26:9
    ./test.cue:42:15
    ./test.cue:46:12
    ./test.cue:66:19
Bar.resource.spec.minFoo: 2 errors in empty disjunction:
Bar.resource.spec.minFoo: conflicting values null and 10 (mismatched types null and int):
    ./test.cue:2:6
    ./test.cue:7:12
    ./test.cue:14:15
    ./test.cue:30:3
    ./test.cue:31:12
    ./test.cue:51:12
Bar.resource.spec.minFoo: conflicting values null and int (mismatched types null and int):
    ./test.cue:2:6
    ./test.cue:7:12
    ./test.cue:26:9
    ./test.cue:42:15
    ./test.cue:51:12
    ./test.cue:64:19
Bar.resource.spec.minBar: undefined field: min:
    ./test.cue:36:24

I can make it work with by making (at least) either of the following two changes:

  1. Writing the equivalent using a combination of a conjunction and disjunction, without the use of additional definitions.
Diff
@@ -2,10 +2,18 @@ Foo: #Abstract & {spec: foo: {}}
 Bar: #Abstract & {spec: bar: {}}

 #Abstract: X={
-	spec: _#Spec
-
 	resource: _Thing & {_X: spec: X.spec}
-}
+} & (*{
+	spec: foo: {
+		min: int | *10
+		max: int | *20
+	}
+} | {
+	spec: bar: {
+		min: int | *30
+		max: int | *40
+	}
+})

 _#Spec: *_#SpecFoo | _#SpecBar
  1. Removing a disjunction within the #Constrained definition
Diff
@@ -51,12 +51,6 @@ _Thing: #Constrained & {
 		minFoo?: null
 		maxFoo?: null
 	}
-
-	spec: *{
-		fuga?: null
-	} | {
-		hoge?: null
-	}
 }

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions