add tests for use domain formal before defined #26664
Merged
+17
−0
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.
Add regression test for a formal pattern that was previously allowing the use of formals before they were defined due to a bug/limitation in the compiler.
As an example, consider the following function signature:
Here the formal
baz
is declared as having the typet
, andtype t
is defined as the second formal.The compiler rightly complains that we've used the
type t
before it was defined.The solution is to reorder the formals such that the type t is defined first:
However, because we can’t enforce domain type bounds at compile time, doing something similar with a domain appeared to work.
This appeared to work because behind the scenes, the compiler is rewriting this array domain expression into the function body as an internal call due to special handling of array domain expressions.
As we move more of the resolution process into the new compiler (Dyno), errors like this are detected at compile time and so formals need to observe the same define-before-use rules as other variables.
This requires reordering the formals such that the domain comes before the array formal that uses it. If call sites do not use named arguments, their ordering will similarly need to be adjusted.
[reviewed by @mppf - thanks!]