Skip to content

Fix issue with calling generics #81

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

Merged
merged 1 commit into from
Jun 10, 2025
Merged

Fix issue with calling generics #81

merged 1 commit into from
Jun 10, 2025

Conversation

nc6
Copy link
Collaborator

@nc6 nc6 commented Jun 6, 2025

Issue #80 identified a case where the resolver would hang when calling a generic function with a parameter whose name matched the name of the argument.

This occurred due to the order of resolution. Since we resolved bindings in a depth-first fashion, we simply ended up resolving a generic parameter to itself.

One way to resolve this would have been to synthesize new names for each parameter in the scope of a local binding. But generating names and ensuring they are all unique is annoying. Instead, we switch the order of resolution. When binding generic args, we first resolve the arguments before traversing the body.

That is, for a replacement series

int -> x -> x

We previously did

int -> (x -> x)

whereas now we do

(int -> x) -> x

Since the top-level (LHS) is always concrete, this process must terminate.

Issue #80 identified a case where the resolver would hang when calling a
generic function with a parameter whose name matched the name of the
argument.

This occurred due to the order of resolution. Since we resolved bindings
in a depth-first fashion, we simply ended up resolving a generic
parameter to itself.

One way to resolve this would have been to synthesize new names for each
parameter in the scope of a local binding. But generating names and
ensuring they are all unique is annoying. Instead, we switch the order
of resolution. When binding generic args, we first resolve the arguments
before traversing the body.

That is, for a replacement series

int -> x -> x

We previously did

int -> (x -> x)

whereas now we do

(int -> x) -> x

Since the top-level (LHS) is always concrete, this process must
terminate.
@nc6 nc6 requested a review from jasagredo June 6, 2025 11:45
@jasagredo jasagredo linked an issue Jun 10, 2025 that may be closed by this pull request
@nc6 nc6 merged commit d10bd6c into master Jun 10, 2025
5 checks passed
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.

Cuddle hangs on duplicate name for generic variable
2 participants