diff --git a/src/analysis/__snapshots__/errors.test.ts.snap b/src/analysis/__snapshots__/errors.test.ts.snap new file mode 100644 index 00000000..c55fee31 --- /dev/null +++ b/src/analysis/__snapshots__/errors.test.ts.snap @@ -0,0 +1,39 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`errorInfoToString > arity mismatch (too few args) 1`] = ` +"Error: Arity mismatch + +Expected 2 arguments, but got 1. + +3| pub let x = f(0) + |  ~~~~" +`; + +exports[`errorInfoToString > arity mismatch (too many args) 1`] = ` +"Error: Arity mismatch + +Expected 1 arguments, but got 2. + +3| pub let x = f(0, 1) + |  ~" +`; + +exports[`errorInfoToString > type error 1`] = ` +"Error: Type mismatch + +Expected: String + Got: Custom + + +3| pub let x: Custom = "abc" + |  ~~~~~" +`; + +exports[`errorInfoToString > unbound variable 1`] = ` +"Error: Unbound variable + +Cannot find variable "unbound_var" + +1| pub let x = unbound_var + |  ~~~~~~~~~~~" +`; diff --git a/src/analysis/analyse.test.ts b/src/analysis/analyse.test.ts index 6b550004..9ffbd451 100644 --- a/src/analysis/analyse.test.ts +++ b/src/analysis/analyse.test.ts @@ -26,7 +26,7 @@ import { UnusedExposing, UnusedImport, UnusedVariable, -} from "../errors"; +} from "./errors"; import { rangeOf } from "../typecheck/typedAst/__test__/utils"; import { dummyRange } from "../typecheck/defaultImports"; import { unsafeParse } from "../parser"; diff --git a/src/analysis/analyse.ts b/src/analysis/analyse.ts index bb67c824..48b4300e 100644 --- a/src/analysis/analyse.ts +++ b/src/analysis/analyse.ts @@ -3,7 +3,7 @@ import { InvalidPipe, OccursCheck, TypeMismatch_REWRITE, -} from "../errors"; +} from "./errors"; import { Binding, ConstLiteral, diff --git a/src/errors.test.ts b/src/analysis/errors.test.ts similarity index 93% rename from src/errors.test.ts rename to src/analysis/errors.test.ts index aeca5364..92671d22 100644 --- a/src/errors.test.ts +++ b/src/analysis/errors.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from "vitest"; import { errorInfoToString } from "./errors"; -import { unsafeParse } from "./parser"; -import { typecheck } from "./typecheck"; +import { unsafeParse } from "../parser"; +import { typecheck } from "../typecheck"; describe(errorInfoToString.name, () => { test("unbound variable", () => { diff --git a/src/errors.ts b/src/analysis/errors.ts similarity index 96% rename from src/errors.ts rename to src/analysis/errors.ts index 71e57f22..5de80bb5 100644 --- a/src/errors.ts +++ b/src/analysis/errors.ts @@ -1,9 +1,9 @@ -import { showErrorLine } from "./utils/showErrorLine"; -import { Range } from "./parser"; -import { Type as LegacyType } from "./typecheck/type"; -import { Type, typePPrint } from "./type"; -import { typeToString } from "./typecheck"; -import { col, withDisabled } from "./utils/colors"; +import { showErrorLine } from "../utils/showErrorLine"; +import { Range } from "../parser"; +import { Type as LegacyType } from "../typecheck/type"; +import { Type, typePPrint } from "../type"; +import { typeToString } from "../typecheck"; +import { col, withDisabled } from "../utils/colors"; export type Severity = "error" | "warning"; diff --git a/src/analysis/index.ts b/src/analysis/index.ts new file mode 100644 index 00000000..03e8ad56 --- /dev/null +++ b/src/analysis/index.ts @@ -0,0 +1,2 @@ +export * from "./analyse"; +export * from "./errors"; diff --git a/src/analysis/resolution.test.ts b/src/analysis/resolution.test.ts index d012b666..10873ae9 100644 --- a/src/analysis/resolution.test.ts +++ b/src/analysis/resolution.test.ts @@ -1,7 +1,7 @@ import { test, expect, vi } from "vitest"; import { ResolutionAnalysis } from "./resolution"; import { unsafeParse } from "../parser"; -import { CyclicDefinition } from "../errors"; +import { CyclicDefinition } from "./errors"; test("allow declarations in swapped order", () => { const src = unsafeParse(` diff --git a/src/analysis/resolution.ts b/src/analysis/resolution.ts index 0e0b9158..d1e6eed3 100644 --- a/src/analysis/resolution.ts +++ b/src/analysis/resolution.ts @@ -12,7 +12,7 @@ import { UnboundType, UnboundVariable, UnusedVariable, -} from "../errors"; +} from "./errors"; import { Binding, TypeAst, diff --git a/src/analysis/typesHydration.ts b/src/analysis/typesHydration.ts index 04c98f3e..8a753445 100644 --- a/src/analysis/typesHydration.ts +++ b/src/analysis/typesHydration.ts @@ -5,7 +5,7 @@ import { InvalidTypeArity, TypeParamShadowing, UnboundTypeParam, -} from "../errors"; +} from "./errors"; import { PolyTypeAst, Range, diff --git a/src/cli/commands/lspCmd.ts b/src/cli/commands/lspCmd.ts index 3ab1caf2..b2672070 100644 --- a/src/cli/commands/lspCmd.ts +++ b/src/cli/commands/lspCmd.ts @@ -33,7 +33,7 @@ import { getInlayHints, } from "../../typecheck"; import { readProjectWithDeps } from "../common"; -import { ErrorInfo, Severity } from "../../errors"; +import { ErrorInfo, Severity } from "../../analysis/errors"; import { withDisabled } from "../../utils/colors"; import { format } from "../../format"; import { Config, readConfig } from "../config"; diff --git a/src/cli/common.ts b/src/cli/common.ts index c4b4e2a8..fa10dcd8 100644 --- a/src/cli/common.ts +++ b/src/cli/common.ts @@ -11,7 +11,7 @@ import { compileProject, defaultEntryPoint } from "../compiler"; import { col } from "../utils/colors"; import { Config, readConfig } from "./config"; import { join } from "node:path"; -import { errorInfoToString } from "../errors"; +import { errorInfoToString } from "../analysis/errors"; import * as paths from "./paths"; export const EXTENSION = "kes"; diff --git a/src/index.ts b/src/index.ts index 78dc7ddf..a4f1f40f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ export * from "./parser"; export * from "./format"; export * from "./compiler"; export * from "./typecheck"; -export * from "./errors"; +export * from "./analysis/errors"; export type { Variant, Item, diff --git a/src/typecheck/resolutionStep.ts b/src/typecheck/resolutionStep.ts index e2289178..6af6ca44 100644 --- a/src/typecheck/resolutionStep.ts +++ b/src/typecheck/resolutionStep.ts @@ -43,7 +43,7 @@ import { UnusedExposing, UnusedImport, UnusedVariable, -} from "../errors"; +} from "../analysis/errors"; import { FramesStack } from "./frame"; export type Deps = Record; diff --git a/src/typecheck/typecheck.test.ts b/src/typecheck/typecheck.test.ts index 66e38496..0c3d44a5 100644 --- a/src/typecheck/typecheck.test.ts +++ b/src/typecheck/typecheck.test.ts @@ -33,7 +33,7 @@ import { UnusedImport, UnusedVariable, TraitNotSatified, -} from "../errors"; +} from "../analysis/errors"; import { TraitImpl } from "./defaultImports"; test("infer int", () => { diff --git a/src/typecheck/typecheck.ts b/src/typecheck/typecheck.ts index 1ff4f387..22a958ec 100644 --- a/src/typecheck/typecheck.ts +++ b/src/typecheck/typecheck.ts @@ -46,7 +46,7 @@ import { TraitNotSatified, TypeMismatch, UnboundTypeParam, -} from "../errors"; +} from "../analysis/errors"; import { castAst, findFieldInModule } from "./resolutionStep"; import { createRecordGraph, topsort } from "../data/graph";