@samitouri / QOS-React-2 / commits / e0562bbd51

[typer] Type hook callee as Hook type

Sathya Gunasekaran committed Feb 14, 2023 at 23:07 UTC e0562bbd51c8da906e62e34e335d2bacd48aba6e
1 file changed +9 -1
compiler/forget/src/TypeInference/InferTypes.ts
+9 -1
@@ -9,6 +9,7 @@ import {
9 TypeVar,
10 } from "../HIR/HIR";
11 import { eachInstructionOperand } from "../HIR/visitors";
12 +import { parseHookCall } from "../Inference/InferReferenceEffects";
13
14 function isPrimitiveBinaryOp(op: t.BinaryExpression["operator"]) {
15 switch (op) {
@@ -120,7 +121,14 @@ function* generateInstructionTypes(
121 }
122
123 case "CallExpression": {
123 - yield equation(value.callee.identifier.type, { kind: "Function" });
124 + const hook = parseHookCall(value.callee);
125 + let type: Type;
126 + if (hook !== null) {
127 + type = { kind: "Hook", name: hook.name };
128 + } else {
129 + type = { kind: "Function" };
130 + }
131 + yield equation(value.callee.identifier.type, type);
132 break;
133 }
134