Skip to content

Commit 82a5167

Browse files
fix: suppress spurious warnings in Text::CSV tests
1. ${q} ambiguity warning: suppress inside string interpolation (matching Perl 5, which only warns in code context) 2. Wide character in print: fix heredoc octet handling to convert Unicode chars back to UTF-8 bytes without use utf8, matching Perl 5 treatment of source bytes as Latin-1. Skips conversion for ISO-8859-1 source files (isByteStringSource). Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 791c0b1 commit 82a5167

3 files changed

Lines changed: 31 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 = "5d58cec3b";
36+
public static final String gitCommitId = "4aafb6057";
3737

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

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import org.perlonjava.frontend.lexer.LexerTokenType;
1111
import org.perlonjava.runtime.runtimetypes.PerlCompilerException;
1212

13+
import java.nio.charset.StandardCharsets;
1314
import java.util.ArrayList;
1415
import java.util.List;
1516

1617
import static org.perlonjava.frontend.parser.StringParser.parseRawString;
18+
import static org.perlonjava.runtime.perlmodule.Strict.HINT_UTF8;
1719

1820
public class ParseHeredoc {
1921
static OperatorNode parseHeredoc(Parser parser, String tokenText) {
@@ -212,6 +214,16 @@ else if (currentIndex >= tokens.size() ||
212214
String string = content.toString();
213215
if (CompilerOptions.DEBUG_ENABLED) parser.ctx.logDebug("Final heredoc content: <<" + string + ">>");
214216

217+
// Without `use utf8`, convert Unicode chars back to UTF-8 byte values,
218+
// matching Perl 5's treatment of source bytes as Latin-1/octets.
219+
// Skip if source is already ISO-8859-1 (isByteStringSource) — chars already
220+
// represent raw byte values and need no conversion.
221+
if (!parser.ctx.symbolTable.isStrictOptionEnabled(HINT_UTF8)
222+
&& !parser.ctx.compilerOptions.isUnicodeSource
223+
&& !parser.ctx.compilerOptions.isByteStringSource) {
224+
string = convertToOctets(string);
225+
}
226+
215227
// Rewrite the heredoc node, according to the delimiter
216228
Node operand = null;
217229
switch (delimiter) {
@@ -293,4 +305,19 @@ public static void restoreHeredocStateIfNeeded(Parser parser, List<OperatorNode>
293305
parser.getHeredocNodes().addAll(savedHeredocNodes);
294306
}
295307
}
308+
309+
/**
310+
* Convert a Unicode string back to UTF-8 byte values.
311+
* Without `use utf8`, Perl treats source bytes as Latin-1/octets.
312+
* Since Java reads source files as UTF-8 and decodes multi-byte sequences
313+
* into single characters, we need to reverse this for Perl compatibility.
314+
*/
315+
private static String convertToOctets(String str) {
316+
byte[] utf8Bytes = str.getBytes(StandardCharsets.UTF_8);
317+
StringBuilder octetString = new StringBuilder(utf8Bytes.length);
318+
for (byte b : utf8Bytes) {
319+
octetString.append((char) (b & 0xFF));
320+
}
321+
return octetString.toString();
322+
}
296323
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,9 @@ public static Node parseBracedVariable(Parser parser, String sigil, boolean isSt
925925
if (TokenUtils.peek(parser).text.equals("}")) {
926926
TokenUtils.consume(parser, LexerTokenType.OPERATOR, "}");
927927

928-
// Issue ambiguity warning if needed
929-
if (isAmbiguous) {
928+
// Issue ambiguity warning if needed (not inside string interpolation,
929+
// matching Perl 5 which only warns in code context)
930+
if (isAmbiguous && !isStringInterpolation) {
930931
String accessType = "";
931932
if (operand instanceof BinaryOperatorNode binOp) {
932933
if (binOp.operator.equals("[")) {

0 commit comments

Comments
 (0)