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

Confusion about optional value in evaluating #1215

Closed
chivalryq opened this issue Aug 18, 2021 · 3 comments
Closed

Confusion about optional value in evaluating #1215

chivalryq opened this issue Aug 18, 2021 · 3 comments
Labels
FeatureRequest New feature or request

Comments

@chivalryq
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Here is an simple example

parameter: {
	a?: int
}
output: {
	output_a?: parameter.a
	y:  1
}

parameter: {
	a: 1
}
// export result
//{
//    "parameter": {
//        "a": 1
//    },
//    "output": {
//        "y": 1
//    }
//}

IMO output_a should be 1. I'm new to cuelang and did I miss something? Is this a feature or bug?

thx for your explanation!

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@chivalryq chivalryq added FeatureRequest New feature or request Triage Requires triage/attention labels Aug 18, 2021
@seh
Copy link
Contributor

seh commented Aug 18, 2021

I understand the desire. At present, at least, CUE doesn't work like that. Instead, you need to write the following:

parameter: {
	a?: int
}
output: {
	if parameter.a != _|_ {
		output_a: parameter.a
	}
	y:  1
}

Note that the comparison against bottom (_|_) is imprecise. See #822 for the proposed numexists and numconcrete builtin functions that would be more precise alternatives.

@verdverm
Copy link

verdverm commented Aug 18, 2021

Given:

p: a: 1
o: a?: p.a

I would expect o: a: 1 in the result, however it is o: {} which is definitely counter intuitive or a bug.

This could be simplified to

p: 1
o: a?: p

which results in o: {}

This seems more so like a bug or very counterintuitive

@myitcv
Copy link
Member

myitcv commented Aug 21, 2021

@chivalryq - @seh is right to point you towards #822, in particular the section regarding printing modes. Because under that proposal, the need for ? largely disappears, and instead manifestation of values becomes a function of concreteness.

@verdverm this is behaving as expected for optional fields.

I'm going to close this as working as intended, because the issues raised here are covered by #822.

@myitcv myitcv closed this as completed Aug 21, 2021
@myitcv myitcv removed the Triage Requires triage/attention label Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants