fixhunt

biome complexity/useSimplifiedLogicExpression: fixed output does not parse

fix-breaks-syntaxlabelled safereal · highduplicate
Findings / 2026-10-17T20-15-13-121Z-vjcv-biome-complexity_useSimplifiedLogicExpression / r2-p001biome 2.5.156 → 4 lines2026-10-17 20:15 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

Fix removing 'true &&' leaves a function expression starting at statement position, which is invalid syntax.

Program

before
1try {
2 true && function() { return 1; }();
3} catch (e) {
4}
after
1try {
2 function() { return 1; }();
3} catch (e) {
4}

Output

stdout beforeexit 0
(no stdout)
stdout afterexit 0
(no stdout)
fired
1 before · 0 after
runs
each version twice, same file name, no network

Judge Nemotron 3 Ultra advisory real · high

The rule rewrites 'true && function() { return 1; }()' to 'function() { return 1; }()', but a function expression in statement position is a syntax error because function statements require a name. The original code was valid because the function expression was an operand of &&, making it an expression statement; the fix changes the parse context and breaks syntax.

Explanation Nemotron 3 Super unverified

The original expression `true && function(){return 1;}()` evaluates to either false or 1 depending on truthiness of left operand but always executes the IIFE due to grouping parentheses after function definition. After rewriting as just `function(){return 1;}();`, it becomes a bare function declaration followed by a call expression which JavaScript parses as invalid syntax—function declarations require an identifier—and thus throws before any execution occurs, changing behavior from potentially returning a value to unconditionally throwing a SyntaxError. This alters both control flow and outcome.

Reproduce

file
prog.js (the before program)
minimized program
r2-p001.js
evidence sheet
r2-p001.md
regression fixture
r2-p001.js the minimized program with a header stating the observed change, for the tool's test suite
node prog.js
bunx @biomejs/biome lint --only=complexity/useSimplifiedLogicExpression --write prog.js
node prog.js

Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra

useSimplifiedLogicExpression fix · complexity useSimplifiedLogicExpression logical AND · Biome rule simplify truthy expressions · remove redundant true && in try block

  • duplicate biomejs/biome/issues/11351 same rule useSimplifiedLogicExpression removing a leading literal in a logical expression and breaking syntax
  • related biomejs/biome/issues/7984 same rule useSimplifiedLogicExpression but different construct multiline conditions with comments
  • related biomejs/biome/issues/8577 same rule useSimplifiedLogicExpression but different construct redundant terms in logical expression
  • related biomejs/biome/issues/279 same rule useSimplifiedLogicExpression but different construct type narrowing with logical negation

Details

program
Lookahead ambiguity breaking parse
hazard
Fix removing 'true &&' leaves a function expression starting at statement position, which is invalid syntax.
oracle
/home/sun/dev/diaghunt/runs/2026-10-17T20-15-13-121Z-vjcv-biome-complexity_useSimplifiedLogicExpression/r2-p001/min/r2-p001-reuse/fixed.js:2 function() { return 1; }(); ^^^^^^^^ SyntaxError: Function statements require a function name at checkSyntax (node:internal/main/check_syntax:84:5) Node.js v26.8.1
run
2026-10-17T20-15-13-121Z-vjcv-biome-complexity_useSimplifiedLogicExpression
generated program (6 lines) and the fix's diff
1try {
2 true && function() { return 1; }();
3 console.log('ok');
4} catch (e) {
5 console.log(e.name + ': ' + e.message);
6}
--- orig.js	2026-10-17 16:15:37.605870939 -0400
+++ fixed.js	2026-10-17 16:15:37.866867196 -0400
@@ -1,5 +1,5 @@
 try {
-  true && function() { return 1; }();
+  function() { return 1; }();
   console.log('ok');
 } catch (e) {
   console.log(e.name + ': ' + e.message);
rule documentation given to the models
Summary

- Name: useSimplifiedLogicExpression
- Fix: safe
- Default severity: info
- Available from version: 1.0.0
- Diagnostic category: lint/complexity/useSimplifiedLogicExpression


Description

 Discard redundant terms from logical expressions.

 The rule applies the [De Morgan's Law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) rule to simplify logical expressions.
 This means that some simplified expressions that are fixed by the rule might seem less intuitive to read, but they are more efficient to evaluate.

 `value || false` and `value && true` are only reported in a boolean context, such as an `if`
 condition or the operand of `!`, where only the truthiness of the result matters. Elsewhere,
 removing the literal changes the result when `value` is not a boolean.
 `value || true` and `value && false` are never reported, since the literal alone would skip
 evaluating `value`.

Examples

Invalid

 ```js,expect_diagnostic
 const boolExp = true;
 const r = true && boolExp;
 ```

 ```js,expect_diagnostic
 const boolExp2 = true;
 const r2 = false || boolExp2;
 ```

 ```js,expect_diagnostic
 const boolExp3 = true;
 if (boolExp3 || false) {
     doSomething();
 }
 ```

 ```js,expect_diagnostic
 const nonNullExp = 123;
 const r3 = null ?? nonNullExp;
 ```

 ```js,expect_diagnostic
 const boolExpr1 = true;
 const boolExpr2 = false;
 const r4 = !boolExpr1 || !boolExpr2;
 ```

Valid
 ```js
 const boolExpr3 = true;
 const boolExpr4 = false;
 const r5 = !(boolExpr1 && boolExpr2);
 const boolExpr5 = true;
 const boolExpr6 = false;
 ```

 ```js
 const value = undefined;
 const r6 = value || false;
 ```