winglang / wing

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

Very confusing compiler diagnostics after incomplete `if` clause #6644

Open eladb opened 3 months ago

eladb commented 3 months ago

I tried this:

bring cloud;

struct ApiEndpoint {
  api: cloud.Api?;
  path: str;
}

struct DoubleEdgedFunctionProps {
  api: ApiEndpoint?;
}

class DoubleEdgedFunction extends cloud.Function {
  new(handler: cloud.IFunctionHandler, props: DoubleEdgedFunctionProps) {
    super(handler);

    if let api = 
  }
}

new DoubleEdgedFunction(inflight () => {
  log("hello, world");
});

This happened:

Failed to compile.

error: Unexpected 'import_statement'
  --> main.w:1:1
  |
1 | bring cloud;
  | ^^^^^^^^^^^^

error: Unexpected 'struct_definition'
  --> main.w:3:1
  |  
3 | / struct ApiEndpoint {
4 | |   api: cloud.Api?;
5 | |   path: str;
6 | | }
  | \-^

error: Unexpected 'struct_definition'
   --> main.w:8:1
   |  
 8 | / struct DoubleEdgedFunctionProps {
 9 | |   api: ApiEndpoint?;
10 | | }
   | \-^

error: Unexpected 'identifier'
   --> main.w:12:7
   |
12 | class DoubleEdgedFunction extends cloud.Function {
   |       ^^^^^^^^^^^^^^^^^^^

error: Unexpected 'custom_type'
   --> main.w:12:35
   |
12 | class DoubleEdgedFunction extends cloud.Function {
   |                                   ^^^^^^^^^^^^^^

error: Unexpected 'parameter_list'
   --> main.w:13:6
   |
13 |   new(handler: cloud.IFunctionHandler, props: DoubleEdgedFunctionProps) {
   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Unexpected 'super_constructor_statement'
   --> main.w:14:5
   |
14 |     super(handler);
   |     ^^^^^^^^^^^^^^^

error: Unexpected 'if_let_statement'
   --> main.w:16:5
   |  
16 | /     if let api = 
17 | |   }
18 | | }
19 | | 
20 | | new DoubleEdgedFunction(inflight () => {
21 | |   log("hello, world");
22 | | });
   | \--^

error: Unknown parser error
   --> main.w:17:3
   |  
17 | /   }
18 | | }
   | \-^

error: Expected block
   --> main.w:22:3
   |
22 | });
   |   ^

I expected this:

No response

Is there a workaround?

No response

Anything else?

No response

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Community Notes

staycoolcall911 commented 3 months ago

This reminded me of #6549, however it does not seem to be the same case

github-actions[bot] commented 2 weeks ago

Hi,

This issue hasn't seen activity in 90 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!