Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for use domain formal before defined (#26664)
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: ```chapel proc foo(baz: t, type t) { //... } ``` Here the formal `baz` is declared as having the type `t`, and `type 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: ```chapel proc foo(type t, baz: t) { //... } ``` However, because we can’t enforce domain type bounds at compile time, doing something similar with a domain appeared to work. ```chapel proc bar(baz: [d] real, d:domain(1)) { //... } ``` 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!]
- Loading branch information