Skip to content

Fix: narrow "Parenthesize unary negation" to surprising precedence (fixes #1636)#1685

Open
mgajda wants to merge 1 commit into
ndmitchell:masterfrom
mgajda:fix/negation-only-backticks
Open

Fix: narrow "Parenthesize unary negation" to surprising precedence (fixes #1636)#1685
mgajda wants to merge 1 commit into
ndmitchell:masterfrom
mgajda:fix/negation-only-backticks

Conversation

@mgajda
Copy link
Copy Markdown

@mgajda mgajda commented Apr 19, 2026

Summary

Fixes #1636. The "Parenthesize unary negation" hint (introduced by #1484)
was firing on conventional arithmetic operators where the precedence
matches the reader's mental model, producing noise like:

Found: -365.25 * nominalDay * fromIntegral y
Perhaps: -(365.25 * nominalDay * fromIntegral y)

Narrow the rule to the operators where precedence around unary - is
genuinely surprising:

Conventional arithmetic (+, -, *, /, fixity 6–7) no longer
triggers the hint.

Test plan

…ixes ndmitchell#1636)

The hint was introduced in ndmitchell#1484 for cases where unary negation combines
with higher-fixity operators in non-obvious ways:

  -1 ^ 2       -- parses as -(1^2) = -1, not (-1)^2 = 1
  -5 `mod` 3   -- parses as -(5 `mod` 3), which returns -2

It also fired on fixity-7 symbolic operators (`*`, `+`, `/`), where the
precedence matches the conventional mathematical reading and the extra
parens are just noise — as flagged in ndmitchell#1636:

    addUTCTime (-365.25 * nominalDay * fromIntegral y)

Narrow the rule to only fire on operators that are actually surprising:

- alphanumeric functions infixed with backticks (fixity 9)
- exponentiation: `^`, `^^`, `**` (fixity 8)

This keeps the canonical ndmitchell#1484 cases firing while silencing the ndmitchell#1636
noise.
@mgajda mgajda force-pushed the fix/negation-only-backticks branch from 2a839c0 to c4229fa Compare April 19, 2026 19:57
@mgajda mgajda changed the title Fix: limit "Parenthesize unary negation" to infix functions (fixes #1636) Fix: narrow "Parenthesize unary negation" to surprising precedence (fixes #1636) Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect "Parenthesize unary negation" suggestion

1 participant