fix type inference

This commit is contained in:
nora 2023-07-29 17:55:36 +02:00
parent 162d71c8b8
commit e88d0f8782
2 changed files with 37 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import { TY_INT, TY_STRING } from "./ast";
import { TY_INT, TY_STRING, TY_UNIT } from "./ast";
import { DUMMY_SPAN as SPAN } from "./error";
import { InferContext } from "./typeck";
@ -34,3 +34,21 @@ it("should conflict assignments to resolvable type vars", () => {
expect(() => infcx.assign(a, TY_STRING, SPAN)).toThrow();
});
it("should not cycle", () => {
const infcx = new InferContext();
const a = infcx.newVar();
const b = infcx.newVar();
infcx.assign(a, b, SPAN);
infcx.assign(b, a, SPAN);
const aType = infcx.resolveIfPossible(a);
expect(aType.kind).toEqual("var");
infcx.assign(a, TY_UNIT, SPAN);
const bType = infcx.resolveIfPossible(b);
expect(bType.kind).toEqual("tuple");
});