This commit is contained in:
parent
9012cfbd5f
commit
db129a3c16
@ -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": {
|
case "IndexExpr": {
|
||||||
throw new Error("not implemented");
|
throw new Error("not implemented");
|
||||||
@ -187,6 +216,14 @@ class TypeChecker {
|
|||||||
}
|
}
|
||||||
throw new Error("not implemented");
|
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 = {
|
type TyRes = {
|
||||||
|
|||||||
@ -69,8 +69,6 @@ export function tyPretty(ty: ty.Ty, colors = noColors): string {
|
|||||||
return `<error>`;
|
return `<error>`;
|
||||||
case "Void":
|
case "Void":
|
||||||
return `${c.typeIdent}void`;
|
return `${c.typeIdent}void`;
|
||||||
case "IntLiteral":
|
|
||||||
return `${c.typeIdent}{integer}`;
|
|
||||||
case "Int":
|
case "Int":
|
||||||
return `${c.typeIdent}${ty.kind.intTy}`;
|
return `${c.typeIdent}${ty.kind.intTy}`;
|
||||||
case "Bool":
|
case "Bool":
|
||||||
@ -103,6 +101,8 @@ export function tyPretty(ty: ty.Ty, colors = noColors): string {
|
|||||||
`${c.punctuation}, `,
|
`${c.punctuation}, `,
|
||||||
)
|
)
|
||||||
}${c.punctuation}) -> ${ty.kind.ty.kind.retTy.pretty(c)}`;
|
}${c.punctuation}) -> ${ty.kind.ty.kind.retTy.pretty(c)}`;
|
||||||
|
case "AnyInt":
|
||||||
|
return `${c.typeIdent}{integer}`;
|
||||||
}
|
}
|
||||||
return "<unhandled>";
|
return "<unhandled>";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user