Skip to content

Commit

Permalink
handle ins/del in completion-record typechecks (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored Sep 16, 2024
1 parent f9f05bf commit 460ad15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/typechecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,19 @@ function previousText(expr: Expr, path: PathItem[]): string | null {

function textFromPreviousPart(seq: Seq, index: number): string | null {
let prevIndex = index - 1;
let text = null;
let prev;
while (isProsePart((prev = seq.items[prevIndex]))) {
if (prev.name === 'text') {
return prev.contents;
text = prev.contents + (text ?? '');
--prevIndex;
} else if (prev.name === 'tag') {
--prevIndex;
} else {
break;
}
}
return null;
return text;
}

function stripWhitespace(items: NonSeq[]) {
Expand Down
3 changes: 3 additions & 0 deletions test/typecheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ describe('typechecking completions', () => {
1. Set _a_ to Completion(<emu-meta suppress-effects="user-code">ExampleAlg()</emu-meta>).
1. Set _a_ to ! ExampleAlg().
1. Return ? ExampleAlg().
1. Return <ins>?</ins> ExampleAlg().
1. Return <del>?</del> <ins>!</ins> ExampleAlg().
1. Let _foo_ be 0.
1. Set _a_ to Completion(ExampleSDO of _foo_).
1. Set _a_ to Completion(ExampleSDO of _foo_ with argument 0).
Expand Down Expand Up @@ -284,6 +286,7 @@ describe('typechecking completions', () => {
</dl>
<emu-alg>
1. Return ExampleAlg().
1. Return <del>!</del> ExampleAlg().
</emu-alg>
</emu-clause>
`);
Expand Down

0 comments on commit 460ad15

Please sign in to comment.