Skip to content
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

[Backport 7.x] Accept UnaryMinusExpression as class parameter type #9272

Merged
merged 3 commits into from
Feb 29, 2024

Conversation

github-actions[bot]
Copy link

Description

Backport of #9269 to 7.x.

@puppetlabs-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

Previously, class parameters of the form `Integer[-1] $param` would fail
compilation, because the value `-1` was lexed as a UnaryMinusExpression
containing a LiteralInteger. And since the LiteralEvaluator didn't implement the
`literal_UnaryMinusExpression` method, the visitor called `literal_XXX` for each
ancestor class, until reaching `literal_Object`, which always raises.

This adds the `literal_UnaryMinusExpression` method and returns -1 times
the expression it wraps. This is similar to how the TypeParser interprets
UnaryMinusExpressions[1].

[1] https://github.com/puppetlabs/puppet/blob/8.5.0/lib/puppet/pops/types/type_parser.rb#L161
@joshcooper joshcooper closed this Feb 29, 2024
@joshcooper joshcooper reopened this Feb 29, 2024
If strict is off, the issue will be ignored. If strict is warning, then a
warning will be reported, but compilation will continue:

    Warning: The parameter '$i' must be a literal type, not a Puppet::Pops::Model::AccessExpression

If strict is error, then compilation will fail.
The "undef to nil" test is special because otherwise the value nil when
interpolated in the name of the test results in empty string.
@joshcooper joshcooper merged commit b0f8ccf into 7.x Feb 29, 2024
12 checks passed
@joshcooper joshcooper deleted the backport-9269-to-7.x branch February 29, 2024 21:52
@joshcooper joshcooper added the bug Something isn't working label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants