Skip to content

Commit 49baece

Browse files
authored
Merge pull request #502 from fglock/fix/overload-diamond-operator
fix: dispatch <> overload on blessed objects instead of warning
2 parents 0d83f6c + ac320f5 commit 49baece

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

docs/reference/feature-matrix.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ The `:encoding()` layer supports all encodings provided by Java's `Charset.forNa
663663
- ✅ Implemented: `<=>`, `cmp`, `<`, `<=`, `>`, `>=`, `==`, `!=`, `lt`, `le`, `gt`, `ge`, `eq`, `ne`.
664664
- ✅ Implemented: `qr`.
665665
- ✅ Implemented: `+=`, `-=`, `*=`, `/=`, `%=`.
666-
- ❌ Missing: `++`, `--`, `=`, `<>`.
666+
- ✅ Implemented: `<>`.
667+
- ❌ Missing: `++`, `--`, `=`.
667668
- ❌ Missing: `&`, `|`, `^`, `~`, `<<`, `>>`, `&.`, `|.`, `^.`, `~.`, `x`, `.`.
668669
- ❌ Missing: `**=`, `<<=`, `>>=`, `x=`, `.=`, `&=`, `|=`, `^=`, `&.=`, `|.=`, `^.=`.
669670
- ❌ Missing: `-X`.

src/main/java/org/perlonjava/backend/bytecode/OpcodeHandlerExtended.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,13 @@ public static int executeReadline(int[] bytecode, int pc, RuntimeBase[] register
837837
RuntimeScalar fh = (RuntimeScalar) registers[fhReg];
838838
// Diamond operator <> passes a plain string scalar (not a glob/IO).
839839
// Route to DiamondIO.readline which manages @ARGV / STDIN iteration.
840+
// But blessed objects may have <> overload, so route those to Readline.
840841
if (fh.getRuntimeIO() == null) {
841-
registers[rd] = DiamondIO.readline(fh, ctx);
842+
if (RuntimeScalarType.blessedId(fh) < 0) {
843+
registers[rd] = Readline.readline(fh, ctx);
844+
} else {
845+
registers[rd] = DiamondIO.readline(fh, ctx);
846+
}
842847
} else {
843848
registers[rd] = Readline.readline(fh, ctx);
844849
}

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 = "7bf93f44f";
36+
public static final String gitCommitId = "0d83f6c7e";
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 13 2026 14:15:09";
51+
public static final String buildTimestamp = "Apr 13 2026 14:49:28";
5252

5353
// Prevent instantiation
5454
private Configuration() {

src/main/java/org/perlonjava/runtime/operators/Readline.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ public static RuntimeBase readline(RuntimeScalar fileHandle, int ctx) {
2020
RuntimeIO fh = fileHandle.getRuntimeIO();
2121

2222
if (fh == null) {
23+
// Check for <> overload before warning about unopened filehandle
24+
int blessId = RuntimeScalarType.blessedId(fileHandle);
25+
if (blessId < 0) {
26+
OverloadContext overloadCtx = OverloadContext.prepare(blessId);
27+
if (overloadCtx != null) {
28+
RuntimeScalar result = overloadCtx.tryOverload("(<>", new RuntimeArray(fileHandle));
29+
if (result != null) {
30+
return result;
31+
}
32+
}
33+
}
34+
2335
// Perl warns and returns undef for unopened filehandle, doesn't die
2436
WarnDie.warn(new RuntimeScalar("readline() on unopened filehandle"), new RuntimeScalar("\n"));
2537
return ctx == RuntimeContextType.LIST ? new RuntimeList() : scalarUndef;

0 commit comments

Comments
 (0)