Skip to content

Preserve Perl scalar dual-value semantics for numeric zero #1262

Description

@fglock

Summary

HTTP::BrowserDetect 3.45 exposes a remaining PerlOnJava scalar-semantics regression: numeric zero returned by browser-version methods is considered different from the string "0" loaded from the JSON fixture.

CPAN evidence

  • Distribution: HTTP-BrowserDetect 3.45
  • CPAN run: 20260904-185312-10032
  • Failing test: t/01-detect.t
  • PerlOnJava result: 304 user-agent cases fail before the harness timeout
  • System Perl result: all 6 test files pass, 2,601 tests successful

The CPAN record reports a timeout because the test contains 1,220 user-agent cases and the failure stream eventually exceeds the harness limit. The timeout is secondary; the failures are deterministic and begin immediately.

Minimal reproducer

The underlying comparison fails on both PerlOnJava backends but passes under system Perl:

use Test::Differences qw(eq_or_diff);

eq_or_diff(0, "0", "numeric zero and string zero");

The same mismatch is exercised by HTTP::BrowserDetect:

my $detected = HTTP::BrowserDetect->new($user_agent);
eq_or_diff($detected->browser_major, "0", "browser_major");

For user agents with no detected browser version, HTTP::BrowserDetect::_init_version assigns numeric 0, while the JSON fixture contains the string value "0". Standard Perl's scalar dual-value behavior allows the comparison; PerlOnJava's Test::Differences sees distinct numeric and string scalar types.

Impact

This affects pure-Perl modules and tests that compare values originating from different sources—such as computed numeric values versus strings decoded from JSON. It can create large numbers of false incompatibilities in data-driven CPAN test suites, and can turn a broad semantic mismatch into a harness timeout.

Related issues

  • #1158 — closed issue on preserving string scalar semantics through arithmetic.
  • #1128 — closed issue on Perl-compatible numeric-zero scalar behavior.
  • #1260 — JSON numeric scalar typing in the opposite direction, where decoded numbers lose numeric behavior.

This issue should be evaluated alongside those fixes rather than assuming that closing them eliminated all scalar dual-value mismatches.

Required regression coverage

Before closing this issue, add tracked project-owned tests that:

  1. Compare numeric zero and string "0" through the same deep-comparison path used by Test::Differences.
  2. Cover values returned from a pure-Perl method after numeric initialization and values decoded from JSON fixtures.
  3. Verify ordinary numeric and string comparisons remain distinct where Perl distinguishes them.
  4. Pass under standard Perl first, then pass on both the JVM and interpreter backends.
  5. Include a focused HTTP::BrowserDetect or equivalent data-driven regression so the CPAN failure cannot silently return.

Do not fix this by weakening Test::Differences globally or by changing the upstream fixture. The implementation must preserve Perl-compatible scalar behavior at the value/operation boundary.

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