Skip to content
This repository was archived by the owner on Apr 11, 2026. It is now read-only.
This repository was archived by the owner on Apr 11, 2026. It is now read-only.

Casting to pair gives unexpected values #3806

Closed

Description

@lesquoyb

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.

Activity

  1. moved this to Todo in GAMA 1.9.2on May 22, 2023
  2. AlexisDrogoul commented on May 30, 2023

    @AlexisDrogoul
    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.

  3. moved this from Todo to In Progress in GAMA 1.9.2on May 30, 2023
  4. added this to the GAMA 1.9.2 milestone on May 30, 2023
  5. added a commit that references this issue on May 30, 2023
  6. moved this from In Progress to Done in GAMA 1.9.2on May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions