You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
model inttofloat
global {
init {
map<string, unknown> m <- ['b'::1.0, 'a'::1];
write type_of(m['a']);
write type_of(int(m['a'])+1);
write type_of(m['a']+1);
}
}
experiment e;
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:
model inttofloat
global {
init {
list<unknown> m <- [1.0, 1];
write type_of(m[0]);
write type_of(int(m[1])+1);
write type_of(m[1]+1);
}
}
experiment e;
To Reproduce
Steps to reproduce the behavior:
Run the model
See error
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:
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: