Fix char-selector parsing when the length is an expression containing a comma#520
Open
perazz wants to merge 2 commits into
Open
Fix char-selector parsing when the length is an expression containing a comma#520perazz wants to merge 2 commits into
perazz wants to merge 2 commits into
Conversation
Char_Selector.match splits the kind and length parts of a char-selector
on the top-level comma of the parenthesised expression that has been
processed by string_replace_map(). The length-first branch restored the
comma-hidden sub-expressions with repmap() before building the child
nodes, but the kind-first and positional branches did not. As a result a
length such as max(len, 0) was left as the placeholder max(F2PY_EXPR_
TUPLE_n), whose single argument makes the intrinsic argument-count check
report "Intrinsic 'MAX' expects at least 2 args but found 1" and reject
otherwise valid declarations, e.g.
character(kind=CK, len=max(len, 0)), pointer :: tmp
The failure only surfaces once all symbols in scope are resolved; while a
wildcard USE leaves them unresolved the same mis-parse silently leaks the
placeholder into the parse tree instead of raising.
Apply repmap() in the kind-first and positional branches so the length
and kind sub-expressions are restored, matching the length-first branch,
and extend the Char_Selector test with the comma-containing length forms.
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.
Summary
Char_Selector.matchsplits the KIND and LEN parts of achar-selectoron the top-level comma of the (placeholder-substituted) selector body. The length-first branch restored the placeholder-hidden sub-expressions withrepmap()before building the child nodes, but the kind-first and positional branches did not. A length whose value contains a comma — e.g. an intrinsic call — was therefore left as the internal placeholdermax(F2PY_EXPR_TUPLE_n), i.e. aMAXwith a single argument.Reproducer
On master this raises
FortranSyntaxError: Intrinsic 'MAX' expects at least 2 args but found 1.The failure only surfaces when every symbol in scope is resolved (all
use … , only:). If the module has a wildcardUSE,all_symbols_resolvedisFalse, the intrinsic arg-count check defers instead of raising, and the same mis-parse silently leaks theF2PY_EXPR_TUPLE_nplaceholder into the parse tree — socharacter(len=max(n,0), kind=ck)(length-first) always worked whilecharacter(kind=ck, len=max(n,0))did not.Fix
Call
repmap()on the length and kind sub-expressions in the kind-first and positional branches, matching the existing length-first branch. Adds regression cases totest_char_selector.Fixes #519.