Open jabraham17 opened 1 week ago
I believe this is a quirk of range being generic with defaults, such that range(?) gives you the defaults.
I'd also expect that range(?)
should not get you the defaults. In other cases, I believe that's the case, such as:
var r: range(?) = 1..10 by -2;
writeln(r);
proc foo(r: range(?)) {
writeln(r);
}
foo(r);
which works as expected.
Your issue also seems to be consistent for other fully-defaulted generics:
record R {
param n = 1;
}
proc foo(): R(?) {
return new R(n=2);
}
writeln(foo()); // similar error
But interestingly, not for partially-defaulted generics:
record R {
param n = 1;
param k;
}
proc foo(): R(?) {
return new R(n=2, k=33);
}
writeln(foo()); // works
[edited to update comments, which I'd copied without updating]
Summary of Problem
Description:
Attempting to specify a generic return type for a range with a non-default type results in an error. However, fully specifying the return type does work. And just removing the explicit return type also works.
I believe this is a quirk of range being generic with defaults, such that
range(?)
gives you the defaults. I would have expected thatrange
says "the return type is a range with the type defaults" andrange(?)
says "the return type is a range with unknown type"Steps to Reproduce
Source Code:
Compile command:
chpl foo.chpl
Configuration Information
chpl --version
: 2.2$CHPL_HOME/util/printchplenv --anonymize
:gcc --version
orclang --version
: LLVM 18