Skip to content

Commit

Permalink
Fix bug in type inference for constructor arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
  • Loading branch information
Mihai Budiu committed Nov 18, 2022
1 parent 747d2d7 commit fabd91c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,21 @@ TypeInference::checkExternConstructor(const IR::Node* errorPosition,
if (!functionType->is<IR::Type_Method>())
BUG("Unexpected type for function %1%", functionType);

LOG2("Constructor type before specialization " << methodType << " with " << tvs);
TypeVariableSubstitutionVisitor substVisitor(tvs);
substVisitor.setCalledBy(this);
auto specMethodType = methodType->apply(substVisitor);
LOG2("Constructor type after specialization " << specMethodType);
learn(specMethodType, this);
auto canon = getType(specMethodType);
if (canon == nullptr)
return nullptr;

auto functionType = specMethodType->to<IR::Type_MethodBase>();
BUG_CHECK(functionType != nullptr, "Method type is %1%", specMethodType);
if (!functionType->is<IR::Type_Method>())
BUG("Unexpected type for function %1%", functionType);

ConstantTypeSubstitution cts(tvs, refMap, typeMap, this);
// Arguments may need to be cast, e.g., list expression to a
// header type.
Expand Down

0 comments on commit fabd91c

Please sign in to comment.