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

Resolving identifier for aliased type imports #950

Closed
muhabdulkadir opened this issue Nov 29, 2024 · 0 comments
Closed

Resolving identifier for aliased type imports #950

muhabdulkadir opened this issue Nov 29, 2024 · 0 comments

Comments

@muhabdulkadir
Copy link
Contributor

Bug Report 🐛

We have identified an issue with how aliased imports are resolved in the metamodel's abstract syntax tree (AST). Currently, we determine the presence of an aliased import by checking for the aliased types property in the import statement and verifying the available names.

However, when parsing models, we observe that the alias name is used as the reference instead of the original imported name. During model resolution involving alias imports, we expect the actual import type name to be used along with its corresponding namespace to differentiate between locally declared types and imported types. Historically, the alias name has been used as the reference, while still being linked to the namespace of the imported model. This behavior is problematic because the alias name does not exist in the imported model. Consequently, we should use the actual imported type name for references.

Expected Behavior

The model should resolve using the actual name of the imported type, ensuring that the namespace is correctly referenced to differentiate between local types and imports.

Current Behavior

Currently, when a model is resolved, the alias name is used as the reference, which is invalid because the alias name does not exist in the imported model.

Example:

Given the following model:

namespace [email protected]

import [email protected].{A as B}

concept C extends B {
  o B b
}

The resolution would look like:

{
  "namespace": "[email protected]",
  "imports": [
    {
      "namespace": "com.test.another",
      "types": ["A"],
      "aliasedTypes": [{"name": "A", "aliasedName": "B"}]
    }
  ],
  "declarations": [
    {
      "name": "C",
      "properties": [
        {
          "name": "b",
          "type": {"name": "B", "namespace": "[email protected]"}
        }
      ],
      "superType": {"name": "B", "namespace": "[email protected]"}
    }
  ]
}

Possible Solution

To resolve this issue, we should update the logic to use the original type name rather than the alias. This ensures that when we resolve models, the reference is based on the imported type name, as shown below:

Corrected Example:

{
  "namespace": "[email protected]",
  "imports": [
    {
      "namespace": "com.test.another",
      "types": ["A"],
      "aliasedTypes": [{"name": "A", "aliasedName": "B"}]
    }
  ],
  "declarations": [
    {
      "name": "C",
      "properties": [
        {
          "name": "b",
          "type": {"name": "A", "namespace": "[email protected]"}
        }
      ],
      "superType": {"name": "A", "namespace": "[email protected]"}
    }
  ]
}

Steps to Reproduce

  1. Create a model with an aliased import.
  2. Resolve the model using the -resolve command via the CLI.

Context (Environment)

Desktop

  • OS: [e.g. macOS]
  • Browser: [e.g. Chrome, Safari]
  • Version: [e.g. 0.22.15]

Detailed Description

Possible Implementation

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

1 participant