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

Fix first-class-functions as arguments to classes #24587

Closed
wants to merge 3 commits into from

Conversation

DanilaFe
Copy link
Contributor

@DanilaFe DanilaFe commented Mar 12, 2024

Fixes #23701.

This PR resolves an internal error that can be triggered by programs that use FCFs as arguments to classes or records:

record r {
    var containedValue;
}

var x = new r(proc() { return 42; });

The bug was that the FCF was converted into a call to a factory function (e.g. fcfFactory()), and replaced in the parent expression. However, the resolution code downstream expects a normalized program, and new r(fcfFactory()) is not normalized. This led to an assertion error.

This PR fixes the issue by introducing a new temporary to store the result of fcfFactory(). This means that the normalization of the program is preserved, and downstream code does not cause errors. Since the FCF transformation happens mid-resolution, I have to explicitly call resolveExpr to ensure the temporary and its initializer have their types computed.

Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
@DanilaFe DanilaFe marked this pull request as draft March 12, 2024 16:53
@DanilaFe
Copy link
Contributor Author

Closing in favor of #25615.

@DanilaFe DanilaFe closed this Jul 23, 2024
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

Successfully merging this pull request may close these issues.

Internal error calling a generic type's initializer with FCP
1 participant