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: repeated use of embedded disjunction results in "field not allowed" #2246

Closed
mvdan opened this issue Feb 6, 2023 · 2 comments
Closed

Comments

@mvdan
Copy link
Member

mvdan commented Feb 6, 2023

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

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

go version devel go1.21-25f5d9d4a2 Sat Feb 4 07:03:16 2023 +0000
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v3

Does this issue reproduce with the latest release?

No; the testscript below succeeds with v0.4.3.

What did you do?

exec cue-v0.4.3 export in.cue
cmp stdout stdout.golden

-- in.cue --
data: forms: [{
	fooID: "00-0000001"
}]

form1040: (#compute & {in: data}).out

#K1: {
	#_base: common: 3
	#FormFoo: {
		#_base
		fooID: string
	}
	#FormBar: {
		#_base
		barID: string
	}
	#Form: {
		#FormFoo | #FormBar
	}
}

#Input: {
	forms: [...#K1.#Form]
}

#summarizeReturn: {
	in:  #Input
	out: [ for k in in.forms { k.common } ]
}

#compute: {
	in:  #Input
	out: (#summarizeReturn & {"in": in}).out
}
-- stdout.golden --
{
    "data": {
        "forms": [
            {
                "fooID": "00-0000001"
            }
        ]
    },
    "form1040": [
        3
    ]
}

Somewhat reduced from @tmm1's code at https://github.com/tmm1/taxes.cue, where the original failure as of c7a9fefa2fa115b5d06fb952636a475823ff14a9 is:

$ make -C returns --always-make sample1
make: Entering directory '/home/mvdan/git/taxes2/returns'
make sample1.txt sample1.freefile
make[1]: Entering directory '/home/mvdan/git/taxes2/returns'
cue export cue: sample1.taxdata -fo sample1.taxdata.json
cue import -l data: -f sample1.taxdata.json
cue export --out cue compute.cue sample1.taxdata.cue -e '{"Form1040": Form1040}' > sample1.txt
in.k1s.0.partnershipEIN: field not allowed:
    ../return.cue:148:15
    ../k1.cue:4:10
    ../k1.cue:17:3
    ../k1.cue:18:3
    ../k1.cue:34:11
    ../k1.cue:35:3
    ../return.cue:19:8
    ../return.cue:19:11
    ../return.cue:46:8
    ../return.cue:146:14
    ../return.cue:147:14
    ../return.cue:148:41
    ./compute.cue:4:7
    ./compute.cue:6:40
    ./sample1.taxdata.cue:70:3
make[1]: *** [Makefile:20: sample1.txt] Error 1
rm sample1.taxdata.json sample1.taxdata.cue
make[1]: Leaving directory '/home/mvdan/git/taxes2/returns'
make: *** [Makefile:25: sample1] Error 2
make: Leaving directory '/home/mvdan/git/taxes2/returns'

What did you expect to see?

A successful testscript run.

What did you see instead?

> exec cue export in.cue
[stderr]
in.forms.0.fooID: field not allowed:
    ./in.cue:33:8
    ./in.cue:2:2
    ./in.cue:5:28
    ./in.cue:8:10
    ./in.cue:10:3
    ./in.cue:11:3
    ./in.cue:17:9
    ./in.cue:18:3
    ./in.cue:23:10
    ./in.cue:23:13
    ./in.cue:27:7
    ./in.cue:32:7
    ./in.cue:33:34
[exit status 1]

Worth noting that current CUE master, 02e19c8, also fails in the same way.

Here's a smaller reproducer, which again succeeds on v0.4.3 but fails on v0.5.0-beta.5:

exec cue export in.cue
cmp stdout stdout.golden

-- in.cue --
#FormFoo: fooID: string
#FormBar: barID: string
#Form: { #FormFoo | #FormBar }

data: {fooID: "123"}
out1: #Form & data
out2: #Form & out1
-- stdout.golden --
{
    "data": {
        "fooID": "123"
    },
    "out1": {
        "fooID": "123"
    },
    "out2": {
        "fooID": "123"
    }
}

Haven't bisected yet; will do so next.

@mvdan
Copy link
Member Author

mvdan commented Feb 6, 2023

Bisected via:

git bisect start v0.5.0-beta.5 v0.4.3
git bisect run bash -c 'go install ./cmd/cue && testscript ~/src/cue/repro-cmd.txtar'

The result is https://review.gerrithub.io/c/cue-lang/cue/+/549079.

@mvdan
Copy link
Member Author

mvdan commented Feb 6, 2023

cc @myitcv @mpvl; the regression seems to have been introduced while fixing #2209.

cueckoo pushed a commit that referenced this issue Mar 17, 2023
This seemed to cause more harm than good.
A fix for 2209 is planned for an upcoming evaluator
restructuring.

Fixes #2263
Fixes #2246

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ia6978abc59f1c1cbd371fd636e719859593f19e6
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551136
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
(cherry picked from commit b300e4f)
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551151
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