Skip to content

codegen: a function used as a value without a target type lowers to a delegate spelled from its Sharpy signature — generic, iterator-returning, defaulted, params and CLR-typed signatures reach Roslyn (SPY0908) #2277

Open

Description

@antonsynd

Class

A function used as a value without a target type is lowered to a Func/Action spelled from its Sharpy signature, and five signature shapes reach Roslyn (SPY0908). The semantic pass accepts f = statistics.mode; code generation then writes a delegate the C# compiler refuses. Plain signatures work as values (sorted(xs, key=os.path.basename), map(math.sqrt, xs) print python's output), so the defect is on the signature-shape axis, not the callee-kind axis: a user-defined generic function fails the same way as a stdlib one.

Contract: a function value either runs with python's result or is refused semantically with a named code (SPY0336 already refuses an overload set with a steer); SPY0908 is never the verdict (docs/design/spy0908-policy.md).

Cells

Measured @ 729bf1e with the built sharpyc run and by the #2272 function-heading guard (StdlibDocFieldNameBindingTests, census line DOC-FN-EMIT, 29 failures over 53 doc pages; pages that hold an overload set stop at SPY0336 and never reach emission, so the census is a lower bound).

signature shape program observed @ 729bf1e expected (python3 3.12) lane reach
generic (stdlib) f = statistics.mode then print(f([1, 1, 2])) SPY0908 CS0246 T 1 ice program
generic (user) def first[T](xs: list[T]) -> T … f = first; print(f([1, 2])) SPY0908 CS0246 T, CS1503 1 ice program
iterator-returning CLR method d = difflib.ndiff; print(len(list(d(["a"], ["b"])))) SPY0908 CS0407 (IEnumerable<string> vs the Sharpy return), CS7036 2 ice program
defaulted parameters same difflib.ndiff (two defaulted Func params) CS7036 (the delegate requires every argument) 2 ice program
params tail f = struct.pack SPY0908 CS0123 binds ice program
unmapped CLR parameter type f = csv.writer SPY0908 CS0246 TextWriter, CS0123 binds ice program
census rows (same shapes) bisect.bisect_left/right, bisect.bisect, bisect.insort*, secrets.choice, yaml.safe_load_typed (generic); difflib.unified_diff/context_diff/restore, struct.iter_unpack (iterator); csv.dict_writer (CLR type) SPY0908 binds ice program
operator page (one program binding every operator.* function) f0 = operator.abs … SPY0599: generated C# has 12 syntax errors binds ice program
control: plain signature sorted(["b/x", "a/y"], key=os.path.basename); list(map(math.sqrt, [4.0, 9.0])) ['b/x', 'a/y']; [2.0, 3.0] same — —

Acceptance

Labels: class-tracker, lane:ice, reach:program. Unplaced (for the next /batch-issues). Found by the #2272 chore's function-heading guard (2026-10-08).

Activity

  1. added
    lane:ice
    reach:program
    class-tracker
    on Oct 8, 2026
  2. antonsynd commented on Oct 9, 2026

    @antonsynd
    OwnerAuthor

    Batching 2026-10-08 @ be1c16f — charter .claude/plans/remediation-round-2026-09-20-batching.md §3.12c, P60 — function-value route parity (order 12c, directly after P57). Ruling R-FW (owner, 2026-10-08): option (a) — a function whose signature has a *args tail is not a value without a lambda; refused in the SPY0335 family with the steer "wrap it: lambda a, b, c: s(a, b, c)".

    Contract: a function used as a value either runs with python's result or is refused semantically with a named code — SPY0908 is never the verdict — and the value's TYPE is ONE recorded fact (full signature, defaults erased, no tail, type arguments closed) read by both the checker's through-value call check and the emitter's delegate speller, so the inferred local f = g reaches every verdict the annotated f: (…) -> T = g reaches. Lane / reach: ice · program; this issue is the class tracker.

    Measured @ be1c16f (built sharpyc run): f = first[int] → SPY0335 already (the explicit spelling is refused; bare f = first reaches Roslyn — this issue's cell); m: (int, int) -> int = h → SPY0486 already, and function_types.md §Default Parameter Erasure rules k(1) through the value SPY0277 — while the inferred k = h; k(1) → SPY0908 CS7036 and k(1, 5) prints 6; m: (int) -> int = h and g: (list[int]) -> int = first → SPY0220 (no arity adaptation, no inference from the target — unchanged); f = s for def s(*xs: int) → SPY0908 CS0123 (Func<int, int>). So the generic and defaulted shapes are spelling-parity cells of EXISTING rules and need no ruling; only the tail did.

    Cells / generator (REQUIRED FIRST, 3 axes): signature shape {plain (control), generic, iterator-returning, defaulted, *args tail, CLR-typed parameter, overload set (SPY0336 control)} × callee kind {user def, spy-sourced stdlib, hand-written C# stdlib, CLR static} × position {local without annotation, key=, map argument, annotated local}; each cell compiled and run against its direct-call twin, allowlist ratchet. The DOC-FN-EMIT census in StdlibDocFieldNameBindingTests is Output.WriteLine only today — the plan's first task makes it an asserted allowlist citing this issue (drain on fix). Emit-family cells (iterator return spelled from the Sharpy type; unqualified TextWriter) join the #1683/#1802 emit-family roster. No snapshot moves by design. Direction record: SPY0908 → the new code / SPY0486 + SPY0277 / runs.

    Rejected: (b) type the tail as one sequence parameter (list[int]) -> int (C# normal form; f([1, 2, 3]) runs where python refuses and f(1, 2, 3) is refused — magic, one-way once written); (c) a *T spelling in function types with a per-arity variadic delegate family (a language feature; (a) → (c) later is additive). Scheduled after P57 rather than as P17e after P17's sentinel (R-GC): every refusal cell lands on an existing code or R-FW's, so the sentinel adds nothing. No seam hypothesis — the plan measures the seam.

  3. antonsynd commented on Oct 14, 2026

    @antonsynd
    OwnerAuthor

    New axis value for this class — the from … import … as ALIAS used as a value (found by the P53 sibling-cell prober @ f33b528; identical on the base binary 8be4576, so pre-existing). Plain signature (no generics, no defaults), so the failing axis here is the SPELLING of the function value, not its shape:

    lib.spy: class Widget: … and def build(label: str) -> Widget: …

    main.spy sharpyc run
    from lib import build as b … f = b; print(f("x").label) SPY0908 ×2: CS0246 The type or namespace name 'Widget' could not be found, CS0407 'Widget LibModule.Build(string)' has the wrong return type
    from lib import build … f = build; print(f("x").label) runs ✅
    from lib import build as b … print(b("x").label) (alias called, not stored) runs ✅

    The delegate the value lowering spells from the Sharpy signature names the return type Widget unqualified; through the alias the type's module qualification is lost (the unaliased value spells it so that it compiles). Recurrence shape of closed #1588 (alias value position). Add aliased from-import to the position axis of the acceptance matrix.

  4. antonsynd commented on Oct 14, 2026

    @antonsynd
    OwnerAuthor

    Batching 2026-10-14 @ 27e2616 — charter .claude/plans/remediation-round-2026-09-20-batching.md §3.12c, P60 — function-value route parity (order 12c; placement unchanged). The call-22 cell (the from … import … as ALIAS used as a value — f = b → CS0246/CS0407, the delegate's return type unqualified through the alias; f = build and b("x") run; recurrence shape of closed #1588) is recorded: aliased from-import joins the position axis of the generator.

  5. antonsynd commented on Nov 20, 2026

    @antonsynd
    OwnerAuthor

    Cell (found by P78's stage-0 generator, plan-777361; outside that plan's contract). Measured with sharpyc run on product code == dev @ e24aaf9f0.

    Program Observed Expected
    from system import Array / x: object = Array.resize SPY0908 behind CS8917 (The delegate type could not be inferred) a refusal with a Sharpy code
    the same read at a parameter default SPY0908 behind CS1736 a refusal with a Sharpy code
    from system import Math / x: object = Math.abs SPY0336 ('abs' is a CLR method group; call it, or wrap it in a lambda) (control: the non-generic overloaded group is refused with a code)

    A generic CLR method read uncalled, with no target type, is not caught by the SPY0336 rule that catches an overloaded CLR method group, and reaches Roslyn. Lane: ice · reach: program. The generator excludes the generic-method shape with a probe tied to this member.


    Generated by Claude Code

  6. antonsynd commented on Nov 20, 2026

    @antonsynd
    OwnerAuthor

    Two cells (found by P78's stage-0 generator, plan-777361; outside that plan's contract). Reproduced with sharpyc run on product code == dev @ e24aaf9f0. Both fail with a literal default, so neither is a scoping verdict.

    Program Observed Expected
    class H: / @static / g: auto = lambda p1: int = 5: p1 / def main() -> None: / print(H.g()) SPY0908 behind CS7036 (no argument given that corresponds to the required parameter 'arg' of 'Func<int, int>') 5, or a Sharpy diagnostic at the call
    class H: / property r: int = (lambda p1: int = 5: p1)() / def main() -> None: / print(H().r) (also the @static form) SPY0908 behind CS0103 (The name '__lambda_0' does not exist in the current context) 5

    The first is this tracker's "defaulted" signature: a lambda stored in an auto field becomes a delegate whose type carries no default. The second may be a different mechanism (a lambda with a default hoisted out of a property default); it is posted here as the nearest open class and may want its own tracker. Lane: ice · reach: program. The generator excludes both shapes with a probe each.


    Generated by Claude Code

  7. antonsynd commented on Nov 20, 2026

    @antonsynd
    OwnerAuthor

    Cell with an owner ruling (2026-11-20; #2423 comment 7052893050, item 29): a function target type selects the overload of a CLR method group. Found by the independent review of PR #2767; reproduced with sharpyc run on product code == dev @ e24aaf9f0.

    Program Observed Expected
    from system import Math / x: (float) -> float = Math.abs / print(x(-1.5)) SPY0336 ('abs' is a CLR method group; call it, or wrap it in a lambda) runs, 1.5
    from system import Char / g: (char) -> bool = Char.is_digit / print(g('5')) SPY0336 runs, True
    const K: (int) -> int = Math.abs SPY0336 runs
    g: (float) -> float = Math.sqrt / print(g(4.0)) (one overload; control) runs, 2.0 runs
    x: (float) -> float = math.log (the Sharpy module's overloaded function; control) runs runs
    x: object = Math.abs (no function target type) SPY0336 SPY0336

    dotnet_interop.md says a function target type at the reference site selects the method for a Sharpy builtin's method (counter: (int) -> int = xs.count). The owner's words on the CLR case: "Must-run, known-red" — "a function target type selects a CLR overload". P78's generated cells for this shape become must-run and cite this tracker; the fix is not P78's. Lane: false-refusal · reach: program.


    Generated by Claude Code

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

    class-trackerlane:icereach:program

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions