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

evaluator: closedness not applied to optional field #1830

Closed
myitcv opened this issue Aug 2, 2022 · 1 comment
Closed

evaluator: closedness not applied to optional field #1830

myitcv opened this issue Aug 2, 2022 · 1 comment
Assignees
Labels
evalv3-win Issues resolved by switching from evalv2 to evalv3 NeedsInvestigation

Comments

@myitcv
Copy link
Member

myitcv commented Aug 2, 2022

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

$ cue version
cue version v0.0.0-20220801114602-5a08d2f7a9a7

       -compiler gc
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
             vcs git
    vcs.revision 5a08d2f7a9a7595def05c5486cbb5276e66391cb
        vcs.time 2022-08-01T11:46:02Z
    vcs.modified false

Does this issue reproduce with the latest release?

Yes

What did you do?

! exec cue eval .
stderr 'x1.age1: field not allowed'
stderr 'x2.age2: field not allowed'

-- x.cue --
package x

#x: {
	y: {
		z?: {
			name: string
		}
	}
}

egs: {
	x1: (#x & {y: z: _}).y.z & {
		name: "blah"
		age1: 5
	}
	x2: (#x.y & {z: _}).z & {
		name: "blah"
		age2: 5
	}
}

What did you expect to see?

Test to pass

What did you see instead?

> ! exec cue eval .
[stdout]
#x: {
    y: {}
}
egs: {
    x1: {
        name: "blah"
        age1: 5
    }
    x2: {
        name: "blah"
        age2: 5
    }
}
FAIL: /tmp/testscript2385917320/repro.txt/script.txt:1: unexpected command success

What's interesting is that the following succeeds, as expected:

exec cue def x.cue --inline-imports -e egs -o out.cue
cmp out.cue out.cue.golden
! exec cue eval out.cue
stderr 'x1.age1: field not allowed'
stderr 'x2.age2: field not allowed'

-- x.cue --
package x

#x: {
	y: {
		z?: {
			name: string
		}
	}
}

egs: {
	x1: (#x & {y: z: _}).y.z & {
		name: "blah"
		age1: 5
	}
	x2: (#x.y & {z: _}).z & {
		name: "blah"
		age2: 5
	}
}
-- out.cue.golden --
x1: Z.#x & {
	name: "blah"
	age1: 5
}
x2: Z_1.#x & {
	name: "blah"
	age2: 5
}

//cue:path: y.z
let Z = {
	#x: {
		name: string
	}
}

//cue:path: z
let Z_1 = {
	#x: {
		name: string
	}
}
@mvdan
Copy link
Member

mvdan commented May 21, 2024

This is another one that's fixed in the new evaluator :) It tracks closedness in a different way, so that must have fixed this bug. Regression test incoming.

@mvdan mvdan self-assigned this May 21, 2024
cueckoo pushed a commit that referenced this issue May 21, 2024
In the added test case, the struct with the "name" field is closed
as it is referenced via the parent definition,
so trying to insert new fields via unification should fail.

The new evaluator fixes this case, as can be seen in the eval diff.
It seems the old evaluator wasn't tracking closedness properly here.

Closes #1830.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I9f96baa377f2f5cd5ab66491f1e3ca112cd33ab9
@mvdan mvdan added the evalv3-win Issues resolved by switching from evalv2 to evalv3 label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
evalv3-win Issues resolved by switching from evalv2 to evalv3 NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

2 participants