Skip to content

feat: Provide a more precise error message when missed return statement is inside branch#1486

Merged
nicolaassolini-qntm merged 10 commits intomainfrom
na/issue1348-error-message-for-missing-return
Mar 17, 2026
Merged

feat: Provide a more precise error message when missed return statement is inside branch#1486
nicolaassolini-qntm merged 10 commits intomainfrom
na/issue1348-error-message-for-missing-return

Conversation

@nicolaassolini-qntm
Copy link
Copy Markdown
Contributor

  • The build function in builder.py now locates the specific statement and branch condition where a return statement is missing
  • The ExpectedError class now includes a Branch note
  • New test cases are added to ensure correct error reporting for missing returns in various branching scenarios

close #1348

@nicolaassolini-qntm nicolaassolini-qntm linked an issue Feb 9, 2026 that may be closed by this pull request
@maximilianruesch maximilianruesch changed the title feat: added a more precise error message when missed return statement is inside branch (closes #1348) feat: added a more precise error message when missed return statement is inside branch Feb 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 9, 2026

🐰 Bencher Report

Branchna/issue1348-error-message-for-missing-return
TestbedLinux

🚨 6 Alerts

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_checkLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
724.69 ms
(+15.59%)Baseline: 626.93 ms
658.28 ms
(110.09%)

tests/benchmarks/test_big_array.py::test_big_array_compileLatency
seconds (s)
📈 plot
🚷 threshold
🚨 alert (🔔)
1.96 s
(+22.90%)Baseline: 1.60 s
1.68 s
(117.05%)

tests/benchmarks/test_big_array.py::test_big_array_executableLatency
seconds (s)
📈 plot
🚷 threshold
🚨 alert (🔔)
8.16 s
(+16.23%)Baseline: 7.02 s
7.37 s
(110.69%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_checkLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
50.55 ms
(+10.27%)Baseline: 45.84 ms
48.13 ms
(105.02%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executableLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
612.26 ms
(+15.87%)Baseline: 528.41 ms
554.83 ms
(110.35%)

tests/benchmarks/test_prelude.py::test_import_guppyLatency
microseconds (µs)
📈 plot
🚷 threshold
🚨 alert (🔔)
51.42 µs
(+24.91%)Baseline: 41.16 µs
43.22 µs
(118.96%)

Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_check📈 view plot
🚷 view threshold
🚨 view alert (🔔)
724,690.82 µs
(+15.59%)Baseline: 626,929.26 µs
658,275.72 µs
(110.09%)

tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
🚨 view alert (🔔)
1,961,315.77 µs
(+22.90%)Baseline: 1,595,852.59 µs
1,675,645.22 µs
(117.05%)

tests/benchmarks/test_big_array.py::test_big_array_executable📈 view plot
🚷 view threshold
🚨 view alert (🔔)
8,155,660.04 µs
(+16.23%)Baseline: 7,017,018.16 µs
7,367,869.07 µs
(110.69%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_check📈 view plot
🚷 view threshold
🚨 view alert (🔔)
50,547.73 µs
(+10.27%)Baseline: 45,838.95 µs
48,130.90 µs
(105.02%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
110,151.43 µs
(-43.93%)Baseline: 196,442.77 µs
206,264.91 µs
(53.40%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executable📈 view plot
🚷 view threshold
🚨 view alert (🔔)
612,260.06 µs
(+15.87%)Baseline: 528,407.93 µs
554,828.32 µs
(110.35%)

tests/benchmarks/test_prelude.py::test_import_guppy📈 view plot
🚷 view threshold
🚨 view alert (🔔)
51.42 µs
(+24.91%)Baseline: 41.16 µs
43.22 µs
(118.96%)

🐰 View full continuous benchmarking report in Bencher

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 9, 2026

🐰 Bencher Report

Branchna/issue1348-error-message-for-missing-return
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes
(Result Δ%)
Upper Boundary
nodes
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
140.94 x 1e3
(0.00%)Baseline: 140.94 x 1e3
142.35 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
6,592.00
(0.00%)Baseline: 6,592.00
6,657.92
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
18.59 x 1e3
(0.00%)Baseline: 18.59 x 1e3
18.78 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
608.00
(0.00%)Baseline: 608.00
614.08
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.39%. Comparing base (2ba5720) to head (9d0755d).
⚠️ Report is 37 commits behind head on main.

Files with missing lines Patch % Lines
...g-internals/src/guppylang_internals/cfg/builder.py 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1486      +/-   ##
==========================================
- Coverage   93.54%   93.39%   -0.15%     
==========================================
  Files         127      128       +1     
  Lines       11797    12004     +207     
==========================================
+ Hits        11035    11211     +176     
- Misses        762      793      +31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nicolaassolini-qntm nicolaassolini-qntm marked this pull request as ready for review February 9, 2026 13:47
@nicolaassolini-qntm nicolaassolini-qntm requested a review from a team as a code owner February 9, 2026 13:47
Comment thread tests/error/misc_errors/no_return_2.err
Comment thread tests/error/misc_errors/no_return_2.err
Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/checker/errors/generic.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/error.py
Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
@nicolaassolini-qntm
Copy link
Copy Markdown
Contributor Author

I have refactored the error point search; it should be better now. I also added a couple of extra test cases

@nicolaassolini-qntm
Copy link
Copy Markdown
Contributor Author

I also moved the test files to misc_errors

@maximilianruesch maximilianruesch changed the title feat: added a more precise error message when missed return statement is inside branch feat: Provide a more precise error message when missed return statement is inside branch Mar 3, 2026
Copy link
Copy Markdown
Collaborator

@mark-koch mark-koch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the new algorithm is looking a lot better! Also sorry for the long delay in getting back to you 😅

Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
# Best solution here is give up on finding the missing return point,
# considering node[-1] as error point
# together with the help on the branch condition.
return None, (fbb_ancestor.branch_pred, 0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it always 0 here?

Copy link
Copy Markdown
Contributor Author

@nicolaassolini-qntm nicolaassolini-qntm Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if the return is inside the loop, the best suggestion we suggest to add a return when the loop condition is false. Added in the comment explanation.

Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/cfg/builder.py Outdated
Copy link
Copy Markdown
Collaborator

@mark-koch mark-koch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me!

@nicolaassolini-qntm nicolaassolini-qntm added this pull request to the merge queue Mar 17, 2026
Merged via the queue into main with commit 436d032 Mar 17, 2026
8 of 9 checks passed
@nicolaassolini-qntm nicolaassolini-qntm deleted the na/issue1348-error-message-for-missing-return branch March 17, 2026 13:01
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.

Confusing error message for missing return statement

3 participants