[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; 

} 

// ... 

```
This commit is contained in:
Mofei Zhang
2023-03-30 15:03:11 -04:00
parent ffc1b5b700
commit 25388d3fda
3 changed files with 11 additions and 5 deletions
+2 -1
View File
@@ -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
+4 -4
View File
@@ -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<string, BuiltInType | null>;
properties: Map<string, BuiltInType | PolyType>;
functionType: FunctionSignature | null;
};
@@ -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;