Intent "in real", but compiler accepts a whole array?

Hello! The following code compiles and runs without errors:

var towsons: domain(string);
towsons = {"red","green","yellow","blue"};
var woff: [towsons] real;
woff["red"] = 1.0;
woff["green"] = 2.0;
woff["yellow"] = 3.0;
woff["blue"] = 4.0;
planrot(woff);          // Why does chapel allow this?
planrot(woff["blue"]);  // This should be ok
proc planrot(in woff: real) {

But to me it does not make sense, and I would expect that the first call ("planrot(woff)") should trigger a compilation error... Could someone explain me why it does not? It looks like the same thing as sin(array) returning a whole array of sines, but planrot does not return anything ...

cheers Nelson

I figured: it is promotion, and is well documented. Last thought: is there any way to prevent promotion when it really does not make sense?



If you want to prevent promoting an array for a particular function you could have an overload that takes an array and produces a compiler error when that case resolves. So something like this:

proc foo(x : [] real) do
  compilerError('foo may not be used for promotion');

proc foo(x : real) do

var A : [0..10] real;
foo(A); // will resolve to version of function that errors

Hi Andy:
great! thanks a lot.

1 Like

If that feels too burdensome, I think it would be reasonable to make a
feature request for an attribute that squashes that for you, e.g.
something like @noPromotionAllowed or something that could be attached
to functions.


1 Like

Hi Lydia; thanks, but I don't think it is necessary. Promotion is a very
nice feature,
and I should have been more aware of it by now. Andy's solution works well
for me.



1 Like