From d45207342cff211679a8194f0aa6f7edaf0e7216 Mon Sep 17 00:00:00 2001 From: Yura Dupyn <2153100+omedusyo@users.noreply.github.com> Date: Sat, 7 Feb 2026 14:57:01 +0100 Subject: [PATCH] strict ts + fixes --- src/lang/debug/expr_show.ts | 1 + src/lang/debug/repl.ts | 2 +- src/lang/debug/value_show.ts | 3 +-- src/lang/parser/cursor.test.ts | 1 + src/lang/parser/cursor.ts | 11 +++++------ src/lang/parser/scanner.ts | 2 +- src/lang/parser/source_text.ts | 2 +- src/lang/value.ts | 2 +- tsconfig.json | 3 +++ 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/lang/debug/expr_show.ts b/src/lang/debug/expr_show.ts index db78fe5..08acf9f 100644 --- a/src/lang/debug/expr_show.ts +++ b/src/lang/debug/expr_show.ts @@ -1,3 +1,4 @@ +// AI GENERATED import { Expr, Pattern, ProductPattern, Literal, FieldAssignment, FieldPattern } from '../value'; export function exprToString(expr: Expr): string { diff --git a/src/lang/debug/repl.ts b/src/lang/debug/repl.ts index 3980e10..efd8f6b 100644 --- a/src/lang/debug/repl.ts +++ b/src/lang/debug/repl.ts @@ -1,3 +1,4 @@ +// AI GENERATED import * as readline from 'readline'; import * as fs from 'fs'; import { parse, ParseError } from '../parser/parser'; @@ -155,7 +156,6 @@ function getErrorMessage(err: ParseError): string { case "UnicodeUnclosed": return "Unicode escape missing closing brace '}'."; case "UnicodeOverflow": return `Unicode code point ${err.reason.value.toString(16)} is out of bounds.`; } - return "Invalid escape sequence."; // Context specific errors case "ExpectedExpression": return "Expected an expression here."; diff --git a/src/lang/debug/value_show.ts b/src/lang/debug/value_show.ts index 7c13080..a59b859 100644 --- a/src/lang/debug/value_show.ts +++ b/src/lang/debug/value_show.ts @@ -1,5 +1,4 @@ -// src/debug/value_string.ts - +// AI GENERATED import { Value, Env, Closure, EnvFrame } from '../value'; import { exprToString, productPatternToString } from './expr_show'; diff --git a/src/lang/parser/cursor.test.ts b/src/lang/parser/cursor.test.ts index 2a3b09e..ae32bf8 100644 --- a/src/lang/parser/cursor.test.ts +++ b/src/lang/parser/cursor.test.ts @@ -1,3 +1,4 @@ +// AI GENERATED import { SourceText } from "./source_text"; import { Cursor, scanString, scanNumber } from "./cursor"; import { Result } from "../result"; diff --git a/src/lang/parser/cursor.ts b/src/lang/parser/cursor.ts index a5a5e5f..f89242c 100644 --- a/src/lang/parser/cursor.ts +++ b/src/lang/parser/cursor.ts @@ -147,16 +147,12 @@ export function scanNumber(cursor: Cursor): Result<{ value: number, span: Span } const startNumberLocation = cursor.currentLocation(); - let c: CodePoint; - // 1. Optional Sign - c = cursor.peek(); - if (c === char("-")) { + if (cursor.peek() === char("-")) { cursor.next(); } // 2. Integer Part - c = cursor.peek(); const integerPartDigitCount = cursor.consumeWhile(isDigit); if (integerPartDigitCount === 0) { return Result.error({ @@ -238,7 +234,10 @@ export function scanString(cursor: Cursor): Result<{ value: string, span: Span } // 2. Escape Sequences const escapeStart = cursor.currentLocation(); cursor.next(); // consume backslash - const escaped = cursor.peek(); + if (cursor.eof()) { + return Result.error({ tag: "UnexpectedEOF", span: cursor.makeSpan(start) }); + } + const escaped = cursor.peek() as CodePoint; // it can't be `undefined` switch (escaped) { case char('n'): value += '\n'; cursor.next(); break; diff --git a/src/lang/parser/scanner.ts b/src/lang/parser/scanner.ts index c1bd3c8..757397f 100644 --- a/src/lang/parser/scanner.ts +++ b/src/lang/parser/scanner.ts @@ -97,7 +97,7 @@ export type PatternStartToken = function rawIdentifier(cursor: Cursor): string { const start = cursor.currentIndex; while (!cursor.eof()) { - const c = cursor.peek(); + const c = cursor.peek() as CodePoint; if (DELIMITER_SET.has(c) || isWhitespace(c)) { break; diff --git a/src/lang/parser/source_text.ts b/src/lang/parser/source_text.ts index bea2545..6a32584 100644 --- a/src/lang/parser/source_text.ts +++ b/src/lang/parser/source_text.ts @@ -5,7 +5,7 @@ export type CodePointIndex = number; // index into array of code-points export type CodePoint = number; // could also name it `UnicodeCodePoint`. Basically for `s: string` we have `s.codePointAt(i: index): char`. export function char(c: string): CodePoint { - return c.codePointAt(0) + return c.codePointAt(0) as CodePoint; } export type CodePointRef = { diff --git a/src/lang/value.ts b/src/lang/value.ts index ae5bd56..e1a3e2a 100644 --- a/src/lang/value.ts +++ b/src/lang/value.ts @@ -333,7 +333,7 @@ export function eval_start(program: Program, e: Expr): Result { return Result.ok(eval_expr(program, Env.nil(), e)); } catch (err) { if (typeof err === "object" && (err as any).kind === "RuntimeError") { - return Result.error(err.error as RuntimeError); + return Result.error((err as ThrownRuntimeError).error); } else { throw err; } diff --git a/tsconfig.json b/tsconfig.json index 74434b2..2ad79ef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,9 @@ "sourceMap": true, "baseUrl": ".", "outDir": "dist", + "strict": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, "moduleResolution": "node", "resolveJsonModule": true }