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

uninstantiated generic classes should not include an invalid specialization in the AST #996

Closed
tdp2110 opened this issue May 14, 2024 · 2 comments

Comments

@tdp2110
Copy link
Contributor

tdp2110 commented May 14, 2024

Describe the bug
Consider test.sv:

class foo # (type T);
endclass

module top;
endmodule

./bin/slang test.sv --ast-json test.json produces

{
  "design": {
    "name": "$root",
    "kind": "Root",
    "addr": 6583145610400,
    "members": [
      {
        "name": "",
        "kind": "CompilationUnit",
        "addr": 6583146894560,
        "members": [
          {
            "name": "foo",
            "kind": "GenericClassDef",
            "addr": 6583146874256,
            "specializations": [
              {
                "name": "foo",
                "kind": "ClassType",
                "addr": 6583146895168,
                "members": [
                  {
                    "name": "T",
                    "kind": "TypeParameter",
                    "addr": 6583146895416,
                    "type": "<error>",
                    "isLocal": false,
                    "isPort": true,
                    "isBody": false
                  }
                ],
                "isAbstract": false,
                "isInterface": false,
                "isFinal": false,
                "genericClass": "6583146874256 foo",
                "implements": [
                ]
              }
            ]
          }
        ]
      },
      {
        "name": "top",
        "kind": "Instance",
        "addr": 6583146895040,
        "body": {
          "name": "top",
          "kind": "InstanceBody",
          "addr": 6583146894856,
          "definition": "6583145479168 top"
        },
        "connections": [
        ]
      }
    ]
  },
  "definitions": [
    {
      "name": "top",
      "kind": "Definition",
      "addr": 6583145479168,
      "defaultNetType": "6583145608160 wire",
      "definitionKind": "Module",
      "defaultLifetime": "Static",
      "unconnectedDrive": "None"
    }
  ]
}

Notice specializations of the generic class contains one member, which has an invalid type parameter. These are created, on purpose, for diagnostic purposes (see https://github.com/MikePopoloski/slang/blob/master/source/ast/ElabVisitors.h#L447-L454), but they probably shouldn't persist in the AST. Am I wrong?

To Reproduce

See above commands.

Additional context
Thanks, you rock.

@MikePopoloski
Copy link
Owner

Yeah, probably the invalid specialization should not be added to the specialization map. Or at the very least it can be filtered out during serialization.

@MikePopoloski
Copy link
Owner

Fixed in ff952d5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants