@@ -4,6 +4,7 @@ import typeCheck from '../type-checker'
4
4
import { getRootEnv , getTypeEnv } from '../env'
5
5
import { fixture } from './helpers'
6
6
import { clone } from '../util'
7
+ import { Type } from '../types'
7
8
import { TypedNode , AstNode } from '../node-types'
8
9
9
10
import {
@@ -14,23 +15,23 @@ import {
14
15
BooleanType
15
16
} from '../types'
16
17
17
- function testTypeCheck ( code , env = getTypeEnv ( getRootEnv ( ) ) ) {
18
- test ( code , ( ) => {
19
- const parsed = parse ( code )
18
+ function testTypeCheck ( source : string , env = getTypeEnv ( getRootEnv ( ) ) ) {
19
+ test ( source , ( ) => {
20
+ const parsed = parse ( source )
20
21
const [ lastNode ] = typeCheck ( parsed , env )
21
22
const type = lastNode . exprType . toString ( )
22
23
expect ( type ) . toMatchSnapshot ( )
23
24
} )
24
25
} ;
25
26
26
- function testFails ( code , env = getTypeEnv ( getRootEnv ( ) ) ) {
27
- test ( code , ( ) => {
28
- const parsed = parse ( code )
27
+ function testFails ( source : string , env = getTypeEnv ( getRootEnv ( ) ) ) {
28
+ test ( source , ( ) => {
29
+ const parsed = parse ( source )
29
30
expect ( ( ) => typeCheck ( parsed , env ) ) . toThrowErrorMatchingSnapshot ( )
30
31
} )
31
32
}
32
33
33
- function testFixture ( fixtureName , env = getTypeEnv ( getRootEnv ( ) ) ) {
34
+ function testFixture ( fixtureName : string , env = getTypeEnv ( getRootEnv ( ) ) ) {
34
35
test ( fixtureName , ( ) => {
35
36
const parsed = parse ( fixture ( fixtureName ) )
36
37
const [ lastNode ] = typeCheck ( parsed , env )
@@ -86,7 +87,7 @@ testFails(`if (1) 1 else 2`)
86
87
87
88
// the peach type checker works over nodes with an `exprType` property.
88
89
// helper for creating nodes for synthetic type tests
89
- function typed ( type ) : TypedNode {
90
+ function typed ( type : Type ) : TypedNode {
90
91
return {
91
92
exprType : type ,
92
93
type : 'Str' ,
@@ -96,11 +97,11 @@ function typed (type): TypedNode {
96
97
97
98
// simulate a user-defined type
98
99
class PairType extends TypeOperator {
99
- constructor ( a , b ) {
100
+ constructor ( a : Type , b : Type ) {
100
101
super ( '*' , [ a , b ] )
101
102
}
102
103
103
- static of ( name , [ a , b ] ) {
104
+ static of ( name : string , [ a , b ] : Type [ ] ) {
104
105
return new PairType ( a , b )
105
106
}
106
107
@@ -109,9 +110,9 @@ class PairType extends TypeOperator {
109
110
}
110
111
}
111
112
112
- const A = typed ( new TypeVariable ( ) )
113
- const B = typed ( new TypeVariable ( ) )
114
- const AB = typed ( new PairType ( A , B ) )
113
+ const A = new TypeVariable ( )
114
+ const B = new TypeVariable ( )
115
+ const AB = new PairType ( A , B )
115
116
116
117
const testEnv = ( ) => ( {
117
118
// No unit type yet, so all functions take exactly one argument
0 commit comments