Skip to content

Commit

Permalink
fix: adjust comparing and hashing and a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich committed Oct 14, 2024
1 parent bd223f4 commit 72ea7b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
10 changes: 6 additions & 4 deletions src/grammar/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,12 @@ export class AstComparator {
identifiers: destructIdentifiers2,
expression: destructExpression2,
} = node2 as AstStatementDestruct;
const sortedIdentifiers1 =
Array.from(destructIdentifiers1).sort();
const sortedIdentifiers2 =
Array.from(destructIdentifiers2).sort();
const sortedIdentifiers1 = Array.from(
destructIdentifiers1.values(),
).sort();
const sortedIdentifiers2 = Array.from(
destructIdentifiers2.values(),
).sort();
if (sortedIdentifiers1.length !== sortedIdentifiers2.length) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/grammar/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class AstHasher {
case "statement_foreach":
return `${node.kind}|${this.hash(node.map)}|${this.hashStatements(node.statements)}`;
case "statement_destruct":
return `${node.kind}|${this.hash(node.type)}|${this.hashDestructIdentifiers(node.identifiers)}|${this.hash(node.expression)}`;
return `${node.kind}|${this.hash(node.type)}|${this.hashDestructIdentifiers(Array.from(node.identifiers.values()))}|${this.hash(node.expression)}`;
// Expressions
case "op_binary":
return `${node.kind}|${node.op}|${this.hash(node.left)}|${this.hash(node.right)}`;
Expand Down Expand Up @@ -195,8 +195,8 @@ export class AstHasher {
}
}

private hashDestructIdentifiers(identifiers: Map<AstId, AstId>): string {
const identifiersHash = Array.from(identifiers)
private hashDestructIdentifiers(identifiers: [AstId, AstId][]): string {
const identifiersHash = identifiers
.map(([key, value]) => `${this.hash(key)}|${this.hash(value)}`)
.join("|");
return identifiersHash;
Expand Down
12 changes: 6 additions & 6 deletions src/test/contracts/case-destructuring.tact
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ message M {
fun testFunc(): Int {
let s = S{a: 1, b: 2, c: 3};
let S {a, b, c} = s;
let S {a: a1, _, _} = s;
let S {_, b: b1, _} = s;
let S {_, _, c: c1} = s;
let S {a: a2, b: b2, _} = s;
let S {a: a3, _, c: c3} = s;
let S {_, b: b4, c: c4} = s;
let S {a: a1} = s;
let S {b: b1} = s;
let S {c: c1} = s;
let S {a: a2, b: b2} = s;
let S {a: a3, c: c3} = s;
let S {b: b4, c: c4} = s;
let m = M{a: 1, b: 2};
let M {a: a_m, b: b_m} = m;
return a + b + c + a1 + b1 + c1 + a2 + b2 + a3 + c3 + b4 + c4 + a_m + b_m;
Expand Down
12 changes: 6 additions & 6 deletions src/test/contracts/renamer-expected/case-destructuring.tact
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ message message_decl_1 {
fun function_def_2(): Int {
let s = S{a: 1, b: 2, c: 3};
let S {a, b, c} = s;
let S {a: a1, _, _} = s;
let S {_, b: b1, _} = s;
let S {_, _, c: c1} = s;
let S {a: a2, b: b2, _} = s;
let S {a: a3, _, c: c3} = s;
let S {_, b: b4, c: c4} = s;
let S {a: a1} = s;
let S {b: b1} = s;
let S {c: c1} = s;
let S {a: a2, b: b2} = s;
let S {a: a3, c: c3} = s;
let S {b: b4, c: c4} = s;
let m = M{a: 1, b: 2};
let M {a: a_m, b: b_m} = m;
return a + b + c + a1 + b1 + c1 + a2 + b2 + a3 + c3 + b4 + c4 + a_m + b_m;
Expand Down

0 comments on commit 72ea7b1

Please sign in to comment.