Skip to content

Conversation

@nwt
Copy link
Member

@nwt nwt commented Oct 3, 2025

Casting of complex types is implemented in runtime/sam/expr/shaper.go.
Replace it with a new implementation in
runtime/sam/expr/function/cast.go with these differences:

  • Always generates a structured error when casting fails

  • Preserves target type field order when casting records

  • Able to cast maps

  • More maintainable

Fixes #2894
Fixes #4315
Closes #5168
Closes #6023

Casting of complex types is implemented in runtime/sam/expr/shaper.go.
Replace it with a new implementation in
runtime/sam/expr/function/cast.go with these differences:

* Preserves target type field order when casting records

* Able to cast maps

* More maintainable
@nwt nwt requested a review from a team October 3, 2025 20:37
}
return c.cast(from, typ)
}
return c.sctx.WrapError("cannot cast to "+sup.FormatValue(to), from)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe an error here about the second argument when the second arg isn't a type or string, e.g., instead of

; super -c "cast(1,2)"
error({message:"cannot cast to 2",on:1})

maybe

error({message:"cast target must be a type or name of type",on:2})

@nwt nwt merged commit 4f44a79 into main Oct 6, 2025
5 checks passed
@nwt nwt deleted the cast branch October 6, 2025 11:39
@nwt nwt mentioned this pull request Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants