18597, "rj-jesus", "Behaviour of the compiler affected by trivial 'else'", "2021-10-20T10:04:04Z"
Summary of Problem
This is a very minor issue (actually, it's mostly just "unexpected behaviour"), but I was trying to use Chapel's polymorphic features to create and initialise arrays from an integer or from a domain in the same function, e.g.
proc foo(len_or_domain) where isDomain(len_or_domain) || isIntegralValue(len_or_domain)
{
if isIntegralValue(len_or_domain) then
return foo({0..<len_or_domain});
//else { // works if I uncomment this else
var a: [len_or_domain] real = 123;
return a;
//}
}
writeln(foo(10));
writeln();
writeln(foo({0..9, 0..9}));
If I uncomment the explicit else
, the code above works. However, if I leave it commented the compiler complains that it can't resolve the function's return type. Since the else
in the code is quite obvious, I was surprised that its presence altered the behaviour of the compiler.