Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unchecked constraint with v2 and v3 #3711

Open
loisch opened this issue Jan 29, 2025 · 1 comment
Open

unchecked constraint with v2 and v3 #3711

loisch opened this issue Jan 29, 2025 · 1 comment
Assignees
Labels
NeedsInvestigation Triage Requires triage/attention

Comments

@loisch
Copy link

loisch commented Jan 29, 2025

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

0.12-rc1

$ cue version
ue version v0.12.0-8dc16dd

go version go1.22.1
      -buildmode exe
       -compiler gc
        -ldflags -X cuelang.org/go/cmd/cue/cmd.version=v0.12.0-8dc16dd
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin
             vcs git
    vcs.revision 8dc16dd330172af44bd376d3f51b32c96e56be81
        vcs.time 2025-01-28T14:37:26Z
    vcs.modified false
cue.lang.version v0.12.0

Does this issue reproduce with the latest stable release?

Yes and no. Old and new evaluator both produce the same result with version 0.11.1 but still the test doesn't fail (as it should, in my opinion). The new evaluator in version 0.11.1 produces the same result as the old evaluator.

What did you do?

env CUE_EXPERIMENT=evalv3=1
exec cue vet out.cue
exec cue export out.cue -e test1
cmp stdout foo.golden
env CUE_EXPERIMENT=evalv3=0
exec cue vet out.cue
exec cue export out.cue -e test1
cmp stdout impossible.golden
-- foo.golden --
"foo"
-- impossible.golden --
"impossible"
-- out.cue --
#TypeA: string | {foo: int}

#fun1: {
	in: #TypeA
	out: [
		// either `in` is a string
		if (in & string) != _|_ {
			in
		},
		// or `in` is has field `foo`
		if in.foo != _|_ {
			"foo"
		},
		"impossible" // in & #TypeA != _|_ !!
	][0]
}


//ab: #TypeA ??
ab: {
	foo: 1
	bar: "15"
}

test1: {
	let call = #fun1 & { in: ab }
	call.out
}

What did you expect to see?

A failing test. cue vet should not accept this program because #fun1.in must unify with #TypeA but ab does not unify with #TypeA. Also #fun1.in is used it the calculation of the result (call.out), so it influences the result and it should have _|_ as value and thus call.out should be _|_, too. If my intuition is wrong and this program is indeed correct it should still have the same result in both evaluators.

What did you see instead?

A passing test showing that old and new evaluator produce different results and that a validity constraint (in: #TypeA) is being ignored.

@loisch loisch added NeedsInvestigation Triage Requires triage/attention labels Jan 29, 2025
@myitcv
Copy link
Member

myitcv commented Jan 30, 2025

@loisch thanks for raising this. Taking a look now.

@myitcv myitcv self-assigned this Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Triage Requires triage/attention
Projects
None yet
Development

No branches or pull requests

2 participants