Symbolic macros do not check allowed attribute values
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
Both rules and symbolic macros support `attr.string()` with a `values` parameter. However, only rules raise an error if an unlisted value is specified.
### Which category does this issue belong to?
Loading API
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
`defs.bzl`:
```
def _my_macro_impl(name, bar, visibility):
native.filegroup(name = name)
my_macro = macro(
implementation = _my_macro_impl,
attrs = {
"bar": attr.string(
values = ["a", "b", "c"],
),
},
)
def _my_rule_impl(ctx):
pass
my_rule = rule(
implementation = _my_rule_impl,
attrs = {
"bar": attr.string(
values = ["a", "b", "c"],
),
},
)
```
`BUILD.bazel`:
```
load("defs.bzl", "my_macro", "my_rule")
my_macro(
name = "a_macro_target",
bar = "d",
)
my_rule(
name = "a_rule_target",
bar = "d",
)
```
The following error is reported for `a_rule_target` but not for `a_macro_target`:
`invalid value in 'bar' attribute: has to be one of 'a', 'b', or 'c' instead of 'd'`
### Which operating system are you running Bazel on?
Linux
### What is the output of `bazel info release`?
release 8.2.1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.