Skip to content

Commit

Permalink
Fixing "key not found" error when using set as key (#754)
Browse files Browse the repository at this point in the history
* Fixing "set key not found in map" error

* [PSym] Add todo for fixing key error when using set as map key

---------

Co-authored-by: Christine Zhou <[email protected]>
Co-authored-by: Aman Goel <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2024
1 parent e09ba81 commit 25f9588
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Src/PChecker/CheckerCore/PRuntime/Values/PrtSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ private bool IsDirty
}
}

public override int GetHashCode()
{
if (!IsDirty)
{
return hashCode;
}

hashCode = ComputeHashCode();
IsDirty = false;

return hashCode;
}

public IEnumerator<IPrtValue> GetEnumerator()
{
return set.GetEnumerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ private static void setRunArgs() {
}

private static void createExcludeList() {
// TODO: fix key not found error when using set as key
excluded.add("../../../Tst/RegressionTests/Integration/Correct/TestMapSet");

// TODO Unsupported: too many choices to throw error if choices more than 10000
excluded.add("../../../Tst/RegressionTests/Feature3Exprs/DynamicError/tooManyChoicesSeq");
excluded.add("../../../Tst/RegressionTests/Feature3Exprs/DynamicError/tooManyChoicesSet");
Expand Down
25 changes: 25 additions & 0 deletions Tst/RegressionTests/Integration/Correct/TestMapSet/TestMapSet.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Recreating set in map error

machine Main
{
start state Init {
entry {
ReplicateMapSet();
}
}
}

fun ReplicateMapSet()
{
var seqmap: map[seq[int], int]; // Creating example for comparison
var mapmap: map[map[int, int], int];
var setmap: map[set[int], int];

seqmap[default(seq[int])] = 0;
mapmap[default(map[int,int])] = 1;
setmap[default(set[int])] = 2;

print format("seqmap: {0}", seqmap[default(seq[int])]);
print format("mapmap: {0}", mapmap[default(map[int,int])]);
print format("setmap: {0}", setmap[default(set[int])]);
}

0 comments on commit 25f9588

Please sign in to comment.