[be] Clean up null -> PolyType in ObjectShape
--- Question - should the unifier ignore `PolyType` for now? ```js class Unifier { // ... bindVariableTo(v: TypeVar, type: Type) { if (type.kind === "Poly") { return; } // ... ```
Mofei Zhang committed
Mar 30, 2023 at 15:03 UTC
25388d3fda8ea901a12c81a3c7c4db62b67771f4
3 files changed
+11
-5
compiler/forget/src/HIR/Environment.ts
+2
-1
@@ -8,6 +8,7 @@ import {
8
IdentifierId,
9
makeIdentifierId,
10
ObjectType,
11
+ PolyType,
12
ValueKind,
13
} from "./HIR";
14
import { Hook } from "./Hooks";
@@ -84,7 +85,7 @@ export class Environment {
85
getPropertyType(
86
receiver: ObjectType | FunctionType,
87
property: string
87
- ): BuiltInType | null {
88
+ ): BuiltInType | PolyType | null {
89
const { shapeId } = receiver;
90
if (shapeId !== null) {
91
// If an object or function has a shapeId, it must have been assigned
compiler/forget/src/HIR/ObjectShape.ts
+4
-4
@@ -38,7 +38,7 @@ function createAnonId(): string {
38
*/
39
export function addFunction(
40
registry: ShapeRegistry,
41
- properties: Iterable<[string, BuiltInType | null]>,
41
+ properties: Iterable<[string, BuiltInType | PolyType]>,
42
fn: FunctionSignature
43
): FunctionType {
44
const shapeId = createAnonId();
@@ -58,7 +58,7 @@ export function addFunction(
58
export function addObject(
59
registry: ShapeRegistry,
60
id: string | null,
61
- properties: Iterable<[string, BuiltInType | null]>
61
+ properties: Iterable<[string, BuiltInType | PolyType]>
62
): ObjectType {
63
const shapeId = id ?? createAnonId();
64
addShape(registry, shapeId, properties, null);
@@ -71,7 +71,7 @@ export function addObject(
71
function addShape(
72
registry: ShapeRegistry,
73
id: string,
74
- properties: Iterable<[string, BuiltInType | null]>,
74
+ properties: Iterable<[string, BuiltInType | PolyType]>,
75
functionType: FunctionSignature | null
76
): ObjectShape {
77
const shape: ObjectShape = {
@@ -110,7 +110,7 @@ export type FunctionSignature = {
110
* are both represented by {@link ObjectShape.functionType}.
111
*/
112
export type ObjectShape = {
113
- properties: Map<string, BuiltInType | null>;
113
+ properties: Map<string, BuiltInType | PolyType>;
114
functionType: FunctionSignature | null;
115
};
116
compiler/forget/src/TypeInference/InferTypes.ts
+5
@@ -236,6 +236,11 @@ class Unifier {
236
}
237
238
bindVariableTo(v: TypeVar, type: Type): void {
239
+ if (type.kind === "Poly") {
240
+ // Ignore PolyType, since we don't support polymorphic types correctly.
241
+ return;
242
+ }
243
+
244
if (this.substitutions.has(v.id)) {
245
this.unify(this.substitutions.get(v.id)!, type);
246
return;