Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two sequential returns at the same level trigger assertion "neighbors.len() <= 1" #6801

Open
alfiedotwtf opened this issue Dec 30, 2024 · 0 comments
Labels
bug Something isn't working triage This issue was opened with a template and needs to be triaged by code owners.

Comments

@alfiedotwtf
Copy link
Contributor

Related Component

compiler

Problem

I had some code, but needed to do some debugging so I added my debugging to the top of the function and then did a return. Something like this:

fn funcname() -> Option<u8> {
  // lots of debug logging
  ...

  return None;
 
  // lots of code
  ...

  // last line in function
  return None;
} 

Which caused the following error:

thread 'main' panicked at sway-core/src/control_flow_analysis/analyze_return_paths.rs:99:13:
assertion failed: neighbors.len() <= 1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I couldn't understand why my debugging was throwing that error and eventually I looked down and saw that last return and then commented it out. Presto it worked. I think assertion failed: neighbors.len() <= 1 may be doing some incorrect optimisation, because if you hide the first return in a branch, then it compiles without an error

Steps

Create the same code as above and try to compile.

Possible Solution(s)

No response

Notes

No response

Installed components

> fuelup check
latest - Up to date
fuelup - Up to date
@alfiedotwtf alfiedotwtf added bug Something isn't working triage This issue was opened with a template and needs to be triaged by code owners. labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage This issue was opened with a template and needs to be triaged by code owners.
Projects
None yet
Development

No branches or pull requests

1 participant