Skip to content

Commit

Permalink
emit InvalidTypeArity
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Sep 15, 2024
1 parent 13368fe commit 52086d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/typecheck/analyse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ describe("ADTs", () => {
expect(a.errors[0]?.description).toBeInstanceOf(UnboundType);
});

test.todo("checks arity in constructors", () => {
test("checks arity in constructors", () => {
const a = new Analysis(
"Main",
`
Expand All @@ -751,6 +751,7 @@ describe("ADTs", () => {
const desc = a.errors[0]?.description as InvalidTypeArity;
expect(desc.expected).toEqual(1);
expect(desc.got).toEqual(2);
expect(desc.type).toEqual("T");
});

test("add types to the type pool", () => {
Expand Down
12 changes: 12 additions & 0 deletions src/typecheck/analyse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {
ErrorInfo,
InvalidPipe,
InvalidTypeArity,
OccursCheck,
TraitNotSatified,
TypeMismatch,
Expand Down Expand Up @@ -475,6 +476,17 @@ class TypeAstsHydration {
return TVar.fresh().asType();
}

if (resolved.declaration.params.length !== t.args.length) {
this.emitError({
description: new InvalidTypeArity(
resolved.declaration.name,
resolved.declaration.params.length,
t.args.length,
),
range: t.range,
});
}

return {
type: "named",
args: t.args.map((arg) =>
Expand Down

0 comments on commit 52086d2

Please sign in to comment.