-
Notifications
You must be signed in to change notification settings - Fork 271
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
syntax: require all capsule values to implement marker interface #159
Comments
This makes two changes to fix the loss of the capsule type when a capsule value is converted to interface{}: 1. Structs with no River tags are no longer considered objects, and are now considered capsules. 2. Capsules can be converted if the Go types can be converted (such as assigning to an interface). Fixes grafana#3171. Related to #2547.
This makes two changes to fix the loss of the capsule type when a capsule value is converted to interface{}: 1. Structs with no River tags are no longer considered objects, and are now considered capsules. 2. Capsules can be converted if the Go types can be converted (such as assigning to an interface). Fixes grafana#3171. Related to #2547.
This makes two changes to fix the loss of the capsule type when a capsule value is converted to interface{}: 1. Structs with no River tags are no longer considered objects, and are now considered capsules. 2. Capsules can be converted if the Go types can be converted (such as assigning to an interface). Fixes #3171. Related to #2547.
This makes two changes to fix the loss of the capsule type when a capsule value is converted to interface{}: 1. Structs with no River tags are no longer considered objects, and are now considered capsules. 2. Capsules can be converted if the Go types can be converted (such as assigning to an interface). Fixes #3171. Related to #2547.
* river: fix capsule type loss when converting capsules to any This makes two changes to fix the loss of the capsule type when a capsule value is converted to interface{}: 1. Structs with no River tags are no longer considered objects, and are now considered capsules. 2. Capsules can be converted if the Go types can be converted (such as assigning to an interface). Fixes #3171. Related to #2547. * add missing changelog entry for #3204 Co-authored-by: erikbaranowski <[email protected]>
This issue has not had any activity in the past 30 days, so the |
Today, a Go value maps to a Alloy syntax capsule when any of the following are true:
interface{}
These rules were intended to make capsules feel "magical," have historically caused bugs (#2361, grafana/agent#2362) and are generally confusing to remember (I even had to look up the rules again just when writing this). The biggest issue with capsules is that capsule information can get lost if a type is casted to an
interface{}
, which can happen in many situations, including storing a capsule value in a*vm.Scope
as a variable.About a month ago I suggested changing these rules, and this issue is a more formal proposal of that suggestion.
Proposal
I propose that:
This proposal only affects developers building components on top of Alloy. Users of Alloy are not impacted.
The new API looks like this:
Example usage
Using the new proposed API above, the exports for
prometheus.remote_write
change to:The arguments type for types which accept capsules would also change:
Discussion
This proposal does come at a cost: developing against Alloy becomes slightly more tedious for capsule values, as it removes the magic introduced in the initial implementation.
However, the new rules are much easier to remember, and the new API should offload most of the tedium introduced by the new rules. This proposal even potentially makes Alloy easier to understand for developers reading the code, as it now must be explicit when something is being encapsulated.
The text was updated successfully, but these errors were encountered: