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

evalv3: "field not allowed" regression inside an if comprehension #3483

Closed
mvdan opened this issue Oct 8, 2024 · 0 comments
Closed

evalv3: "field not allowed" regression inside an if comprehension #3483

mvdan opened this issue Oct 8, 2024 · 0 comments

Comments

@mvdan
Copy link
Member

mvdan commented Oct 8, 2024

Reduced from https://github.com/tmm1/taxes.cue/blob/c7a9fefa2fa115b5d06fb952636a475823ff14a9/return.cue#L215, which is correctly defined in the #Form1040 schema.

As of b51914f:

env CUE_EXPERIMENT=evalv3=0
exec cue vet -c=false in.cue

env CUE_EXPERIMENT=evalv3=1
exec cue vet -c=false in.cue

-- in.cue --
#Schema: {
	schemaField: number
}

out1: {
	out2: #Schema & {
		if false {
			schemaField: 3
		}
	}
}

I would expect this testscript to pass - the old and new evaluator should agree that the above is valid CUE. However:

> env CUE_EXPERIMENT=evalv3=0
> exec cue vet -c=false in.cue
> env CUE_EXPERIMENT=evalv3=1
> exec cue vet -c=false in.cue
[stderr]
out1.out2.schemaField: field not allowed:
    ./in.cue:8:17
    ./in.cue:2:2
    ./in.cue:8:4
[exit status 1]
FAIL: f1040.cue:5: unexpected command failure

The error seems wrong; we are only closing one struct here, #Schema, and it does define and allow the schemaField field.

Note that the evalv3 regression goes away if I swap if false for if true. Similarly, if I swap schemaField: 3 for an embedding like { schemaField: 3 }, the error also goes away. Both seem supporting evidence for my reasoning above.

@mvdan mvdan added the evaluator label Oct 8, 2024
@cueckoo cueckoo closed this as completed in 89acced Oct 9, 2024
vanhtuan0409 pushed a commit to anduintransaction/cue that referenced this issue Oct 15, 2024
Closedness was reported incorrectly for the following case,
because when handling comprehensions one should look at
the arcType of the closedcontext, not the Vertex.
In fact, the Vertex arc MUST always be decided by the time
the closeContext finishes. Add an assertion to this effect.

	out1: out2: #Schema & {
		if false {
			schemaField: 3
		}
	}

Fixes cue-lang#3483

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I21e3bf45cf765940d6106d7ae671ea2ace985593
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202419
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant