[typer] Reuse PolyType objects
Sathya Gunasekaran committed
Dec 20, 2022 at 13:38 UTC
6f06b0e08a4ae43785e8b9fd2270d459af455973
1 file changed
+8
-5
compiler/forget/src/HIR/InferTypes.ts
+8
-5
@@ -317,12 +317,15 @@ class Unifier {
317
objectType.kind === "Object" &&
318
objectType.properties.has(name[0])
319
) {
320
- const newType: Type = {
321
- kind: "Poly",
322
- };
320
+ let type = objectType.properties.get(name[0])!;
321
+ if (type.kind === "Poly") {
322
+ return type;
323
+ }
324
324
- objectType.properties.set(name[0], newType);
325
- return newType;
325
+ type = { kind: "Poly" };
326
+
327
+ objectType.properties.set(name[0], type);
328
+ return type;
329
}
330
331
return null;