Skip to content

Commit

Permalink
Fix match clone bug
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-y committed Sep 26, 2024
1 parent 81688c1 commit 8d7677c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/__tests__/compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ describe("E2E Compiler Pipeline", () => {
2, // IntersectionType tests
20, // While loop
"Hello, world! This is a test.",
12, // Array of objects test + advanced match
173, // Array test
]);
});

Expand Down
27 changes: 27 additions & 0 deletions src/__tests__/fixtures/e2e-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,33 @@ pub fn test19() -> i32
pub fn test20() -> string
"Hello, world!" + " " + "This is a test."
pub fn test21()
let arr = new_array<Optional<i32>>({ with_size: 4 })
arr.push(Some<i32> { value: 12 })
arr.pop()
.match(val)
Some<Optional<i32>>:
val.value
None:
None {}
.match(v)
Some<i32>:
v.value
None:
-1
pub fn test22()
let arr = new_array<i32>({ from: FixedArray(1, 2, 3, 4) })
arr.push(5)
arr.push(3)
arr.push(173)
arr.pop()
.match(v)
Some<i32>:
v.value
None:
-1
`;

export const tcoText = `
Expand Down
9 changes: 7 additions & 2 deletions src/syntax-objects/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ export class Match extends Syntax implements ScopedSyntax {
return new Match({
...this.getCloneOpts(parent),
operand: this.operand.clone(),
cases: this.cases.map((c) => ({ ...c, expr: c.expr.clone() })),
cases: this.cases.map((c) => ({
expr: c.expr.clone(),
matchTypeExpr: c.matchTypeExpr?.clone(),
matchType: undefined,
})),
defaultCase: this.defaultCase
? {
...this.defaultCase,
expr: this.defaultCase.expr.clone(),
matchTypeExpr: this.defaultCase.matchTypeExpr?.clone(),
matchType: undefined,
}
: undefined,
type: this.type,
Expand Down

0 comments on commit 8d7677c

Please sign in to comment.