cue: cue: ResolveReferences option not work in method "Syntax"
_Originally opened by @leejanee in https://github.com/cuelang/cue/issues/867_
What version of CUE are you using (cue version)?
$ cue version v0.3.0-beta.8
What did you do?
The code is as follows
var src =`
t: {name: string}
output: [...t]
`
var r cue.Runtime
inst,_:=r.Compile("-",src)
ct,_:=format.Node(inst.Value().Lookup("output").Syntax(cue.ResolveReferences(true)))
fmt.Println(string(ct))
After running the code,I get
[...t]
But import the v0.2.2 version, The result is as follows
[...{
name: string
}]
and, This is what i expected
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 39 (21 by maintainers)
Commits related to this issue
- internal/core/export: keep open lists open When no default resolution is selected. In the future we may make lists open by default if they are not in definitions (like with structs). Issue #867 Si... — committed to cue-lang/cue by mpvl 3 years ago
- internal/core/export: support ResolveReferences Note that this does not fully implement what was requested in #867, but this may be sufficient. Feedback welcome. Issue #867 Change-Id: I54db0a623df6... — committed to cue-lang/cue by mpvl 3 years ago
- internal/core/export: keep open lists open When no default resolution is selected. In the future we may make lists open by default if they are not in definitions or within the scope of a close built... — committed to cue-lang/cue by mpvl 3 years ago
- cue: support ResolveReferences Note that this does not fully implement what was requested in #867, but this may be sufficient. Feedback welcome. Issue #867 Change-Id: I54db0a623df69a6bfa1cc164c2903... — committed to cue-lang/cue by mpvl 3 years ago
- internal/core/export: keep open lists open When no default resolution is selected. In the future we may make lists open by default if they are not in definitions or within the scope of a close built... — committed to cue-lang/cue by mpvl 3 years ago
- cue: support ResolveReferences Note that this does not fully implement what was requested in #867, but this may be sufficient. Feedback welcome. Issue #867 Change-Id: I54db0a623df69a6bfa1cc164c2903... — committed to cue-lang/cue by mpvl 3 years ago
- internal/core/export: keep open lists open When no default resolution is selected. In the future we may make lists open by default if they are not in definitions or within the scope of a close built... — committed to jlongtine/cue by mpvl 3 years ago
- cue: support ResolveReferences Note that this does not fully implement what was requested in #867, but this may be sufficient. Feedback welcome. Issue #867 Change-Id: I54db0a623df69a6bfa1cc164c2903... — committed to jlongtine/cue by mpvl 3 years ago
- internal/core/export: hoist reference logic In preperation for implementing the self contained feature. Issue #867 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Change-Id: If71e89ab6ea18a1e7... — committed to cue-lang/cue by mpvl 2 years ago
- tools/fix: remove rewriting support for old-style let This has been deprecated for a long time and we soon want to support aliases for embeddings. Issue #867 Signed-off-by: Marcel van Lohuizen <mpv... — committed to cue-lang/cue by mpvl 2 years ago
- internal/core/export: move tests to subdir This allows us to put tests for the self-contained rewriter, which are very different, to be put in a separate subdir. Issue #867 Signed-off-by: Marcel va... — committed to cue-lang/cue by mpvl 2 years ago
- internal/core/export: pass Environment And adjust it in sync. This is in line with how dep uses Environment: for internal structures it just uses an "empty" Vertex, meaning values cannot be evaluated... — committed to cue-lang/cue by mpvl 2 years ago
- internal/core/export: hoist FieldReference logic This later can be used for DynamicReferences as well. Needed for Issue #867 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Change-Id: Ie867eda... — committed to cue-lang/cue by mpvl 2 years ago
- internal/core/export: fix bug exporting dynamic references The implementation was written for pattern constraints, which only allow aliases within the fields. However, dynamic field aliases are also ... — committed to cue-lang/cue by mpvl 2 years ago
- internal/core/export: refactor uniqueFeature - clean up code - avoid introducing new label unnecessarily - allow code to be reused for different sets of features Used for Issue #867 Signed-off-by: ... — committed to cue-lang/cue by mpvl 2 years ago
- internal/core/export: simplify dynamic labels This is now possible because of the passed down evaluator. Note that most of it is actually left unimplemented as revealing a new field may cause other ... — committed to cue-lang/cue by mpvl 2 years ago
- internal/core/export: cleanup of initialization and finalize This makes the logic for self-containment a bit nicer down the line. Issue #867 Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Chan... — committed to cue-lang/cue by mpvl 2 years ago
- internal/core/export: implement self-contained algo for export The ensures that all references pointing outside an exported value (in Def) are either inlined or included as let, the latter to avoid ... — committed to FogDong/cue by mpvl 2 years ago
- internal/core/export: enhancements for import inlining - never inline core packages (see comments) - mangle hidden fields of packages Issue #867 Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> ... — committed to FogDong/cue by mpvl 2 years ago
- internal/core/export: don't inline for errors This makes it easier to see where errors originally came from, as a value that is not inlined is marked with the original path. - tighten comprehension ... — committed to FogDong/cue by mpvl 2 years ago
Here you can find a first implementation: https://review.gerrithub.io/c/cue-lang/cue/+/541464/3.
There is a new test set where you can see some of the logic behind it.
Note that the current implementation assumes that whenever you pass a struct that is not the root, this behavior is desirable. I still need to distinguish between also closing over import references or not. So my current thinking is that there will be
SelfContainedoption that is needed to expand references to imported packages (maybeExpandImportsis a better name). But that otherwise the use of the option is not necessary.Very Good, It seems to satisfy our usage, next I will try to upgrade the cue version used in our project
KubeVela. Also very much looking forward to the GA version.It indeed solve it, to some extent, but please see my answer there. It may not solve it how you want it, but at least in principle it is able to solve it so it will not be hard to iterate towards something workable.
@leejanee @wonderflow please see
v0.4.1-beta.6(release notes to follow) as a first cut of a solution to resolve this issue. Please let us know what works/doesn’t work for you.@wonderflow @fogdong just following up on the issues linked from above:
Replied in the issue. I’m not clear there is actually an issue here, just a bogus error value being reported. Perhaps you can confirm my understanding in the issue?
Commented in response to @mpvl. I think my conversation with @FogDong helped move this forward, but please let me know if there are any outstanding questions/issues.
Commented. You can work around this for now by casting a value of
*cue.Contextto*cue.Runtime.We use
cuelangto render kubernetes resources in kubevela. This process is divided into two stages:ast.Nodeformat.For example:
First of all, the template on the user side has a consistent format, for example as follows:
the
parameteris user input, and theresourceis the desired resource definition.I expect that the cue execution result on the user side can be recompiled on the server side again.
Morning, can we expect this fix in the next version? or is this blocked somehow? A new version of culang would improve the writing of templates in Kubevela very much 😃