Fix bug in enum-declaration inference and fix some type errors

This commit is contained in:
Sam Vervaeck 2022-09-14 23:09:22 +02:00
parent c5fe5004b6
commit 2ec8649456

View file

@ -702,8 +702,8 @@ abstract class SchemeBase {
class Forall extends SchemeBase { class Forall extends SchemeBase {
public constructor( public constructor(
public typeVars: TVar[], public typeVars: Iterable<TVar>,
public constraints: Constraint[], public constraints: Iterable<Constraint>,
public type: Type, public type: Type,
) { ) {
super(); super();
@ -1423,16 +1423,15 @@ export class Checker {
this.addBinding(node.name.text, new Forall([], [], type)); this.addBinding(node.name.text, new Forall([], [], type));
return type; return type;
} }
assert(scheme.typeVars.length === 0); assert(isEmpty(scheme.typeVars));
assert(scheme.constraints.length === 0); assert(isEmpty(scheme.constraints));
return scheme.type; return scheme.type;
} }
case SyntaxKind.AppTypeExpression: case SyntaxKind.AppTypeExpression:
{ {
const argTypes = node.args.map(arg => this.inferTypeExpression(arg, introduceTypeVars));
return TApp.build([ return TApp.build([
...argTypes, ...node.args.map(arg => this.inferTypeExpression(arg, introduceTypeVars)),
this.inferTypeExpression(node.operator, introduceTypeVars), this.inferTypeExpression(node.operator, introduceTypeVars),
]); ]);
} }
@ -1770,7 +1769,7 @@ export class Checker {
{ {
const argTypes = member.elements.map(el => this.inferTypeExpression(el)); const argTypes = member.elements.map(el => this.inferTypeExpression(el));
elementType = new TArrow(argTypes, TApp.build([ ...kindArgs, type ])); elementType = new TArrow(argTypes, TApp.build([ ...kindArgs, type ]));
parentEnv.add(member.name.text, new Forall([], [], elementType)); parentEnv.add(member.name.text, new Forall(typeVars, constraints, elementType));
break; break;
} }
// TODO // TODO