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.05k stars 198 forks source link

can't wrap function in function - unknown symbol "this" #5065

Closed skorfmann closed 7 months ago

skorfmann commented 11 months ago

I tried this:

bring cloud;

let authenticatedMiddleware = (handler: inflight (cloud.ApiRequest): cloud.ApiResponse): inflight (cloud.ApiRequest): cloud.ApiResponse => {
  let middleware = inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
    return handler(req);
  };

  return middleware;
};

see playground

This happened:

Screenshot 2023-11-27 at 20 44 25

Failed to compile.

error: Unknown symbol "this"
  --> wing/main.w:1:1
  |
1 | bring cloud;
  | ^ Unknown symbol "this"

I expected this:

no error

Is there a workaround?

No response

Anything else?

Perhaps related to this, but I'm not sure https://github.com/winglang/wing/pull/4993

Wing Version

0.50.6

Node.js Version

18.7

Platform(s)

MacOS

Community Notes

skorfmann commented 11 months ago

Looks a bit similar to https://github.com/winglang/wing/issues/3717 but this might be a coincidence

github-actions[bot] commented 9 months 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!

Chriscbr commented 8 months ago

The example in the original issue compiles and works now.

However, the alternate case where you write the code as a static method (instead of a free-floating function) causes a runtime error:

bring cloud;

class A {
  pub static authenticatedMiddleware(handler: inflight (cloud.ApiRequest): cloud.ApiResponse): inflight (cloud.ApiRequest): cloud.ApiResponse {
    let middleware = inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
      return handler(req);
    };

    return middleware;
  }
}

let api = new cloud.Api();
api.get("/hello", A.authenticatedMiddleware(inflight (req) => {
  return { status: 200 };
}));
yoav-steinberg commented 7 months ago

However, the alternate case where you write the code as a static method (instead of a free-floating function) causes a runtime error...

Fixed in #6040, closing.