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

Casting to pair gives unexpected values #3806

Closed
lesquoyb opened this issue May 5, 2023 · 1 comment
Closed

Casting to pair gives unexpected values #3806

lesquoyb opened this issue May 5, 2023 · 1 comment
Assignees
Labels
About GAML This issue concerns the GAML language 👍 Fix to be tested 🤔 Question
Milestone

Comments

@lesquoyb
Copy link
Collaborator

lesquoyb commented May 5, 2023

Describe the bug
The casting to a pair results in strange values in some cases:

  • the type of the key is always casted to unknown:
pair<int,int> p <- pair(1::2);
write sample(pair(p));

results in pair<unknown, int>(p) -: 1::2 while the type is explicitly defined for p.

  • casting a list of pair creates a pair where the key is a list of keys and the value is zero:
write sample(pair([1::2, 3::4]));

result in pair<unknown, int>( [1::2,3::4] ) -: [1,3]::0. Either returning the first item or setting the value as the list of all values would make way more sense.

  • casting a point into a pair returns a pair where the key is the point and the value is zero:
write sample(pair(point(1,2,3)));

returns pair<unknown, float>(point(1,2,3)) -: {1.0,2.0,3.0}::0.0, I understand why but it goes against the general casting behaviour for pair when there's no obvious cast which is to take the object and make it the key AND value. We could also decide that casting a point to a pair is just reducing dimensionality and thus pair(point(x,y,z)) => x::y

  • casting a list of one item returns a pair where the key and the value are the only element of the said list, but if there are three or more elements and the type is int or bool then the key is the whole list and the value is 0 or true:
write sample(pair([1]));
write sample(pair([1,2,3]));

returns:

pair<unknown, int>([1]) -: 1::1
pair<unknown, int>([1,2,3]) -: [1,2,3]::0

It is not coherent and as the previous point it goes against the general behaviour of casting into a pair when there's no obvious way of doing so.

  • casting a list of string into a pair gives a key which is the list and a value which is a string containing the list:
write sample(pair(["1","2","3"]));

returns pair<unknown, string>(['1','2','3']) -: ['1','2','3']::'[\'1\',\'2\',\'3\']', I think there's really nobody expecting this from the original cast.

Additional context
Add any other context about the problem here.

@lesquoyb lesquoyb added 🤔 Question About GAML This issue concerns the GAML language labels May 5, 2023
@AlexisDrogoul
Copy link
Member

I've answered most of the issues in the latest commit. Casting is now always following the same rules except for map (list of keys::list of values) and pair obviously.

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 👍 Fix to be tested 🤔 Question
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants