RFR: [type-classes]: Lowered code for operator for type class operators is missing a cast

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Jan 26 10:38:19 UTC 2026


When we lower an unary/binary type class-mediated operation:


P p1 = ... ; P p2 = ...
p1 + p2


To:


Numerical<P>.__witness.add(p1, p2)


We should add a cast to the resulting expression, as the result type of the witness method (e.g. `add`, in this case) is generic, and its erasure is just `Object`.
Leaving the type as is leads to verifier errors due to wrong stack maps being generated.

-------------

Commit messages:
 - Add missing cast in operator lowering code

Changes: https://git.openjdk.org/valhalla/pull/1968/files
  Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=1968&range=00
  Stats: 88 lines in 2 files changed: 74 ins; 6 del; 8 mod
  Patch: https://git.openjdk.org/valhalla/pull/1968.diff
  Fetch: git fetch https://git.openjdk.org/valhalla.git pull/1968/head:pull/1968

PR: https://git.openjdk.org/valhalla/pull/1968


More information about the valhalla-dev mailing list