@hatchingpoint/point 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Point
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Point
2
+
3
+ Point is an AI-first general-purpose language core for coding-agent-native software engineering.
4
+
5
+ This package is the source of truth for Point. It exposes:
6
+
7
+ - `point` CLI through `src/cli.ts`
8
+ - core language APIs through `@hatchingpoint/point/core`
9
+ - core parser, formatter, checker, and TypeScript emitter APIs
10
+
11
+ Core workflow:
12
+
13
+ ```bash
14
+ bun run point:fmt-check:all
15
+ bun run point:check:all
16
+ bun run point:build:all
17
+ ```
18
+
19
+ `point:build:all` emits TypeScript that can be imported by React, Vue, Bun, Node, and Vite projects.
20
+
21
+ When Point is extracted, this package can move into a standalone repo with the same package name and public entrypoints.
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@hatchingpoint/point",
3
+ "version": "0.0.3",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "Point language compiler and CLI.",
7
+ "homepage": "https://github.com/HatchingPoint/point#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/HatchingPoint/point.git",
11
+ "directory": "packages/point"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/HatchingPoint/point/issues"
15
+ },
16
+ "files": [
17
+ "src",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "bin": {
22
+ "point": "src/cli.ts"
23
+ },
24
+ "exports": {
25
+ ".": "./src/index.ts",
26
+ "./cli": "./src/cli.ts",
27
+ "./core": "./src/core/index.ts"
28
+ },
29
+ "license": "MIT"
30
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bun
2
+ import { main } from "./core/cli.ts";
3
+
4
+ main().catch((error) => {
5
+ console.error(error instanceof Error ? error.message : error);
6
+ process.exit(1);
7
+ });
@@ -0,0 +1,117 @@
1
+ export type PointCorePrimitiveType = "Text" | "Int" | "Float" | "Bool" | "Void";
2
+
3
+ export interface PointSourcePosition {
4
+ line: number;
5
+ column: number;
6
+ offset: number;
7
+ }
8
+
9
+ export interface PointSourceSpan {
10
+ start: PointSourcePosition;
11
+ end: PointSourcePosition;
12
+ }
13
+
14
+ export interface PointCoreProgram {
15
+ kind: "coreProgram";
16
+ module?: string;
17
+ declarations: PointCoreDeclaration[];
18
+ span?: PointSourceSpan;
19
+ }
20
+
21
+ export type PointCoreDeclaration =
22
+ | PointCoreImportDeclaration
23
+ | PointCoreValueDeclaration
24
+ | PointCoreFunctionDeclaration
25
+ | PointCoreTypeDeclaration;
26
+
27
+ export interface PointCoreImportDeclaration {
28
+ kind: "import";
29
+ names: string[];
30
+ from: string;
31
+ span?: PointSourceSpan;
32
+ }
33
+
34
+ export interface PointCoreValueDeclaration {
35
+ kind: "value";
36
+ name: string;
37
+ type: PointCoreTypeExpression;
38
+ value: PointCoreExpression;
39
+ mutable: boolean;
40
+ span?: PointSourceSpan;
41
+ }
42
+
43
+ export interface PointCoreFunctionDeclaration {
44
+ kind: "function";
45
+ name: string;
46
+ params: PointCoreParameter[];
47
+ returnType: PointCoreTypeExpression;
48
+ body: PointCoreStatement[];
49
+ span?: PointSourceSpan;
50
+ }
51
+
52
+ export interface PointCoreTypeDeclaration {
53
+ kind: "type";
54
+ name: string;
55
+ fields: PointCoreParameter[];
56
+ span?: PointSourceSpan;
57
+ }
58
+
59
+ export interface PointCoreParameter {
60
+ name: string;
61
+ type: PointCoreTypeExpression;
62
+ span?: PointSourceSpan;
63
+ }
64
+
65
+ export interface PointCoreTypeExpression {
66
+ kind: "typeRef";
67
+ name: PointCorePrimitiveType | string;
68
+ args: PointCoreTypeExpression[];
69
+ span?: PointSourceSpan;
70
+ }
71
+
72
+ export interface PointCoreRecordField {
73
+ name: string;
74
+ value: PointCoreExpression;
75
+ span?: PointSourceSpan;
76
+ }
77
+
78
+ export type PointCoreStatement =
79
+ | { kind: "return"; value?: PointCoreExpression; span?: PointSourceSpan }
80
+ | PointCoreValueDeclaration
81
+ | {
82
+ kind: "if";
83
+ condition: PointCoreExpression;
84
+ thenBody: PointCoreStatement[];
85
+ elseBody: PointCoreStatement[];
86
+ span?: PointSourceSpan;
87
+ }
88
+ | { kind: "expression"; value: PointCoreExpression; span?: PointSourceSpan };
89
+
90
+ export type PointCoreExpression =
91
+ | { kind: "literal"; value: string | number | boolean; span?: PointSourceSpan }
92
+ | { kind: "identifier"; name: string; span?: PointSourceSpan }
93
+ | { kind: "list"; items: PointCoreExpression[]; span?: PointSourceSpan }
94
+ | { kind: "record"; fields: PointCoreRecordField[]; span?: PointSourceSpan }
95
+ | { kind: "property"; target: PointCoreExpression; name: string; span?: PointSourceSpan }
96
+ | {
97
+ kind: "binary";
98
+ operator: PointCoreBinaryOperator;
99
+ left: PointCoreExpression;
100
+ right: PointCoreExpression;
101
+ span?: PointSourceSpan;
102
+ }
103
+ | { kind: "call"; callee: string; args: PointCoreExpression[]; span?: PointSourceSpan };
104
+
105
+ export type PointCoreBinaryOperator =
106
+ | "+"
107
+ | "-"
108
+ | "*"
109
+ | "/"
110
+ | "=="
111
+ | "!="
112
+ | "<"
113
+ | "<="
114
+ | ">"
115
+ | ">="
116
+ | "and"
117
+ | "or";
@@ -0,0 +1,442 @@
1
+ import type {
2
+ PointCoreDeclaration,
3
+ PointCoreExpression,
4
+ PointCoreFunctionDeclaration,
5
+ PointCoreProgram,
6
+ PointCoreStatement,
7
+ PointCoreTypeDeclaration,
8
+ PointCoreTypeExpression,
9
+ PointCoreValueDeclaration,
10
+ PointSourceSpan,
11
+ } from "./ast.ts";
12
+
13
+ export interface PointCoreDiagnostic {
14
+ code: string;
15
+ message: string;
16
+ path: string;
17
+ ref: string;
18
+ severity: "error";
19
+ span: PointSourceSpan | null;
20
+ expected?: string | string[];
21
+ actual?: string;
22
+ repair?: string;
23
+ relatedRefs?: string[];
24
+ }
25
+
26
+ type DiagnosticMetadata = Partial<Pick<PointCoreDiagnostic, "expected" | "actual" | "repair" | "relatedRefs">>;
27
+
28
+ const PRIMITIVE_TYPES = new Set(["Text", "Int", "Float", "Bool", "Void", "List"]);
29
+
30
+ export function checkPointCore(program: PointCoreProgram): PointCoreDiagnostic[] {
31
+ const checker = new CoreChecker(program);
32
+ return checker.check();
33
+ }
34
+
35
+ class CoreChecker {
36
+ private readonly diagnostics: PointCoreDiagnostic[] = [];
37
+ private readonly types = new Set(PRIMITIVE_TYPES);
38
+ private readonly typeDeclarations = new Map<string, PointCoreTypeDeclaration>();
39
+ private readonly globals = new Map<string, PointCoreTypeExpression>();
40
+ private readonly functions = new Map<string, PointCoreFunctionDeclaration>();
41
+
42
+ constructor(private readonly program: PointCoreProgram) {}
43
+
44
+ check(): PointCoreDiagnostic[] {
45
+ this.collectDeclarations();
46
+ for (const declaration of this.program.declarations) this.checkDeclaration(declaration);
47
+ return this.diagnostics;
48
+ }
49
+
50
+ private collectDeclarations() {
51
+ for (const declaration of this.program.declarations) {
52
+ if (declaration.kind === "type") {
53
+ if (this.types.has(declaration.name)) {
54
+ this.push("duplicate-type", `Duplicate type ${declaration.name}`, `type.${declaration.name}`, declaration.span);
55
+ }
56
+ this.types.add(declaration.name);
57
+ this.typeDeclarations.set(declaration.name, declaration);
58
+ }
59
+ if (declaration.kind === "value") this.addGlobal(declaration);
60
+ if (declaration.kind === "function") {
61
+ if (this.functions.has(declaration.name)) {
62
+ this.push("duplicate-function", `Duplicate function ${declaration.name}`, `fn.${declaration.name}`, declaration.span);
63
+ }
64
+ this.functions.set(declaration.name, declaration);
65
+ }
66
+ }
67
+ }
68
+
69
+ private addGlobal(declaration: PointCoreValueDeclaration) {
70
+ if (this.globals.has(declaration.name)) {
71
+ this.push("duplicate-value", `Duplicate value ${declaration.name}`, `value.${declaration.name}`, declaration.span);
72
+ }
73
+ this.globals.set(declaration.name, declaration.type);
74
+ }
75
+
76
+ private checkDeclaration(declaration: PointCoreDeclaration) {
77
+ if (declaration.kind === "import") return;
78
+ if (declaration.kind === "type") {
79
+ for (const field of declaration.fields) this.checkType(field.type, `type.${declaration.name}.${field.name}`);
80
+ return;
81
+ }
82
+ if (declaration.kind === "value") {
83
+ this.checkType(declaration.type, `value.${declaration.name}.type`);
84
+ this.checkExpressionAssignable(declaration.value, declaration.type, `value.${declaration.name}.value`, this.globals);
85
+ return;
86
+ }
87
+ this.checkFunction(declaration);
88
+ }
89
+
90
+ private checkFunction(declaration: PointCoreFunctionDeclaration) {
91
+ this.checkType(declaration.returnType, `fn.${declaration.name}.return`);
92
+ const locals = new Map(this.globals);
93
+ for (const param of declaration.params) {
94
+ this.checkType(param.type, `fn.${declaration.name}.${param.name}.type`);
95
+ locals.set(param.name, param.type);
96
+ }
97
+ for (const statement of declaration.body) {
98
+ this.checkStatement(statement, declaration, locals);
99
+ }
100
+ }
101
+
102
+ private checkStatement(
103
+ statement: PointCoreStatement,
104
+ fn: PointCoreFunctionDeclaration,
105
+ locals: Map<string, PointCoreTypeExpression>,
106
+ ) {
107
+ if (statement.kind === "return") {
108
+ if (!statement.value) {
109
+ if (fn.returnType.name !== "Void") {
110
+ this.push("return-type-mismatch", `Function ${fn.name} must return ${fn.returnType.name}`, `fn.${fn.name}.return`, statement.span);
111
+ }
112
+ return;
113
+ }
114
+ this.checkExpressionAssignable(statement.value, fn.returnType, `fn.${fn.name}.return`, locals);
115
+ return;
116
+ }
117
+ if (statement.kind === "value") {
118
+ this.checkType(statement.type, `fn.${fn.name}.${statement.name}.type`);
119
+ this.checkExpressionAssignable(statement.value, statement.type, `fn.${fn.name}.${statement.name}.value`, locals);
120
+ locals.set(statement.name, statement.type);
121
+ return;
122
+ }
123
+ if (statement.kind === "if") {
124
+ this.checkExpressionAssignable(statement.condition, typeRef("Bool"), `fn.${fn.name}.if.condition`, locals);
125
+ const thenLocals = new Map(locals);
126
+ for (const child of statement.thenBody) this.checkStatement(child, fn, thenLocals);
127
+ const elseLocals = new Map(locals);
128
+ for (const child of statement.elseBody) this.checkStatement(child, fn, elseLocals);
129
+ return;
130
+ }
131
+ this.typeOfExpression(statement.value, locals, `fn.${fn.name}.expression`);
132
+ }
133
+
134
+ private checkExpressionAssignable(
135
+ expression: PointCoreExpression,
136
+ expected: PointCoreTypeExpression,
137
+ path: string,
138
+ scope: Map<string, PointCoreTypeExpression>,
139
+ ) {
140
+ if (expression.kind === "list") {
141
+ this.checkListAssignable(expression, expected, path, scope);
142
+ return;
143
+ }
144
+ if (expression.kind === "record") {
145
+ this.checkRecordAssignable(expression, expected, path, scope);
146
+ return;
147
+ }
148
+ const actual = this.typeOfExpression(expression, scope, path);
149
+ if (actual && !sameType(actual, expected)) {
150
+ this.push("type-mismatch", `Expected ${formatType(expected)}, got ${formatType(actual)}`, path, expression.span, {
151
+ expected: formatType(expected),
152
+ actual: formatType(actual),
153
+ repair: `Return or assign a ${formatType(expected)} value here.`,
154
+ });
155
+ }
156
+ }
157
+
158
+ private checkListAssignable(
159
+ expression: Extract<PointCoreExpression, { kind: "list" }>,
160
+ expected: PointCoreTypeExpression,
161
+ path: string,
162
+ scope: Map<string, PointCoreTypeExpression>,
163
+ ) {
164
+ if (expected.name !== "List" || expected.args.length !== 1) {
165
+ this.push("type-mismatch", `Expected ${formatType(expected)}, got List`, path, expression.span, {
166
+ expected: formatType(expected),
167
+ actual: "List",
168
+ repair: `Annotate this value as List<T> or replace the list with a ${formatType(expected)} value.`,
169
+ });
170
+ return;
171
+ }
172
+ for (const [index, item] of expression.items.entries()) {
173
+ this.checkExpressionAssignable(item, expected.args[0]!, `${path}.${index}`, scope);
174
+ }
175
+ }
176
+
177
+ private checkRecordAssignable(
178
+ expression: Extract<PointCoreExpression, { kind: "record" }>,
179
+ expected: PointCoreTypeExpression,
180
+ path: string,
181
+ scope: Map<string, PointCoreTypeExpression>,
182
+ ) {
183
+ const declaration = this.typeDeclarations.get(String(expected.name));
184
+ if (!declaration) {
185
+ this.push("type-mismatch", `Expected ${formatType(expected)}, got record`, path, expression.span, {
186
+ expected: formatType(expected),
187
+ actual: "record",
188
+ repair: "Assign record literals to a named type with declared fields.",
189
+ });
190
+ return;
191
+ }
192
+ const provided = new Map(expression.fields.map((field) => [field.name, field]));
193
+ for (const field of declaration.fields) {
194
+ const value = provided.get(field.name);
195
+ if (!value) {
196
+ this.push("missing-field", `Missing field ${field.name}`, `${path}.${field.name}`, expression.span, {
197
+ expected: declaration.fields.map((candidate) => candidate.name),
198
+ actual: [...provided.keys()].join(", "),
199
+ repair: `Add field ${field.name}: ${formatType(field.type)} to this record literal.`,
200
+ relatedRefs: this.fieldRefsFor(declaration),
201
+ });
202
+ continue;
203
+ }
204
+ this.checkExpressionAssignable(value.value, field.type, `${path}.${field.name}`, scope);
205
+ provided.delete(field.name);
206
+ }
207
+ for (const extra of provided.values()) {
208
+ this.push("unknown-field", `Unknown field ${extra.name}`, `${path}.${extra.name}`, extra.span, {
209
+ expected: declaration.fields.map((field) => field.name),
210
+ actual: extra.name,
211
+ repair: `Use one of: ${declaration.fields.map((field) => field.name).join(", ")}.`,
212
+ relatedRefs: this.fieldRefsFor(declaration),
213
+ });
214
+ }
215
+ }
216
+
217
+ private typeOfExpression(
218
+ expression: PointCoreExpression,
219
+ scope: Map<string, PointCoreTypeExpression>,
220
+ path: string,
221
+ ): PointCoreTypeExpression | null {
222
+ if (expression.kind === "literal") {
223
+ const valueType =
224
+ typeof expression.value === "string"
225
+ ? "Text"
226
+ : typeof expression.value === "boolean"
227
+ ? "Bool"
228
+ : Number.isInteger(expression.value)
229
+ ? "Int"
230
+ : "Float";
231
+ return { kind: "typeRef", name: valueType, args: [], span: expression.span };
232
+ }
233
+ if (expression.kind === "list") return this.typeOfListExpression(expression, scope, path);
234
+ if (expression.kind === "record") {
235
+ this.push("record-type-required", "Record literals require an expected named type", path, expression.span);
236
+ return null;
237
+ }
238
+ if (expression.kind === "identifier") {
239
+ const type = scope.get(expression.name);
240
+ if (!type) {
241
+ this.push("unknown-identifier", `Unknown identifier ${expression.name}`, path, expression.span, {
242
+ actual: expression.name,
243
+ repair: `Declare ${expression.name}, pass it as a parameter, or replace it with an in-scope symbol.`,
244
+ });
245
+ return null;
246
+ }
247
+ return type;
248
+ }
249
+ if (expression.kind === "binary") {
250
+ return this.typeOfBinaryExpression(expression, scope, path);
251
+ }
252
+ if (expression.kind === "property") {
253
+ return this.typeOfPropertyExpression(expression, scope, path);
254
+ }
255
+ const target = this.functions.get(expression.callee);
256
+ if (!target) {
257
+ this.push("unknown-function", `Unknown function ${expression.callee}`, path, expression.span, {
258
+ actual: expression.callee,
259
+ expected: [...this.functions.keys()],
260
+ repair: `Define fn ${expression.callee}(...) or call an existing function.`,
261
+ });
262
+ return null;
263
+ }
264
+ if (target.params.length !== expression.args.length) {
265
+ this.push("arity-mismatch", `Function ${expression.callee} expects ${target.params.length} args`, path, expression.span, {
266
+ expected: `${target.params.length} args`,
267
+ actual: `${expression.args.length} args`,
268
+ repair: `Call ${expression.callee} with ${target.params.length} argument(s).`,
269
+ relatedRefs: [this.refFor(`fn.${target.name}`)],
270
+ });
271
+ }
272
+ for (const [index, arg] of expression.args.entries()) {
273
+ const param = target.params[index];
274
+ if (param) this.checkExpressionAssignable(arg, param.type, `${path}.arg${index}`, scope);
275
+ }
276
+ return target.returnType;
277
+ }
278
+
279
+ private typeOfListExpression(
280
+ expression: Extract<PointCoreExpression, { kind: "list" }>,
281
+ scope: Map<string, PointCoreTypeExpression>,
282
+ path: string,
283
+ ): PointCoreTypeExpression | null {
284
+ if (expression.items.length === 0) {
285
+ this.push("list-type-required", "Empty lists require an expected List type", path, expression.span);
286
+ return null;
287
+ }
288
+ const first = this.typeOfExpression(expression.items[0]!, scope, `${path}.0`);
289
+ if (!first) return null;
290
+ for (const [index, item] of expression.items.slice(1).entries()) {
291
+ const actual = this.typeOfExpression(item, scope, `${path}.${index + 1}`);
292
+ if (actual && !sameType(actual, first)) {
293
+ this.push("type-mismatch", `Expected ${formatType(first)}, got ${formatType(actual)}`, `${path}.${index + 1}`, item.span);
294
+ }
295
+ }
296
+ return { kind: "typeRef", name: "List", args: [first], span: expression.span };
297
+ }
298
+
299
+ private typeOfPropertyExpression(
300
+ expression: Extract<PointCoreExpression, { kind: "property" }>,
301
+ scope: Map<string, PointCoreTypeExpression>,
302
+ path: string,
303
+ ): PointCoreTypeExpression | null {
304
+ const targetType = this.typeOfExpression(expression.target, scope, `${path}.target`);
305
+ if (!targetType) return null;
306
+ const declaration = this.typeDeclarations.get(String(targetType.name));
307
+ if (!declaration) {
308
+ this.push("not-a-record", `${formatType(targetType)} has no fields`, path, expression.span, {
309
+ actual: formatType(targetType),
310
+ repair: "Only access fields on named record types.",
311
+ });
312
+ return null;
313
+ }
314
+ const field = declaration.fields.find((candidate) => candidate.name === expression.name);
315
+ if (!field) {
316
+ this.push("unknown-field", `Unknown field ${expression.name} on ${targetType.name}`, path, expression.span, {
317
+ expected: declaration.fields.map((candidate) => candidate.name),
318
+ actual: expression.name,
319
+ repair: `Use one of: ${declaration.fields.map((candidate) => candidate.name).join(", ")}.`,
320
+ relatedRefs: this.fieldRefsFor(declaration),
321
+ });
322
+ return null;
323
+ }
324
+ return field.type;
325
+ }
326
+
327
+ private typeOfBinaryExpression(
328
+ expression: Extract<PointCoreExpression, { kind: "binary" }>,
329
+ scope: Map<string, PointCoreTypeExpression>,
330
+ path: string,
331
+ ): PointCoreTypeExpression | null {
332
+ const left = this.typeOfExpression(expression.left, scope, `${path}.left`);
333
+ const right = this.typeOfExpression(expression.right, scope, `${path}.right`);
334
+ if (!left || !right) return null;
335
+ if (expression.operator === "and" || expression.operator === "or") {
336
+ if (left.name !== "Bool" || right.name !== "Bool") {
337
+ this.push("operator-type-mismatch", `${expression.operator} requires Bool operands`, path, expression.span, {
338
+ expected: "Bool operands",
339
+ actual: `${formatType(left)} and ${formatType(right)}`,
340
+ repair: `Use Bool expressions on both sides of ${expression.operator}.`,
341
+ });
342
+ }
343
+ return { kind: "typeRef", name: "Bool", args: [], span: expression.span };
344
+ }
345
+ if (expression.operator === "==" || expression.operator === "!=") {
346
+ if (left.name !== right.name) {
347
+ this.push("operator-type-mismatch", `${expression.operator} requires matching operand types`, path, expression.span, {
348
+ expected: formatType(left),
349
+ actual: formatType(right),
350
+ repair: "Compare values with the same Point type.",
351
+ });
352
+ }
353
+ return { kind: "typeRef", name: "Bool", args: [], span: expression.span };
354
+ }
355
+ if (expression.operator === "+" && left.name === "Text" && right.name === "Text") {
356
+ return { kind: "typeRef", name: "Text", args: [], span: expression.span };
357
+ }
358
+ if (!isNumeric(left.name) || !isNumeric(right.name)) {
359
+ this.push("operator-type-mismatch", `${expression.operator} requires numeric operands`, path, expression.span, {
360
+ expected: "Int or Float operands",
361
+ actual: `${formatType(left)} and ${formatType(right)}`,
362
+ repair: `Use numeric expressions on both sides of ${expression.operator}.`,
363
+ });
364
+ return null;
365
+ }
366
+ if (["<", "<=", ">", ">="].includes(expression.operator)) {
367
+ return { kind: "typeRef", name: "Bool", args: [], span: expression.span };
368
+ }
369
+ return { kind: "typeRef", name: left.name === "Float" || right.name === "Float" ? "Float" : "Int", args: [], span: expression.span };
370
+ }
371
+
372
+ private checkType(type: PointCoreTypeExpression, path: string) {
373
+ if (!this.types.has(type.name)) {
374
+ this.push("unknown-type", `Unknown type ${type.name}`, path, type.span, {
375
+ expected: [...this.types].sort(),
376
+ actual: String(type.name),
377
+ repair: `Declare type ${type.name} or use an existing type.`,
378
+ });
379
+ }
380
+ if (type.name === "List" && type.args.length !== 1) {
381
+ this.push("invalid-type-arity", "List requires one type argument", path, type.span, {
382
+ expected: "List<T>",
383
+ actual: formatType(type),
384
+ repair: "Use List<Text>, List<Int>, or another concrete item type.",
385
+ });
386
+ }
387
+ if (type.name !== "List" && type.args.length > 0 && !this.typeDeclarations.has(String(type.name))) {
388
+ this.push("invalid-type-arity", `${type.name} does not accept type arguments`, path, type.span, {
389
+ expected: String(type.name),
390
+ actual: formatType(type),
391
+ repair: `Remove type arguments from ${type.name}.`,
392
+ });
393
+ }
394
+ for (const arg of type.args) this.checkType(arg, `${path}.arg`);
395
+ }
396
+
397
+ private push(
398
+ code: string,
399
+ message: string,
400
+ path: string,
401
+ span: PointSourceSpan | undefined,
402
+ metadata: DiagnosticMetadata = {},
403
+ ) {
404
+ this.diagnostics.push({
405
+ code,
406
+ message,
407
+ path,
408
+ ref: this.refFor(path),
409
+ severity: "error",
410
+ span: span ?? null,
411
+ ...metadata,
412
+ });
413
+ }
414
+
415
+ private refFor(path: string): string {
416
+ return `point://core/${this.program.module ?? "anonymous"}/${path}`;
417
+ }
418
+
419
+ private fieldRefsFor(declaration: PointCoreTypeDeclaration): string[] {
420
+ return declaration.fields.map((field) => this.refFor(`type.${declaration.name}.${field.name}`));
421
+ }
422
+ }
423
+
424
+ function isNumeric(type: string): boolean {
425
+ return type === "Int" || type === "Float";
426
+ }
427
+
428
+ function sameType(left: PointCoreTypeExpression, right: PointCoreTypeExpression): boolean {
429
+ const leftArgs = left.args ?? [];
430
+ const rightArgs = right.args ?? [];
431
+ return left.name === right.name && leftArgs.length === rightArgs.length && leftArgs.every((arg, index) => sameType(arg, rightArgs[index]!));
432
+ }
433
+
434
+ function formatType(type: PointCoreTypeExpression): string {
435
+ const args = type.args ?? [];
436
+ if (args.length === 0) return String(type.name);
437
+ return `${type.name}<${args.map(formatType).join(", ")}>`;
438
+ }
439
+
440
+ function typeRef(name: string, args: PointCoreTypeExpression[] = [], span?: PointSourceSpan): PointCoreTypeExpression {
441
+ return { kind: "typeRef", name, args, span };
442
+ }