Skip to content

Commit 3f72120

Browse files
committed
Expose type checker method for package
1 parent fd272a5 commit 3f72120

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/types/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
import { check } from './checker'
12
import { Node } from './ast/types'
2-
import { typeCheckBody } from './checker'
3+
import { parse } from './ast'
34

4-
export type TypeCheckResult = { hasTypeErrors: boolean }
5+
export type TypeCheckResult = { hasTypeErrors: boolean; errorMessages: string[] }
6+
7+
export const parseProgram = (program: string): Node => {
8+
return parse(program)
9+
}
510

611
export const typeCheck = (ast: Node): TypeCheckResult => {
7-
const result = typeCheckBody(ast)
8-
return { hasTypeErrors: result.errors.length > 0 }
12+
const result = check(ast)
13+
return {
14+
hasTypeErrors: result.errors.length > 0,
15+
errorMessages: result.errors.map(error => error.message)
16+
}
917
}

src/types/inputs/Main.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
class A extends B {}
2-
class B extends A {}
31
public class Main {
4-
public static void main(String[] args) {}
5-
}
2+
public static void main(String[] args) {
3+
throwing();
4+
}
5+
public static void throwing() throws Exception {}
6+
}

0 commit comments

Comments
 (0)