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

Invalid JSII library: failed to add property init to class #5441

Closed
meirdev opened this issue Jan 15, 2024 · 6 comments
Closed

Invalid JSII library: failed to add property init to class #5441

meirdev opened this issue Jan 15, 2024 · 6 comments
Assignees
Labels
🐛 bug Something isn't working good first issue Good for newcomers refactor

Comments

@meirdev
Copy link
Contributor

meirdev commented Jan 15, 2024

I tried this:

Minimal (added by @eladb):

bring "@cdktf/provider-docker" as tfdocker;

new tfdocker.container.Container();
// npm i -D @cdktf/provider-docker

bring cloud;

bring "@cdktf/provider-docker" as tfdocker;

pub class Test {
    new() {
        let image = new tfdocker.image.Image(name: "ubuntu");
        let container = new tfdocker.container.Container(image: image.id, name: "test");
    }
}

This happened:

Compiler bug during type-checking ('panicked at libs/wingc/src/type_check/jsii_importer.rs:585:22:
Invalid JSII library: failed to add property init to class: TypeError { message: "Symbol \"init\" already defined in this scope", span: WingSpan { start: WingLocation { line: 0, col: 0 }, end: WingLocation { line: 0, col: 0 }, file_id: "" }, annotations: [DiagnosticAnnotation { message: "previous definition", span: WingSpan { start: WingLocation { line: 0, col: 0 }, end: WingLocation { line: 0, col: 0 }, file_id: "" } }] }'), please report at https://www.winglang.io/contributing/start-here/bugs

I expected this:

No response

Is there a workaround?

No response

Anything else?

The relevant parts:

@cdktf/provider-docker.container.ContainerConfig

        {
          "abstract": true,
          "docs": {
            "remarks": "If unset this will default to the `dockerd` defaults.\n\nDocs at Terraform Registry: {@link https://registry.terraform.io/providers/kreuzwerker/docker/3.0.2/docs/resources/container#init Container#init}",
            "stability": "stable",
            "summary": "Configured whether an init process should be injected for this container."
          },
          "immutable": true,
          "locationInModule": {
            "filename": "src/container/index.ts",
            "line": 129
          },
          "name": "init",
          "optional": true,
          "type": {
            "union": {
              "types": [
                {
                  "primitive": "boolean"
                },
                {
                  "fqn": "cdktf.IResolvable"
                }
              ]
            }
          }
        },
@cdktf/provider-docker.container.Container

        {
          "docs": {
            "stability": "stable"
          },
          "locationInModule": {
            "filename": "src/container/index.ts",
            "line": 3785
          },
          "name": "init",
          "type": {
            "union": {
              "types": [
                {
                  "primitive": "boolean"
                },
                {
                  "fqn": "cdktf.IResolvable"
                }
              ]
            }
          }
        },

If I manually change the init name to something else it works.

Wing Version

0.54.36

Node.js Version

v18.16.0

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.
@meirdev meirdev added the 🐛 bug Something isn't working label Jan 15, 2024
@Chriscbr
Copy link
Contributor

Perhaps we can store initializers under a different name in class symbol environments - for example "constructor" or "$init" instead of "init"?

@Chriscbr Chriscbr added the good first issue Good for newcomers label Jan 15, 2024
@eladb
Copy link
Contributor

eladb commented Jan 16, 2024

It's a completely internal name, correct?

@Chriscbr
Copy link
Contributor

Chriscbr commented Jan 16, 2024

Sort of. The compiler currently couples together the names of symbols with the code we generate for them in JavaScript code. (Definitely something we could decouple, but since we're no longer converting names between camelCase and snake_case etc. there haven't been many cases where we need this).

Technically the solution I mentioned would prevent you from adding your own method named $init, but I think it's OK. (For similar reasons you can't name a method $inflight_init today 🙂).

Maybe $preflight_init would make the chance of collision with real world libraries less likely

@eladb
Copy link
Contributor

eladb commented Jan 17, 2024

Do we even support $ in symbols? (I think we shouldn't)

@MarkMcCulloh
Copy link
Contributor

Do we even support $ in symbols? (I think we shouldn't)

Yes
https://github.com/winglang/wing/blob/main/libs/tree-sitter-wing/grammar.js#L67

@tsuf239
Copy link
Collaborator

tsuf239 commented May 16, 2024

Those following two examples were compiled to tf-aws without a problem, on 0.73.47

bring cloud;
bring "@cdktf/provider-docker" as tfdocker;

new tfdocker.provider.DockerProvider();
pub class Test {
    new() {
        let image = new tfdocker.image.Image(name: "ubuntu");
        let container = new tfdocker.container.Container(image: image.id, name: "test");
    }
}

and

bring "@cdktf/provider-docker" as tfdocker;

new tfdocker.provider.DockerProvider();
new tfdocker.container.Container({image: "iii", name: "eee"});

probably because of this: #6242 (and that one #4870 that was merge before the error appear)

@tsuf239 tsuf239 closed this as completed May 16, 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 good first issue Good for newcomers refactor
Projects
Archived in project
Development

No branches or pull requests

6 participants