Fix 'when' keyword parsing to respect 'use feature switch'#114
Merged
Conversation
The 'when' keyword should only be treated as a reserved keyword when
'use feature "switch"' is active. Without this feature enabled, 'when'
should be allowed as a bareword, particularly as a hash key.
Changes:
- StatementResolver.java: Add feature flag checks for 'given', 'when',
and 'default' keywords (similar to 'try' and 'class')
- ListParser.java: Add 'when' to the list of keywords that should be
treated as barewords when followed by '=>' (fat comma)
This fixes parsing errors in ExifTool's XMP.pm where 'when' is used
as a hash key: when => { %dateTimeInfo, Groups => { 2 => 'Time' } }
Tested with ExifTool 13.44 - XMP-related commands now parse correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
whenkeyword was being treated as a reserved keyword unconditionally, causing parser errors when used as a bareword hash key. This broke ExifTool's XMP.pm which useswhenas a hash key:The
whenkeyword should only be reserved whenuse feature 'switch'is active, similar to howtryandclassare handled.Changes
StatementResolver.java
given,when, anddefaultkeywordsuse feature 'switch'is enabledListParser.java (2 locations)
whento the list of keywords that should be treated as barewords when followed by=>(fat comma)and,or, andxorkeywordsTesting
Tested with ExifTool 13.44:
Before fix:
After fix:
-h,-json,-X,-listxnow proceed past the parser stagewhen => { ... }hash key is correctly recognized as a barewordImpact
This fix allows code that uses
whenas a bareword (hash keys, subroutine names, etc.) to work correctly when the switch feature is not enabled, matching standard Perl behavior.