Skip to content

Return decl attrs from Value.Attribute and preserve embed YAML tags#4272

Open
jonas-meyer wants to merge 1 commit intocue-lang:masterfrom
jonas-meyer:feat/yaml-tag-embed
Open

Return decl attrs from Value.Attribute and preserve embed YAML tags#4272
jonas-meyer wants to merge 1 commit intocue-lang:masterfrom
jonas-meyer:feat/yaml-tag-embed

Conversation

@jonas-meyer
Copy link
Copy Markdown
Contributor

Summary

This PR fixes attribute lookup and YAML tag handling in two related places:

  • Value.Attribute now falls back to declaration attributes when no matching field attribute exists.
  • YAML encoding for embedded expressions now only overrides the node tag when @yaml(...,tag=...) is explicitly present.
  • Embedded bare ast.Expr values (emitted by Value.Syntax in some list/struct cases) are now handled consistently with EmbedDecl.
  • Added focused regression tests for declaration attributes on list elements and for preserving intrinsic tags on untagged embeds (for example !!binary).

Why

  • Some declaration attributes (including list element attrs) were not discoverable via Value.Attribute.
  • Embed encoding could clear intrinsic tags when no YAML tag argument was present, which changed output semantics.

Addresses #4269

Copilot AI review requested due to automatic review settings February 19, 2026 18:16
@jonas-meyer jonas-meyer requested a review from cueckoo as a code owner February 19, 2026 18:16
Signed-off-by: Jonas Meyer-Ohle <19151471+jonas-meyer@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances CUE's attribute handling and YAML encoding to support declaration attributes on embedded expressions and properly preserve YAML tags. The changes enable attributes on list elements (addressing issue #4269) and fix tag preservation for embedded values.

Changes:

  • Value.Attribute now falls back to declaration attributes when no field attribute exists, with field attributes taking precedence
  • YAML encoder preserves intrinsic node tags (like !!binary) when no explicit @yaml(,tag=...) is specified
  • Added support for bare ast.Expr in declaration lists (produced by Value.Syntax in some cases)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
cue/attribute.go Added fallback to declaration attributes in Value.Attribute method
cue/attribute_test.go Added comprehensive tests for list element attributes and attribute precedence
internal/encoding/yaml/encode.go Refactored tag extraction, added encodeEmbed function, and bare Expr handling
internal/encoding/yaml/encode_test.go Added tests for binary embed tag preservation and nested list element tags

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mvdan mvdan self-assigned this Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants