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

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

Closed
skorfmann opened this issue Nov 27, 2023 · 4 comments
Closed

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

skorfmann opened this issue Nov 27, 2023 · 4 comments
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler

Comments

@skorfmann
Copy link
Contributor

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 #4993

Wing Version

0.50.6

Node.js Version

18.7

Platform(s)

MacOS

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@skorfmann skorfmann added the 🐛 bug Something isn't working label Nov 27, 2023
@monadabot monadabot added this to Wing Nov 27, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New - not properly defined in Wing Nov 27, 2023
@staycoolcall911 staycoolcall911 moved this from 🆕 New - not properly defined to 🤝 Backlog - handoff to owners in Wing Nov 28, 2023
skorfmann added a commit to winglang/examples that referenced this issue Nov 28, 2023
but might be related to
@skorfmann
Copy link
Contributor Author

Looks a bit similar to #3717 but this might be a coincidence

Copy link

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
Copy link
Contributor

Chriscbr commented Feb 27, 2024

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 };
}));

@Chriscbr Chriscbr added this to the Winglang Stable Release milestone Feb 27, 2024
@yoav-steinberg
Copy link
Contributor

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.

@github-project-automation github-project-automation bot moved this from 🤝 Backlog - handoff to owners to ✅ Done in Wing Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler
Projects
Archived in project
Development

No branches or pull requests

4 participants