Move type alias attribute validation to parser #1916
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1898
This just moves the logic from #1890 to an allow list of types that can have attributes in the parser so that we avoid a hacky check. I don't really like checks in the parser like this very much, but since this fixes a weird validation I think it's ok.
The rest of this is just on what I chose not to do, which may be interesting depending what you think. That's all on the
topic/etyp/cleanup-parsing-attributes
branch now.My initial impression was that attributes should apply to types, then remove
opt_attributes
from thetype_decl
. That technically seems possible, but I'd hardly call it a cleanup. It essentially requires duplicating the attributes logic into manyUnqualifiedType
implementations (struct, enum, etc. but also likeexception
).This goes into hilti world, so now the hilti parser needs changed, and once you get there all bets are off. You can use the
&on-heap
attribute on a lot of things, which is a declaration attribute. That's because what that means for a type is just that it becomes avalue_ref
. So now we think about these attributes on declarations as type attributes, which just doesn't intuitively make sense. I guess you could try to have both, but since there isn't a great distinction from syntax alone, it's hard.There's a fair bit more, but I think the attribute changes should try to stay minimal unless we're going to really rework them, which I kind of advocated for in the issue this is closing... but that's a big change :)
As an added point: The branch I did that on had some positive consequences - tests like
unsupported_attribute.spicy
flag an error on an attribute, but the range given does not even encompass the attribute. I added a continuation of #1899 for unit'ssetAttributes
for that case just as an added bonus.