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

[gaml] Wrong implicit casting when directly manipulating elements of a container of unknown type elements #385

Open
lesquoyb opened this issue Dec 17, 2024 · 0 comments
Labels
About GAML This issue concerns the GAML language 😱 Bug The issue reveals a bug in GAMA

Comments

@lesquoyb
Copy link
Contributor

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:

  1. Run the model
  2. 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

@lesquoyb lesquoyb added 😱 Bug The issue reveals a bug in GAMA About GAML This issue concerns the GAML language labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
About GAML This issue concerns the GAML language 😱 Bug The issue reveals a bug in GAMA
Projects
None yet
Development

No branches or pull requests

1 participant