chore: Add secondary message for UnknownLoopBound error #4268
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem*
Resolves #3687
Summary*
This simply adds a secondary message to clarify that using a slice length will lead to the
Could not determine loop bound at compile-time
error.I was thinking of disabling this earlier during type check but we don't necessarily know that we will have a slice until codegen as arrays and slices are polymorphic with one another. I also thought about making a separate runtime error to check during loop unrolling but we are not necessarily going to still have the
ArrayLen
call codegen'd in SSA and will instead have the call's results for the loop condition, so this isn't a basic check and some more logic would be needed.The best option for a specific error check seems to be during
codegen_for
before we codegen the end range. We can check whether we are making a slice ArrayLen call for the end range. These changes all felt a bit much as the error is quite clear except for this one error case and thus a secondary message felt sufficient.If we would like the error to be more specific for the failure case then I can look at adding logic that triggers an error for a slice length loop bound.
An example of the error now:

Additional Context
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.