From 460ad15d299290895ef2469feec442a6406ec0a2 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Mon, 16 Sep 2024 10:07:27 -0700 Subject: [PATCH] handle ins/del in completion-record typechecks (#610) --- src/typechecker.ts | 6 ++++-- test/typecheck.js | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/typechecker.ts b/src/typechecker.ts index 3ead85c9..b1237145 100644 --- a/src/typechecker.ts +++ b/src/typechecker.ts @@ -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[]) { diff --git a/test/typecheck.js b/test/typecheck.js index 71be5c5f..90d33cec 100644 --- a/test/typecheck.js +++ b/test/typecheck.js @@ -203,6 +203,8 @@ describe('typechecking completions', () => { 1. Set _a_ to Completion(ExampleAlg()). 1. Set _a_ to ! ExampleAlg(). 1. Return ? ExampleAlg(). + 1. Return ? ExampleAlg(). + 1. Return ? ! 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). @@ -284,6 +286,7 @@ describe('typechecking completions', () => { 1. Return ExampleAlg(). + 1. Return ! ExampleAlg(). `);