Skip to content

Commit 86baa2f

Browse files
fix: bare split without string argument now correctly uses $_ in eval'd code
When `split` was called without an explicit string argument (e.g., bare `split` or `split /PAT/`), it relied on the runtime fallback to getGlobalVariable("main::_"). This worked in JVM-compiled code but failed in bytecode-interpreted code (eval'd strings because the bytecode compiler compiled the empty argument list in scalar context, producing a spurious value that was then treated as the string to split. Fix: In parseSplit(), when no string argument is provided, explicitly add -A as the default argument in the AST. This is consistent with how other operators (defined, print, chomp) handle the -A default, and ensures both JVM and bytecode backends correctly resolve -A at runtime. This fixes ExifTool Writer test 6 (TimeCodes encoding), Geotag tests 2/4/9/10 (GPX parsing), and Geolocation test 5 (GPS track processing), all of which used bare inside eval'd code strings. ExifTool test results: 113/113 files pass, 600/600 tests pass (100%). Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> EOF )
1 parent b5078ad commit 86baa2f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
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 = "094672225";
36+
public static final String gitCommitId = "8a2462e01";
3737

3838
/**
3939
* Git commit date of the build (ISO format: YYYY-MM-DD).
@@ -48,7 +48,7 @@ public final class Configuration {
4848
* Parsed by App::perlbrew and other tools via: perl -V | grep "Compiled at"
4949
* DO NOT EDIT MANUALLY - this value is replaced at build time.
5050
*/
51-
public static final String buildTimestamp = "Apr 9 2026 17:10:40";
51+
public static final String buildTimestamp = "Apr 9 2026 17:23:07";
5252

5353
// Prevent instantiation
5454
private Configuration() {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,13 @@ static BinaryOperatorNode parseSplit(Parser parser, LexerToken token, int curren
911911
((OperatorNode) separator).operator = "quoteRegex";
912912
}
913913
}
914+
// If no string argument provided, default to $_
915+
// This is needed so both JVM and bytecode backends resolve $_ correctly
916+
// at runtime (the bytecode backend otherwise compiles the empty ListNode
917+
// in scalar context, producing a spurious value instead of $_ fallback)
918+
if (operand.elements.isEmpty()) {
919+
operand.elements.add(ParserNodeUtils.scalarUnderscore(parser));
920+
}
914921
return new BinaryOperatorNode(token.text, separator, operand, currentIndex);
915922
}
916923

0 commit comments

Comments
 (0)