Diagnostic and cause
LinkInteger overflow
- Family
- topaz
- Phase
- run
- Code
TPZ4004
Cause and conditions
An int addition whose mathematical result is outside the signed 64-bit int range faults at the addition expression. The range failures specified by Duration values use the same runtime diagnostic, TPZ4004.
Related rule: Trigger and repairResponse
Check that the intended result fits in int, or change the arithmetic representation. The repair adds zero to the maximum int value and stays at the representable boundary.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 535-543 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 57-57 - compiler/crates/topaz_value/src/lib.rs at
151141d7bb44· 164-164 - compiler/crates/topaz_value/src/value/operators.rs at
151141d7bb44· 12-17 - compiler/crates/topaz_value/src/value/operators.rs at
151141d7bb44· 205-214 - compiler/crates/topaz_product_runtime/src/runtime/evaluate.rs at
151141d7bb44· 331-363 - compiler/crates/topaz_value/src/lib.rs at
151141d7bb44· 157-164 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 38-57 - compiler/crates/topaz_cli/src/compile/direct_run.rs at
151141d7bb44· 37-77 - TPZ4004 at
f42fbeb4f27e - TPZ4004 repair at
151141d7bb44
Compiler phase: runtime.
Compiler explanation: A checked integer operation exceeded the int range.
Message templates are Pending. The explanation above is not an observed CLI message.
Observed for the candidate in Topaz 5.21.3. Execution
- error[TPZ4004]: integer addition overflows
An int operation produces a result outside the signed 64-bit range, or a Duration operation violates the range rules in Duration values.
Trigger and repair
An int addition whose mathematical result is outside the signed 64-bit int range faults at the addition expression. The range failures specified by Duration values use the same runtime diagnostic, TPZ4004.
Why
Duration range failures use the existing integer overflow diagnostic. One code describes an arithmetic result that cannot be represented.
Source evidence
- compiler/crates/topaz_value/src/value/operators.rs at
151141d7bb44· 12-17 - compiler/crates/topaz_value/src/value/operators.rs at
151141d7bb44· 205-214 - compiler/crates/topaz_product_runtime/src/runtime/evaluate.rs at
151141d7bb44· 331-363 - compiler/crates/topaz_value/src/lib.rs at
151141d7bb44· 157-164 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 38-57 - compiler/crates/topaz_cli/src/compile/direct_run.rs at
151141d7bb44· 37-77 - TPZ4004 at
f42fbeb4f27e - TPZ4004 repair at
151141d7bb44 - issues/31 at
1cbf38d3d422
Response
LinkCheck that the intended result fits in int, or change the arithmetic representation. The repair adds zero to the maximum int value and stays at the representable boundary.
Reproduction and verification
LinkProduct diagnostic test
Linkfunction add(left: int, right: int) -> int {left + right}add(9223372036854775807, 1)
Expected result
Expected result
The separate diagnostic product test validates this command, runtime diagnostic, or filesystem setup. The shared example runner does not execute that assertion plan.
Run topaz run example..
Expect exit status 1, empty standard output, and TPZ4004.
The evaluated operands of an int operation produce a result outside the representable signed 64-bit range. The reproduced case adds one to the maximum int value; the operation faults instead of wrapping.
The primary location is example..
Expect exactly one diagnostic.
The diagnostic product test checks these expectations with the same files and command.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 535-543 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 57-57 - compiler/crates/topaz_value/src/lib.rs at
151141d7bb44· 164-164 - compiler/crates/topaz_value/src/value/operators.rs at
151141d7bb44· 12-17 - compiler/crates/topaz_value/src/value/operators.rs at
151141d7bb44· 205-214 - compiler/crates/topaz_product_runtime/src/runtime/evaluate.rs at
151141d7bb44· 331-363 - compiler/crates/topaz_value/src/lib.rs at
151141d7bb44· 157-164 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 38-57 - compiler/crates/topaz_cli/src/compile/direct_run.rs at
151141d7bb44· 37-77 - TPZ4004 at
f42fbeb4f27e - TPZ4004 repair at
151141d7bb44
Corrected program
Linkfunction add(left: int, right: int) -> int {left + right}add(9223372036854775807, 0)
No stdout.
Expected result
Expected result
Execution completes. Exit code 0.
This program applies the repair described above. The verification status records whether it has been run.
Source evidence
- compiler/crates/topaz_value/src/value/operators.rs at
151141d7bb44· 12-17 - compiler/crates/topaz_value/src/value/operators.rs at
151141d7bb44· 205-214 - compiler/crates/topaz_product_runtime/src/runtime/evaluate.rs at
151141d7bb44· 331-363 - compiler/crates/topaz_value/src/lib.rs at
151141d7bb44· 157-164 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 38-57 - compiler/crates/topaz_cli/src/compile/direct_run.rs at
151141d7bb44· 37-77 - TPZ4004 at
f42fbeb4f27e - TPZ4004 repair at
151141d7bb44