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

Properly handle semantically anonymous functions #1666

Merged
merged 3 commits into from Feb 3, 2021
Merged

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Feb 3, 2021

Fixes the compiler not being able to refer back to named functions declared inside of functions, and makes sure that functions that are semantically anonymous (i.e. named but are part of an expression) do not conflict with named functions when initializing their program elements.

fixes #1652

  • I've read the contributing guidelines

@dcodeIO dcodeIO requested a review from MaxGraey February 3, 2021 22:59
@MaxGraey
Copy link
Member

MaxGraey commented Feb 3, 2021

Oh, nice! Does it allow dependent direct and indirect function call depend on context? Like:

const foo = (x: i32): i32 => {
  return x;
}

foo(2); // direct call

function test(): (x: i32) => i32 {
  return foo;
}

test()(2); // indirect call

and same for declaration functions:

function foo(x: i32): i32 {
  return x;
}

foo(2); // direct call

function test(): (x: i32) => i32 {
  return foo;
}

test()(2); // indirect call

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 3, 2021

This currently always results in an indirect call due to using a local to refer back. I guess static lookups should be possible, though, similar to how it works on a non-function level. May need a bit more resolver infrastructure.

@MaxGraey
Copy link
Member

MaxGraey commented Feb 3, 2021

Ok, probably better to do it in a separate PR

@dcodeIO dcodeIO merged commit 368fda0 into master Feb 3, 2021
@dcodeIO dcodeIO deleted the issue-1652 branch June 1, 2021 15:20
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.

function pointers with some names may couse to endless compilation
2 participants