winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.07k stars 198 forks source link

Function Types: support implicit forward declarations #480

Open staycoolcall911 opened 2 years ago

staycoolcall911 commented 2 years ago

This, for example, should be supported:

let f = () => {
  x = 1;
}
let x = 2;

This was split from https://github.com/winglang/wing/issues/25

ekeren commented 1 year ago

@yoav-steinberg , I understand that we want to support function forward deceleration, but I am not so sure about this example.

Can you explain why we want to support this?

yoav-steinberg commented 1 year ago

In this case it's a variable forward declarations (not a function): x is defined in the outer scope after the functions f is defined. So, currently, the compiler will complain that x is an undefined symbol when accessing it in f even though it's actually defined - just in the outer scope.

github-actions[bot] commented 1 year ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 1 year ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

yoav-steinberg commented 1 year ago

Here's another snippet showing the same thing which might be clearer:

class Foo {
  my_method() {
    x = 1;
  //^ Symbol "x" used before being defined
  }
}
let x = 2;

The exact same code in TypeScript works, because TS doesn't care that x is defined after Foo.