diff --git a/src/front/check2.ts b/src/front/check2.ts index 2cbe3d7..4699d3c 100644 --- a/src/front/check2.ts +++ b/src/front/check2.ts @@ -136,7 +136,36 @@ class TypeChecker { } } - throw new Error("not implemented"); + const expectedInner = expected.is("Any") + ? expected + : expected.as("Array").kind.ty; + + let res = this.resolve( + this.expr(k.values[0], expectedInner), + expected, + k.values[0].loc, + ); + while (true) { + for (const val of k.values.slice(1)) { + res = this.resolve( + this.expr(val, expectedInner), + expected, + k.values[0].loc, + ); + if (res.rewriteSubtree) { + break; + } + } + if (!res.rewriteSubtree) { + break; + } + + for (const val of k.values) { + this.rewriteTree(val, res.ty); + } + } + + return res.ty; } case "IndexExpr": { throw new Error("not implemented"); @@ -187,6 +216,14 @@ class TypeChecker { } throw new Error("not implemented"); } + + private rewriteTree(node: ast.Node, ty: Ty) { + const k = node.kind; + switch (k.tag) { + default: + throw new Error("not implemented"); + } + } } type TyRes = { diff --git a/src/stringify.ts b/src/stringify.ts index e97248d..36e0449 100644 --- a/src/stringify.ts +++ b/src/stringify.ts @@ -69,8 +69,6 @@ export function tyPretty(ty: ty.Ty, colors = noColors): string { return ``; case "Void": return `${c.typeIdent}void`; - case "IntLiteral": - return `${c.typeIdent}{integer}`; case "Int": return `${c.typeIdent}${ty.kind.intTy}`; case "Bool": @@ -103,6 +101,8 @@ export function tyPretty(ty: ty.Ty, colors = noColors): string { `${c.punctuation}, `, ) }${c.punctuation}) -> ${ty.kind.ty.kind.retTy.pretty(c)}`; + case "AnyInt": + return `${c.typeIdent}{integer}`; } return ""; }