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.03k stars 197 forks source link

Class Declaration: `init()` - verify all fields are initialized #1446

Open staycoolcall911 opened 1 year ago

staycoolcall911 commented 1 year ago

Community Note

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.

Feature Spec

The compiler now throws an error when a resource init() method is not initializing a resource field.

For example, consider this wing code:

bring cloud;

class MyResource {
    _bucket: cloud.Bucket;
    new() {
    }
}

Compilation should throw an error: "Error at code.w:6:1 | MyResource init failed to initialize field _bucket"

Use Cases

See above.

Implementation Notes

This requires some Control Flow Analysis. We could start with something basic that will not allow conditional initialization (if statement) and will simply check that all fields have an initialization statement inside init().

Component

Compiler

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!

marciocadev commented 1 year ago

Hey @staycoolcall911

I think this issue is close on PR #2391

staycoolcall911 commented 1 year ago

Thanks @marciocadev ! However, I think this issue is still not fully supported - please see the implementation notes section in the issue description above. For example, this code currently passes compilation:

class A {
 x: num;
 new(a: num) {
  if a == 1 {
   this.x = a;
  }
 }
}
github-actions[bot] commented 5 months 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!