# constant-condition

> Branch condition reduces to a typed scalar source constant.

Canonical: https://nightshade.dicksonwu.xyz/rules/constant-condition.html
Release: Nightshade 0.1.1 (v0.1.1)

| Field | Value |
| --- | --- |
| Rule ID | `constant-condition` |
| Severity | info |
| Confidence | high |
| Maturity | experimental |
| Selection | Hygiene only |
| Policy intent | not required |
| Default enabled | yes |
| Category | Additional hygiene rules |
| Engine facts used | resolved-model, typed-source-constants |
| Release | v0.1.1 |

## Selection and scope

Not in the default profile. `--profile hygiene` adds it, or select it explicitly with `--detectors`.

```sh
./.nightshade/node_modules/.bin/nightshade ./contracts --detectors constant-condition
./.nightshade/node_modules/.bin/nightshade detector show constant-condition
```

The first command runs only this rule; `--detectors` takes a comma-separated list. The second prints the rule's metadata from your installed version.

Severity is review priority. It does not express exploitability or impact. Confidence is detector metadata, not a probability. All built-in rules are experimental.

Compiler scope: the engine supports the pinned profiles 0.28.0, 0.29.0, 0.30.0, 0.31.1, 0.33.0-rc.2, 0.34.0, 0.35.0-rc.1 and 0.35.0, with ZKIR2 by default. Support for this rule can be narrower; the rule documentation below states any narrower scope.

## Corpus checks

Synthetic corpus checks for this rule in the 0.1.1 proof run. A check counts only with compiler acceptance and complete analysis.

| Positive detected | Corrected quiet | Lookalike quiet | Other negative quiet | Incomplete |
| ---: | ---: | ---: | ---: | ---: |
| 1/1 | 1/1 | 1/1 | 0/0 | 0 |

No deviations were recorded for this rule.

These are behavior checks on synthetic fixtures, not a precision or recall estimate. See [evaluation](https://nightshade.dicksonwu.xyz/evaluation.md#synthetic-corpus).

## Rule documentation

From https://github.com/DicksonWu654/nightshade/blob/v0.1.1/docs/detectors/constant-condition.md at v0.1.1.

Availability: **default-on**; no policy required.
Severity **info**, confidence **high** for the typed source-constant observation.
Use `--min-severity low` to hide informational findings, or
`--detectors constant-condition` to select only this rule.

Reports a root-file branch condition reducing to the same typed scalar constant
across its instantiated copies. This identifies a fixed branch choice for review.

### Example and review scenario

The compiler-0.34.0-qualified owned [Counter fixture](#example-1)
uses `if (1 < 2)` to select an increment. Its
[correction](#example-2)
keeps the selected `round.increment(1)` directly. Review accidental fixed operands
when a branch was intended to depend on configuration or an input.

Recommendation: verify the operands and intended configuration, then correct an
unintended constant or simplify an intentional branch.

### False positives and limitations

Compile-time configuration and generic specialization can intentionally fix a
branch. The source model does not infer arbitrary call results or aggregate
projections as constants; it is not a solver for all invariant conditions. Only
root-file observations are reported. Budget exhaustion remains incomplete.
[Dead-code](https://nightshade.dicksonwu.xyz/rules/dead-code.md) can separately report an excluded branch.

### Source examples

These short regression examples are included here for installed-package readers.
Rule-specific policy requirements and limits above still apply.

#### Example 1

Counter fixture (source: `tests/corpus/informational/constant-condition-positive.compact`).

```compact
// This file is part of midnightntwrk/example-counter.
// Copyright (C) Midnight Foundation
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pragma language_version >= 0.20;

import CompactStandardLibrary;

// public state
export ledger round: Counter;

// Nightshade owned informational regression; adapted from example-counter.
export circuit increment(): [] {
  if (1 < 2) { round.increment(1); } else { round.increment(2); }
}
```

#### Example 2

Correction (source: `tests/corpus/informational/constant-condition-corrected.compact`).

```compact
// This file is part of midnightntwrk/example-counter.
// Copyright (C) Midnight Foundation
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pragma language_version >= 0.20;

import CompactStandardLibrary;

// public state
export ledger round: Counter;

// Nightshade owned informational regression; adapted from example-counter.
export circuit increment(): [] {
  round.increment(1);
}
```

## Suppress a match

If a match is intentional, suppress it on the line before with the exact rule ID and a reason of at least eight characters:

```compact
// nightshade-disable-next-line constant-condition -- Reason this match is intentional
```

Diagnostics cannot be suppressed, and an unmatched directive for a selected rule makes analysis incomplete. See [configuration](https://nightshade.dicksonwu.xyz/configuration.md#suppress-an-intentional-match) for fingerprint suppressions and baselines.

## References

- [Rule source document at v0.1.1](https://github.com/DicksonWu654/nightshade/blob/v0.1.1/docs/detectors/constant-condition.md)
- [Catalog entry in rules.json](https://nightshade.dicksonwu.xyz/rules.json)
- [All rules](https://nightshade.dicksonwu.xyz/rules.md#additional-hygiene-rules)
- [Limitations](https://nightshade.dicksonwu.xyz/limitations.md)
