You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Param folding of if expressions can result in a compiler error depending on the branch expressions. In my specific case, futures filed for tuples in #15394 failed because they were unable to resolve a call to chpl__initCopy. Relying on a different mechanism such as a where clause sidesteps the issue.
While our specific failures occurred when a branch expression tried to copy initialize an owned class or a borrowed class, I think that the failure might occur any time a copy initializer requires a ref argument.
Steps to Reproduce
Source Code:
class C { var x:int=0; }
proc test(type T) {
// Trivially evaluate to second branch.var a =if isTuple(T) then128else (128, new T(256));
writeln(a);
}
type T1 =owned C;
proc main() {
test(T1);
}
Output:
test.chpl:3: In function 'test':
test.chpl:5: error: non-lvalue actual is passed to a 'ref' formal of chpl__initCopy()
Here are two issues about how param folding interacts with return (which is not the topic of this issue but I tend to find this one with my searches so am leaving a breadcrumb here): #14683#18597
Summary of Problem
Param folding of if expressions can result in a compiler error depending on the branch expressions. In my specific case, futures filed for tuples in #15394 failed because they were unable to resolve a call to
chpl__initCopy
. Relying on a different mechanism such as awhere
clause sidesteps the issue.While our specific failures occurred when a branch expression tried to copy initialize an
owned
class or aborrowed
class, I think that the failure might occur any time a copy initializer requires aref
argument.Steps to Reproduce
Source Code:
Output:
Compile command:
chpl test.chpl
Execution command:
./test
Associated Future Test(s):
test/param/ifExprCopyInitBug.chpl
The text was updated successfully, but these errors were encountered: