Skip to content

Commit

Permalink
moved errors module
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Nov 20, 2024
1 parent 6ef5fe0 commit 08fa81b
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 19 deletions.
39 changes: 39 additions & 0 deletions src/analysis/__snapshots__/errors.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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
|  ~~~~~~~~~~~"
`;
2 changes: 1 addition & 1 deletion src/analysis/analyse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/analyse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
InvalidPipe,
OccursCheck,
TypeMismatch_REWRITE,
} from "../errors";
} from "./errors";
import {
Binding,
ConstLiteral,
Expand Down
4 changes: 2 additions & 2 deletions src/errors.test.ts → src/analysis/errors.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
12 changes: 6 additions & 6 deletions src/errors.ts → src/analysis/errors.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
2 changes: 2 additions & 0 deletions src/analysis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./analyse";
export * from "./errors";

Check warning on line 2 in src/analysis/index.ts

View check run for this annotation

Codecov / codecov/patch

src/analysis/index.ts#L2

Added line #L2 was not covered by tests
2 changes: 1 addition & 1 deletion src/analysis/resolution.test.ts
Original file line number Diff line number Diff line change
@@ -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(`
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
UnboundType,
UnboundVariable,
UnusedVariable,
} from "../errors";
} from "./errors";
import {
Binding,
TypeAst,
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/typesHydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
InvalidTypeArity,
TypeParamShadowing,
UnboundTypeParam,
} from "../errors";
} from "./errors";
import {
PolyTypeAst,
Range,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/lspCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
getInlayHints,
} from "../../typecheck";
import { readProjectWithDeps } from "../common";
import { ErrorInfo, Severity } from "../../errors";
import { ErrorInfo, Severity } from "../../analysis/errors";

Check warning on line 36 in src/cli/commands/lspCmd.ts

View check run for this annotation

Codecov / codecov/patch

src/cli/commands/lspCmd.ts#L36

Added line #L36 was not covered by tests
import { withDisabled } from "../../utils/colors";
import { format } from "../../format";
import { Config, readConfig } from "../config";
Expand Down
2 changes: 1 addition & 1 deletion src/cli/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check warning on line 14 in src/cli/common.ts

View check run for this annotation

Codecov / codecov/patch

src/cli/common.ts#L14

Added line #L14 was not covered by tests
import * as paths from "./paths";

export const EXTENSION = "kes";
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from "./parser";
export * from "./format";
export * from "./compiler";
export * from "./typecheck";
export * from "./errors";
export * from "./analysis/errors";

Check warning on line 5 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L5

Added line #L5 was not covered by tests
export type {
Variant,
Item,
Expand Down
2 changes: 1 addition & 1 deletion src/typecheck/resolutionStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
UnusedExposing,
UnusedImport,
UnusedVariable,
} from "../errors";
} from "../analysis/errors";
import { FramesStack } from "./frame";

export type Deps = Record<string, TypedModule>;
Expand Down
2 changes: 1 addition & 1 deletion src/typecheck/typecheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
UnusedImport,
UnusedVariable,
TraitNotSatified,
} from "../errors";
} from "../analysis/errors";
import { TraitImpl } from "./defaultImports";

test("infer int", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/typecheck/typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
TraitNotSatified,
TypeMismatch,
UnboundTypeParam,
} from "../errors";
} from "../analysis/errors";
import { castAst, findFieldInModule } from "./resolutionStep";
import { createRecordGraph, topsort } from "../data/graph";

Expand Down

0 comments on commit 08fa81b

Please sign in to comment.