const nC = 5;
var xbar,ybar: [1..nC] real;
for C in 1..nC do {
// -----------------------------------------------------------------
// The eigenvalues.
// -----------------------------------------------------------------
var lambda1 = 10.0;
// -----------------------------------------------------------------
// Find the ellipse for each cluster.
// -----------------------------------------------------------------
ErrorTest(lambda1,xbar,ybar);
}
proc ErrorTest(
const in lambda1: real,
out xbar: real,
out ybar: real) {
xbar = lambda1;
ybar = lambda1 + 1.0;
}
Produces an error message that is somewhat cryptic:
trials$ chpl outerror.chpl
outerror.chpl:11: internal error: AST-FOR-LLS-01346 chpl version 2.8.0
Note: This source location is a guess.
Internal errors indicate a bug in the Chapel compiler,
and we're sorry for the hassle. We would appreciate your reporting this bug --
please see https://chapel-lang.org/bugs.html for instructions. In the meantime,
the filename + line number above may be useful in working around the issue.
The error itself is not hard to spot: the procedure call should have been
ErrorTest(lambda1,xbar[C],ybar[C]);
However, I expected the compiler to identify the error in the type passed ([ ] real instead of real) and to issue an error message about the wrong type being used. Could this be a compiler bug?
It is of course the programmer's (myself) responsibility to know the language features and understand what happens when inserting an array in lieu of a scalar triggers promotion. On the other hand, because promotion is much less frequently needed than standard scalar arguments, I wonder if it would make sense to make promotion an explicit request (instead of an automatic decision by the compiler), as in
proc haversine( const in x: || real) : || real {
return sin(x/2)**2 ;
}
Then the compiler would know that haversine is a candidate for promotion. Just a thought: neither a priority nor an actual feature request ...