Skip to content

Commit 84ff93f

Browse files
Fix prototype parsing: allow trailing comma before semicolon
When calling a prototype function without parentheses, a trailing comma before the statement terminator was incorrectly treated as 'too many arguments'. In Perl, trailing commas are allowed: like $warning, qr/foo/, 'test',; # valid Perl The fix checks if the comma is followed by a statement terminator (;, EOF, or other expression terminators) and allows it in that case. This fixes t/conflicts.t in Dist::CheckConflicts which uses this pattern. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 8085636 commit 84ff93f

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/main/java/org/perlonjava/core/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public final class Configuration {
3333
* Automatically populated by Gradle/Maven during build.
3434
* DO NOT EDIT MANUALLY - this value is replaced at build time.
3535
*/
36-
public static final String gitCommitId = "3f00c2f24";
36+
public static final String gitCommitId = "80856361b";
3737

3838
/**
3939
* Git commit date of the build (ISO format: YYYY-MM-DD).

src/main/java/org/perlonjava/frontend/parser/PrototypeArgs.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,21 @@ static ListNode consumeArgsWithPrototype(Parser parser, String prototype, boolea
165165

166166
// Check for too many arguments without parentheses only if prototype expects 2+ args
167167
if (!hasParentheses && countPrototypeArgs(prototype) >= 2) {
168-
// If we see a comma after parsing all required args, there are too many
168+
// If we see a comma after parsing all required args, check if it's a trailing comma
169169
if (isComma(TokenUtils.peek(parser))) {
170-
throwTooManyArgumentsError(parser);
170+
// Consume the comma and check what follows
171+
int saveIndex = parser.tokenIndex;
172+
consumeCommas(parser);
173+
LexerToken nextToken = TokenUtils.peek(parser);
174+
// If followed by a statement terminator, it's a trailing comma (allowed)
175+
// Otherwise, it's too many arguments
176+
if (!Parser.isExpressionTerminator(nextToken) &&
177+
nextToken.type != LexerTokenType.EOF &&
178+
!nextToken.text.equals(")")) {
179+
throwTooManyArgumentsError(parser);
180+
}
181+
// Restore position - the comma will be handled by the caller
182+
parser.tokenIndex = saveIndex;
171183
}
172184
}
173185
}

0 commit comments

Comments
 (0)