Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Param folding of if expression can result in compiler error #15542

Open
dlongnecke-cray opened this issue Apr 17, 2020 · 2 comments
Open

Param folding of if expression can result in compiler error #15542

dlongnecke-cray opened this issue Apr 17, 2020 · 2 comments

Comments

@dlongnecke-cray
Copy link
Contributor

dlongnecke-cray commented Apr 17, 2020

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 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) then 128 else (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()

Compile command:
chpl test.chpl

Execution command:
./test

Associated Future Test(s):

test/param/ifExprCopyInitBug.chpl

@e-kayrakli
Copy link
Contributor

Possibly related: #14317, #14309, #14301, #14279

@mppf
Copy link
Member

mppf commented Feb 8, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants