Skip to content

Commit 303d215

Browse files
committed
WIP on strictNullChecks - this one is tough
1 parent 0f6d66a commit 303d215

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

src/interpreter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type Visitor = (node: TypedNode, env: RuntimeEnv) => InterpreterResult
2121
// Visit each of `nodes` in order, returning the result
2222
// and environment of the last node.
2323
function visitSerial (nodes: TypedNode[], rootEnv: RuntimeEnv): InterpreterResult {
24-
const initialState: [TypedNode, RuntimeEnv] = [null, rootEnv]
24+
const initialState: [TypedNode, RuntimeEnv] = [nodes[0], rootEnv]
2525
return nodes.reduce(([, env], node) => (
2626
visit(node, env)
2727
), initialState)

src/type-checker.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
AstDestructuredArrayNode, AstFunctionNode, AstIfNode,
99
TypedAst, TypedNode, TypedProgramNode, TypedDefNode, TypedNameNode,
1010
TypedNumeralNode, TypedBooleanNode, TypedStringNode, TypedCallNode, TypedArrayNode,
11-
TypedDestructuredArrayNode, TypedFunctionNode, TypedFunctionClauseNode, TypedIfNode
11+
TypedDestructuredArrayNode, TypedFunctionNode, TypedFunctionClauseNode, TypedIfNode,
12+
NoBoundValueYetNode
1213
} from './node-types'
1314

1415
import {
@@ -294,6 +295,8 @@ function fresh (type: Type, nonGeneric: Set<Type>) {
294295

295296
// FIXME find out how to do this with type safety, given type erasure.
296297
return (pruned.constructor as any).of(pruned.name, freshTypeArgs)
298+
} else {
299+
return t
297300
}
298301
}
299302

src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class TypeVariable extends Type {
9494
instance: Type
9595

9696
constructor () {
97-
super(null)
97+
super('')
9898
this.id = TypeVariable.nextId ++
9999
}
100100

src/unify.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isArray, isEqual } from './array'
33
import { zip } from './util'
44
import { AstNode, AstLiteralNode, AstDestructuredArrayNode, Value, isAstLiteralNode } from './node-types'
55

6-
// FIXME tagged union - with didMatch: false, there are never bindings.
6+
// FIXME tagged union - with didMatch: false, there are never bindings (hence binding | null return types)
77
type binding = { [name: string]: Value }
88

99
interface unification {
@@ -29,7 +29,7 @@ export default function unify (patterns: AstNode[], values: Value[]): unificatio
2929
return didMatch(bindings)
3030
}
3131

32-
function unifyOne (pattern: AstNode, value: Value): binding {
32+
function unifyOne (pattern: AstNode, value: Value): binding | null {
3333
if (isAstLiteralNode(pattern) && pattern.value === value) {
3434
// the pattern matched, but there is nothing to bind
3535
return {}
@@ -54,7 +54,7 @@ function unifyOne (pattern: AstNode, value: Value): binding {
5454
}
5555

5656
// TODO this will need to change when Array is a wrapped type
57-
function destructure ({ head, tail }: AstDestructuredArrayNode, values: Value[]): binding {
57+
function destructure ({ head, tail }: AstDestructuredArrayNode, values: Value[]): binding | null {
5858
if (values.length === 0) {
5959
throw new PeachError(`Empty arrays cannot be destructured because they don't have a head`)
6060
}

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"target": "es2017",
88
"sourceMap": true,
99
"noImplicitAny": true,
10+
"strictNullChecks": true,
1011
"noImplicitThis": true,
1112
"alwaysStrict": true
1213
},

0 commit comments

Comments
 (0)