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

New type for "dynamic type" declarations #1667

Open
oxisto opened this issue Sep 3, 2024 · 0 comments
Open

New type for "dynamic type" declarations #1667

oxisto opened this issue Sep 3, 2024 · 0 comments
Labels
discussion Label for issues or future features to be discussed before putting them onto the road-map javascript python typescript

Comments

@oxisto
Copy link
Member

oxisto commented Sep 3, 2024

For languages that do not have static types (such as JavaScript and Python), we probably need a distinct new Type, especially for declarations. The existing types do not really match this dynamic type.

  • UnknownType should only be used for nodes whose type information are not available (yet). This is the default for inferred nodes or for nodes where we only can parse type information at a later stage and need to set "some" unknown type at the point of creation
  • AutoType might be close to it, but this is used for scenarios where the compiler knows the exact time at build time, but the developer is too "lazy" to explicitly write the type. Examples includes C++ auto keywords or snippets like var a = "test" in Go. Basically, it can only be used for variable declarations, which have an initializer because type information is used from it.

A simple example to illustrate it in Python:

a = "test"
a = 2

In line 1, we create a new VariableDeclaration (in a pass) and the line represents an assignment to the Reference a. Currently, we set the type to unknown.
In line 2, we only have an assignment to a. The type of the reference to a can be inferred to int. The type of the variable declaration is not really determinable, but the assignedTypes could be set to int and str.

In the current implementation, we have the following problem:

  1. Since the type of a is unknown, it will get the type of the first assignment, and after translation, the type of variable a is str and assigned types is str. This is incorrect
  2. The type of the first ref is str and assigned types are str. This is ok
  3. The type of the second ref is str (probably propagated from the variable) and assigned types are str, int. This is also incorrect.
@oxisto oxisto added documentation Improvements or additions to documentation discussion Label for issues or future features to be discussed before putting them onto the road-map python typescript javascript and removed documentation Improvements or additions to documentation labels Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Label for issues or future features to be discussed before putting them onto the road-map javascript python typescript
Projects
None yet
Development

No branches or pull requests

1 participant