Skip to content

Nim: branch counts try, except and finally (a handler is not a decision) #8926

Closed

Description

@squid-protocol

What is wrong

Nim branch counts exception handlers, against the branch contract. Found with a Nim oracle on nim-lang/Nim lib/ (3,953 routines matched; args 0.93 / 1.00; branch 0.98 / 0.91):

  • A try/except/finally procedure scores branch 3 (the try, except and finally). The branch contract's corollary 1: "A handler is not a decision. catch/rescue/except/finally/ensure/trap, the guarded-region opener (try) and the raiser (throw) ... are safety's constructs", retired from 27 other rules.
  • (The class in branch: short-circuit boolean operators are counted in some languages and not others; Zig's rule lists && and || that Zig does not have #8905:) a and b or a scores 0: Nim's boolean and/or are not counted, as in Java, Solidity, Zig and Groovy.
  • A Nim proc type (cb: proc (x: int)) scores as a closure; a standalone ## comment inside a body is credited to the following routine as its doc (both reported by the oracle on the corpus, not re-checked on a minimal file).

Reproduce (pinned scanner; counts read from function_data)

proc tryProc(a: int): int =
  try:
    result = a
  except ValueError:
    result = 0
  finally:
    discard                       # struct_branch == 3, should be 0

proc boolOps(a, b: bool): bool =
  return a and b or a             # struct_branch == 0 (#8905 decides whether boolean operators count)

proc realIf(a: int): int =
  if a > 1:
    return 1
  return 0                        # struct_branch == 1, correct

Expected

Remove try, except and finally from the Nim branch rule (move to safety or structural_boundaries as for the other languages).

Part of #8863. Time the change; rosetta:rebless-owed if counts move; add the case above as a test.

Activity

  1. added
    bug
    core-engine
    on Nov 21, 2026
  2. squid-protocol commented on Nov 22, 2026

    @squid-protocol
    OwnerAuthor

    Covered by #8939 (the family split removes try/except/finally from Nim's branch). PR #9017 was closed as superseded at the owner's direction; no new worker is needed for this item. The issue closes when #8939 merges.

  3. squid-protocol commented on Nov 22, 2026

    @squid-protocol
    OwnerAuthor

    Claimed by promoter-bot host melek, lease renewed 2026-11-23T10:31Z. It lapses after 6 h without a renewal. To take it back, assign someone or remove the claim:melek label.

  4. squid-protocol commented on Nov 23, 2026

    @squid-protocol
    OwnerAuthor

    Fixed by #8939 (handlers out of Nim branch; and/or in short_circuit) and regression-tested in #9066. The proc-type and standalone ## comment items are oracle-reported only, not reproduced, and no burned-estate program needs them; reopen with a minimal repro if one does.

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

    bugclaim:melekcore-enginepriority: medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions