-
Notifications
You must be signed in to change notification settings - Fork 9
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
[gaml] Wrong implicit casting when directly manipulating elements of a container of unknown type elements #385
Comments
First of all, the way type inference works in containers is by finding the common super type of all values. Here, it is The semantics of
In the latter case, It is also confusing because in some cases we want type inference and in other cases no. For instance, in another instance of var declaration, when I write What is the common denominator of all this ? Well, i think it is quite easy:
It is probably not too difficult to implement. The only drawback is that we do not allow (anymore) the |
- Declaration of attributes now systematically respect the type provided by the modeller (no type inference) - if a local variable declaration provides a type, it is also respected (no type inference) - type inference is however done when no explicit type is provide (let, loop, etc.) Adjustments to various models of the library, which were relying on blind type inference, especially for files.
Describe the bug
I was investigating the problems mentioned in this discussion and noticed that the type resolution for elements in a map is different when using directly
map[key]
than when passing by an intermediary variable.Here is an example:
The last type casting is wrong, my guess is that it is using the type of the first element in the map. You can test it by changing the first element by a string instead and you will notice that this time gama raises an exception at the last line, but the second works as expected.
The same also applies to list of unknown type:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
That when accessing an element inside a map directly it behaves in the same way as when storing it in a variable.
Additional context
I've ruled out the
unknown
type alone as being the problem, as if you store an int inside an unknown and perform operations on it, everything works normally, so it really is about the maps and lists of unknown element types.I think it's not the first time we have that kind of weird behaviours with types "changing" a bit on the fly depending on how variables are accessed. It could be a good idea to cover this by a dedicated unit test model
The text was updated successfully, but these errors were encountered: