Skip to content

Commit 09b6373

Browse files
committed
[cpp] Fix collectionWithStringStgKeys.Remove(stringRef).
Fix #223
1 parent 428dcc1 commit 09b6373

6 files changed

Lines changed: 29 additions & 13 deletions

File tree

GenCpp.fu

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,10 @@ public class GenCpp : GenCCpp
10611061
case FuId.SortedSetRemove:
10621062
case FuId.DictionaryRemove:
10631063
case FuId.SortedDictionaryRemove:
1064-
WriteMethodCall(obj, "erase", args[0]);
1064+
StartMethodCall(obj);
1065+
Write("erase(");
1066+
WriteStronglyCoerced(obj.Type.AsClassType().GetKeyType(), args[0]);
1067+
WriteChar(')');
10651068
break;
10661069
case FuId.DictionaryAdd:
10671070
WriteIndexing(obj, args[0]);

libfut.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14959,7 +14959,10 @@ void GenCpp::writeCallExpr(const FuType * type, const FuExpr * obj, const FuMeth
1495914959
case FuId::sortedSetRemove:
1496014960
case FuId::dictionaryRemove:
1496114961
case FuId::sortedDictionaryRemove:
14962-
writeMethodCall(obj, "erase", (*args)[0].get());
14962+
startMethodCall(obj);
14963+
write("erase(");
14964+
writeStronglyCoerced(obj->type->asClassType()->getKeyType(), (*args)[0].get());
14965+
writeChar(')');
1496314966
break;
1496414967
case FuId::dictionaryAdd:
1496514968
writeIndexing(obj, (*args)[0].get());

libfut.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15293,7 +15293,10 @@ protected override void WriteCallExpr(FuType type, FuExpr obj, FuMethod method,
1529315293
case FuId.SortedSetRemove:
1529415294
case FuId.DictionaryRemove:
1529515295
case FuId.SortedDictionaryRemove:
15296-
WriteMethodCall(obj, "erase", args[0]);
15296+
StartMethodCall(obj);
15297+
Write("erase(");
15298+
WriteStronglyCoerced(obj.Type.AsClassType().GetKeyType(), args[0]);
15299+
WriteChar(')');
1529715300
break;
1529815301
case FuId.DictionaryAdd:
1529915302
WriteIndexing(obj, args[0]);

libfut.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15800,7 +15800,10 @@ export class GenCpp extends GenCCpp
1580015800
case FuId.SORTED_SET_REMOVE:
1580115801
case FuId.DICTIONARY_REMOVE:
1580215802
case FuId.SORTED_DICTIONARY_REMOVE:
15803-
this.writeMethodCall(obj, "erase", args[0]);
15803+
this.#startMethodCall(obj);
15804+
this.write("erase(");
15805+
this.writeStronglyCoerced(obj.type.asClassType().getKeyType(), args[0]);
15806+
this.writeChar(41);
1580415807
break;
1580515808
case FuId.DICTIONARY_ADD:
1580615809
this.writeIndexing(obj, args[0]);

test/DictionaryString.fu

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public static class Test
1717
dict2.Clear();
1818
dict2[one] = "jeden";
1919
dict2[two] = "dwa";
20-
dict2["three"] = "trzy";
21-
dict2.Remove("three");
20+
string three = "three";
21+
dict2[three] = "trzy";
22+
dict2.Remove(three);
2223

2324
Dictionary<string, string()>() dict3;
2425
dict3["only"] = "test";

test/SortedDictionary.fu

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ public static class Test
22
{
33
public static bool Run()
44
{
5-
SortedDictionary<int, int>() dict; //FAIL: cl
6-
dict[1] = 10;
5+
SortedDictionary<string(), int>() dict; //FAIL: cl
6+
dict["one"] = 10;
77
dict.Clear();
8-
dict[2] = 12;
9-
dict[2] = 20;
10-
dict[3] = 30;
11-
dict.Remove(1);
12-
return dict.Count == 2 && dict[2] == 20 && dict[3] == 30 && dict.ContainsKey(2);
8+
dict["two"] = 12;
9+
string two = "two";
10+
dict[two] = 20;
11+
dict["three"] = 30;
12+
dict.Remove("one");
13+
string one = "one";
14+
dict.Remove(one);
15+
return dict.Count == 2 && dict["two"] == 20 && dict["three"] == 30 && dict.ContainsKey("two");
1316
}
1417
}

0 commit comments

Comments
 (0)