Skip to content

Morpheus::Key overloaded comparisons incorrectly require cmp #1342

Description

@fglock

Summary

PerlOnJava fails Morpheus 0.46 operations involving overloaded
Morpheus::Key comparisons. The runtime attempts to dispatch the cmp
operation even though the class defines the relational overloads used by the
module (eq, lt, le, gt, and ge), and then aborts because no cmp
method is available.

CPAN regression

The CPAN random-tester run 20260910-101908-8428 recorded a regression for
Morpheus 0.46. The previous passing result was recorded on 2026-08-26 at
commit fc1332935.

Result from the current run:

26/58 subtests failed; 7/11 test programs failed

The recurring error is:

Operation "cmp": no method found, argument in overloaded package Morpheus::Key

The error is reported from Morpheus.pm while comparing configuration keys.
It causes bootstrap, cross-plugin, environment, file, import, and script
tests to fail or abort. t/key.t, which directly tests the key class, passes,
so the failure depends on the comparison context used by the larger module.

Minimal reproducer

Morpheus::Key's overload behavior can be exercised without external services
or platform prerequisites:

./jperl --interpreter -Ilib -e '
  use Morpheus::Key qw(key);
  sub compare { my ($a, $b) = @_; return $a le $b }
  my $a = key("/foo");
  my $b = key("/foo/bar");
  print compare($a, $b) ? "ok\\n" : "bad\\n";
'

Expected output:

ok

The PerlOnJava interpreter instead aborts with the missing-cmp diagnostic.
The equivalent focused test passes under system Perl. A direct JVM execution
of this reduced expression currently passes, while the archived CPAN run
fails through the default jperl path; the JVM/interpreter difference should
be retained as part of the investigation rather than assumed away.

Upstream implementation

Morpheus::Key declares these overloads:

use overload
    'eq' => ...,
    'lt' => \&less,
    'le' => ...,
    'gt' => ...,
    'ge' => ...,
    '""' => ...,
    '@{}' => \&parts;

It intentionally does not declare cmp. Standard Perl resolves the
relational operations according to the available overloads and fallback
rules. PerlOnJava is incorrectly requiring or dispatching cmp for at least
some dynamically typed overloaded comparisons.

Impact

Morpheus configuration loading and merging is broadly broken on the affected
execution path. More generally, CPAN classes that implement relational
overloads without explicitly implementing cmp may fail when their objects
are compared through subroutine arguments, configuration traversal, or other
dynamic code paths.

Suggested fix and regression coverage

Fix overloaded comparison dispatch/fallback so eq, lt, le, gt, and
ge use the methods supplied by the package and do not require an absent
cmp overload. Preserve Perl's behavior for incomparable operands and mixed
object/string comparisons.

Add project-owned regression coverage for:

  1. A Morpheus::Key comparison through a subroutine with dynamically typed
    arguments, under both backends.
  2. The Morpheus configuration traversal that currently fails in
    Morpheus.pm.
  3. The existing upstream Morpheus tests after the dispatch fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backendJVM interpreter or execution-backend behaviorarea:cpan-portCPAN compatibility ports and providersarea:runtimeCore Perl runtime semanticsbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions