gofront 0.0.7 → 0.0.9

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.
@@ -157,6 +157,8 @@ export class TypeChecker {
157
157
  for (const decl of program.decls) {
158
158
  if (decl.kind === "FuncDecl" || decl.kind === "MethodDecl") {
159
159
  this.collectFunc(decl);
160
+ } else if (decl.kind === "TemplDecl") {
161
+ this._collectTemplDecl(decl);
160
162
  }
161
163
  }
162
164
  // Pass 2.1: Promote embedded methods
@@ -203,9 +205,11 @@ export class TypeChecker {
203
205
  for (const p of programs) {
204
206
  this._currentFile = p._filename ?? null;
205
207
  this._currentSource = p._source ?? null;
206
- for (const d of p.decls)
208
+ for (const d of p.decls) {
207
209
  if (d.kind === "FuncDecl" || d.kind === "MethodDecl")
208
210
  this.collectFunc(d);
211
+ else if (d.kind === "TemplDecl") this._collectTemplDecl(d);
212
+ }
209
213
  }
210
214
 
211
215
  // Pass 2.1: Promote embedded methods
@@ -407,8 +411,32 @@ export class TypeChecker {
407
411
  this.checkConstDecl(decl, scope);
408
412
  break;
409
413
  case "TypeDecl":
410
- break; // already collected
414
+ case "TemplDecl":
415
+ break; // already collected / no body to check
416
+ }
417
+ }
418
+
419
+ _collectTemplDecl(decl) {
420
+ const paramTypes = decl.params.map((p) =>
421
+ this.resolveTypeNode(p.type, this.globals),
422
+ );
423
+ const gomNodeType = this.types.get("gom.Node") ?? {
424
+ kind: "basic",
425
+ name: "any",
426
+ };
427
+ const isVariadic =
428
+ decl.params.length > 0 && decl.params[decl.params.length - 1].variadic;
429
+ const funcType = {
430
+ kind: "func",
431
+ params: paramTypes,
432
+ returns: [gomNodeType],
433
+ variadic: isVariadic,
434
+ async: false,
435
+ };
436
+ if (this.globals.symbols.has(decl.name) && decl.name !== "init") {
437
+ this.err(`${decl.name} redeclared in this block`, decl);
411
438
  }
439
+ this.globals.define(decl.name, funcType);
412
440
  }
413
441
 
414
442
  checkFuncDecl(decl, outer) {