You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix off-by-one error in stack traces by making line and column numbers 1-based for user display (#2628)
Stack traces were displaying both line and column numbers using 0-based
indexing instead of the standard 1-based indexing expected by users and
editors.
## Problem
When a runtime error occurred, the stack trace would report incorrect
line and column numbers that were off by one:
```qsharp
function Main() : Unit {
fail "line 2"; // This is line 2, column 5 (1-based counting)
}
```
**Before fix:**
```
Error: program failed: line 2
Call stack:
at Main in test.qs:1:4 // Wrong! Shows line 1, column 4
```
**After fix:**
```
Error: program failed: line 2
Call stack:
at Main in test.qs:2:5 // Correct! Shows line 2, column 5
```
## Root Cause
The `format_call_stack` function in
`source/compiler/qsc/src/interpret/debug.rs` was displaying `pos.line`
and `pos.column` (which are 0-based for internal calculations) directly
to users. Both line and column numbers should be 1-based for user-facing
display as this is the standard convention used by editors and IDEs.
## Solution
Updated both line and column number display to add 1 to convert from
internal 0-based indexing to user-expected 1-based indexing:
```rust
// Before
pos.line,
pos.column,
// After
pos.line + 1,
pos.column + 1,
```
This change ensures that both line and column numbers are displayed
correctly to users while preserving the internal 0-based indexing used
throughout the codebase.
## Testing
- Updated existing stack trace test expectations to reflect correct
1-based line and column numbers
- All 158 qsc package tests pass
- All debug-specific tests pass
Fixes#2627.
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to
start the survey.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: minestarks <[email protected]>
0 commit comments