mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-15 00:45:04 +01:00
extract and test inference context
This commit is contained in:
parent
39a995b765
commit
84cd8eec90
3 changed files with 176 additions and 133 deletions
36
src/typeck.test.ts
Normal file
36
src/typeck.test.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { TY_INT, TY_STRING } from "./ast";
|
||||
import { DUMMY_SPAN as SPAN } from "./error";
|
||||
import { InferContext } from "./typeck";
|
||||
|
||||
it("should infer types across assignments", () => {
|
||||
const infcx = new InferContext();
|
||||
|
||||
const a = infcx.newVar();
|
||||
const b = infcx.newVar();
|
||||
const c = infcx.newVar();
|
||||
|
||||
infcx.assign(a, b, SPAN);
|
||||
infcx.assign(b, c, SPAN);
|
||||
|
||||
infcx.assign(a, TY_INT, SPAN);
|
||||
|
||||
const aTy = infcx.resolveIfPossible(c);
|
||||
const bTy = infcx.resolveIfPossible(c);
|
||||
const cTy = infcx.resolveIfPossible(c);
|
||||
|
||||
expect(aTy.kind).toEqual("int");
|
||||
expect(bTy.kind).toEqual("int");
|
||||
expect(cTy.kind).toEqual("int");
|
||||
});
|
||||
|
||||
it("should conflict assignments to resolvable type vars", () => {
|
||||
const infcx = new InferContext();
|
||||
|
||||
const a = infcx.newVar();
|
||||
const b = infcx.newVar();
|
||||
|
||||
infcx.assign(a, b, SPAN);
|
||||
infcx.assign(b, TY_INT, SPAN);
|
||||
|
||||
expect(() => infcx.assign(a, TY_STRING, SPAN)).toThrow();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue