Skip to content

Dart: branch counts nullable ? and ?. (precision 0.76); closures counts => on named functions (precision 0.32) #8906

Closed

Description

@squid-protocol

What is wrong

Two Dart families count things that are not what the contracts name. Found with a Dart oracle on flutter's widgets (7,020 functions matched; args 1.00 / 1.00, so the oracle reads functions correctly):

  1. branch counts the ? of nullable types and null-aware access (recall 1.00, precision 0.76; all 845 false-positive functions contain a ?). The Dart rule (dart.py, the branch regex, ~line 82) matches a bare ?. A nullable type T? and the null-aware ?. are not decisions; the contract counts the ternary at its ? and ?? as one value-selection decision (docs/branch_rule_contract.md, "Java's : and ?" and the value-selection dual).
  2. closures counts => expr on a named function (precision 0.32). An arrow body (int arrow(int a) => a + 1;) is the function's own body, not an anonymous callable ("the syntax that opens an anonymous callable ... at the point it is defined").
  3. (The class already filed as bitwise_ops: counts closing generics as a shift and ignores & and | that its contract names; string text counts by design (#2535) against the contract #8866:) List<List<int>> counts as bitwise 2: a closing generic >> is read as a shift.

Reproduce (scanned with the pinned scanner; counts read from function_data)

int? nullable(int? a) { return a; }                  // struct_branch == 2, should be 0
int chain(Foo? a) { return a?.x; }                   // 2, should be 0
int opt(Foo? a) { return a?.x ?? 1; }                // 3, should be 1 (only `??`)
int arrow(int a) => a + 1;                           // struct_closures == 1, should be 0
List<List<int>> generics(List<List<int>> m) { return m; }   // bitwise_ops == 2, should be 0
int realIf(int a) { if (a > 1) { return 1; } return 0; }    // branch 1, correct

Expected

Anchor the ? on ternary position (the model is java's, #2833: (?<!\w)\? with the generic wildcard exclusions) and count ?? once; do not count ?. or T?. Count a closures hit only for a function expression used as a value (an anonymous (x) => ... or () { ... } argument or assignment), not the => of a declaration.

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

Activity

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

    @squid-protocol
    OwnerAuthor

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

  3. squid-protocol commented on Nov 23, 2026

    @squid-protocol
    OwnerAuthor

    Fixed by #9111 (merged as fcc440b), which carried this issue's PR (rebuilt with eight others to re-bless the golden snapshots once).

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