Skip to content

Operands of arithmetic operators are type checked twice #9500

Description

@cknitt

The operands of an arithmetic operator such as + are type checked twice. Each nested operator doubles that again.

One way to see it is a diagnostic on an operand:

let b = 1 + @warning(3) 2
let c = 1 + (1 + (1 + @warning(3) 2))

The malformed payload (warning 47) is reported twice for b and eight times for c. A @ppwarning on an operand is reported twice too.

The cause is translate_unified_ops in compiler/typing/typecore.ml (around line 4418). It types an operand with type_exp to find out its type, and then types it again with type_expect. When the operand is itself an operator application, the same happens inside it, so the work doubles with each level of nesting. Besides the repeated diagnostics, this costs type checking time on long chains of operators.

Found by a review of #9491, which makes every other warning attribute report once.

(Filed by Claude.)

Activity

  1. added theissue type on Dec 1, 2026
  2. added a commit that references this issue on Dec 2, 2026
    0fe7cd9
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

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions