New type for "dynamic type" declarations #1667
Labels
discussion
Label for issues or future features to be discussed before putting them onto the road-map
javascript
python
typescript
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 creationAutoType
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 likevar a = "test"
in Go. Basically, it can only be used for variable declarations, which have aninitializer
because type information is used from it.A simple example to illustrate it in Python:
In line 1, we create a new
VariableDeclaration
(in a pass) and the line represents an assignment to the Referencea
. Currently, we set thetype
to unknown.In line 2, we only have an assignment to
a
. Thetype
of the reference toa
can be inferred toint
. The type of the variable declaration is not really determinable, but theassignedTypes
could be set toint
andstr
.In the current implementation, we have the following problem:
a
is unknown, it will get the type of the first assignment, and after translation, thetype
of variable a isstr
and assigned types isstr
. This is incorrecttype
of the first ref isstr
and assigned types arestr
. This is oktype
of the second ref isstr
(probably propagated from the variable) and assigned types arestr, int
. This is also incorrect.The text was updated successfully, but these errors were encountered: