- Compiler Used: gcc 6.3.0
- Operating System: Win8, MinGW, Chaiscript 6.0.0
- Architecture (ARM/x86/32bit/64bit/etc): Intel
Expected Behavior
Return a vector with all keys of a map.
In 5.x the following function works without problem:
def keys(map)
{
auto range := range(map); // get a range obj from the map
auto v := Vector(); // create empty vector
while (!range.empty()) // as long as the range has elements
{
v.push_back(range.front().first()); // append key to the vector
range.pop_front(); // remove first element from the range
}
v; // return the new vector
}
print(keys(["1a":111, "2b":222]));
In 6.x.x I wanted to use the new for loop:
def keys(map)
{
auto v := Vector(); // create empty vector
auto i;
for( i : map )
{
v.push_back(i.first()); // append key to the vector
}
v; // return the new vector
}
print(keys(["1a":111, "2b":222]));
Actual Behavior
The version with for( : ) for 6.x.x crashes without exception.
Minimal Example to Reproduce Behavior
def keys(map)
{
auto v := Vector(); // create empty vector
auto i;
for( i : map )
{
v.push_back(i.first()); // append key to the vector
}
v; // return the new vector
}
print(keys(["1a":111, "2b":222]));
Workaround
It looks like, that there is a memory issue. Cloning i.first() will solve the problem:
def keys(map)
{
auto v := Vector(); // create empty vector
auto i;
for( i : map )
{
v.push_back(clone(i.first())); // append key to the vector
}
v; // return the new vector
}
print(keys(["1a":111, "2b":222]));
Expected Behavior
Return a vector with all keys of a map.
In 5.x the following function works without problem:
In 6.x.x I wanted to use the new for loop:
Actual Behavior
The version with for( : ) for 6.x.x crashes without exception.
Minimal Example to Reproduce Behavior
Workaround
It looks like, that there is a memory issue. Cloning i.first() will solve the problem: