Skip to content

str/repr of Result renders the payload with CLR ToString — Ok(R2.Snake), Err(Sharpy.ValueError: bad) — Optional's twin (#2005) was routed, Result's was not #2137

Description

@antonsynd

Found by /verify-implementation plan-0ca7b7 (2026-09-26), measured @ 61bf20f with the built sharpyc; pre-existing at BASE acd1d40 unless noted.

class Snake:
    x: int

def f(ok: bool) -> Snake !ValueError:
    if ok:
        return Ok(Snake())
    return Err(ValueError("bad"))

def main():
    print(f(True))        # Ok(R2.Snake)          (BASE: Ok(R2+Snake))
    print(f(False))       # Err(Sharpy.ValueError: bad)
    print(Some(Snake()))  # <__main__.Snake object>  (routed by #2005 in plan-0ca7b7)
    print(repr(f(True)))  # Ok(R2.Snake)

Also print(json.loads[Snake]('{"x": 4}')) prints Ok(Tz.Snake). P11f's class contract says every runtime spelling of a value comes from the one python-name/repr channel (PyFormat, IRepr). Result.cs's ToString formats the payload/error with .NET ToString, so the CLR type name leaks. Expected: Ok(<__main__.Snake object>), and for Err the payload's repr (Err(ValueError('bad'))). The exact spelling needs a spec line, since result_types has none. Sibling cell of #2005 and #2006; the P11f matrix had Optional rows but no Result rows.

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

    lane:silent-wrongCompiles and runs with wrong output or semantics (rank first)reach:programAn ordinary program a Python programmer would write hits it

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions