diff --git a/compiler/forget/src/HIR/Environment.ts b/compiler/forget/src/HIR/Environment.ts index f9b73e8888..e2f044c27d 100644 --- a/compiler/forget/src/HIR/Environment.ts +++ b/compiler/forget/src/HIR/Environment.ts @@ -8,6 +8,7 @@ import { IdentifierId, makeIdentifierId, ObjectType, + PolyType, ValueKind, } from "./HIR"; import { Hook } from "./Hooks"; @@ -84,7 +85,7 @@ export class Environment { getPropertyType( receiver: ObjectType | FunctionType, property: string - ): BuiltInType | null { + ): BuiltInType | PolyType | null { const { shapeId } = receiver; if (shapeId !== null) { // If an object or function has a shapeId, it must have been assigned diff --git a/compiler/forget/src/HIR/ObjectShape.ts b/compiler/forget/src/HIR/ObjectShape.ts index ba722c98b5..4b21252d25 100644 --- a/compiler/forget/src/HIR/ObjectShape.ts +++ b/compiler/forget/src/HIR/ObjectShape.ts @@ -38,7 +38,7 @@ function createAnonId(): string { */ export function addFunction( registry: ShapeRegistry, - properties: Iterable<[string, BuiltInType | null]>, + properties: Iterable<[string, BuiltInType | PolyType]>, fn: FunctionSignature ): FunctionType { const shapeId = createAnonId(); @@ -58,7 +58,7 @@ export function addFunction( export function addObject( registry: ShapeRegistry, id: string | null, - properties: Iterable<[string, BuiltInType | null]> + properties: Iterable<[string, BuiltInType | PolyType]> ): ObjectType { const shapeId = id ?? createAnonId(); addShape(registry, shapeId, properties, null); @@ -71,7 +71,7 @@ export function addObject( function addShape( registry: ShapeRegistry, id: string, - properties: Iterable<[string, BuiltInType | null]>, + properties: Iterable<[string, BuiltInType | PolyType]>, functionType: FunctionSignature | null ): ObjectShape { const shape: ObjectShape = { @@ -110,7 +110,7 @@ export type FunctionSignature = { * are both represented by {@link ObjectShape.functionType}. */ export type ObjectShape = { - properties: Map; + properties: Map; functionType: FunctionSignature | null; }; diff --git a/compiler/forget/src/TypeInference/InferTypes.ts b/compiler/forget/src/TypeInference/InferTypes.ts index 1fdb3bbb31..26663915cf 100644 --- a/compiler/forget/src/TypeInference/InferTypes.ts +++ b/compiler/forget/src/TypeInference/InferTypes.ts @@ -236,6 +236,11 @@ class Unifier { } bindVariableTo(v: TypeVar, type: Type): void { + if (type.kind === "Poly") { + // Ignore PolyType, since we don't support polymorphic types correctly. + return; + } + if (this.substitutions.has(v.id)) { this.unify(this.substitutions.get(v.id)!, type); return;