Skip to content

Commit

Permalink
More robust
Browse files Browse the repository at this point in the history
  • Loading branch information
ajreynol committed Jul 21, 2023
1 parent 9c08486 commit c8dad09
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TypeChecker::TypeChecker(State& s) : d_state(s)
// initialize literal kinds
for (Kind k : d_literalKinds)
{
d_literalTypeRules[k] = d_state.mkBuiltinType(k);
d_literalTypeRules[k] = nullptr;
}
}

Expand All @@ -51,6 +51,12 @@ void TypeChecker::setTypeRule(Kind k, const Expr& t)
ss << "TypeChecker::setTypeRule: cannot set type rule for kind " << k;
Error::reportError(ss.str());
}
else if (it->second!=nullptr && it->second!=t)
{
std::stringstream ss;
ss << "TypeChecker::setTypeRule: cannot set type rule for kind " << k << " to " << t << ", since its type was already set to " << it->second;
Error::reportError(ss.str());
}
it->second = t;
}

Expand Down Expand Up @@ -213,8 +219,18 @@ Expr TypeChecker::getTypeInternal(Expr& e, std::ostream& out)
case Kind::HEXADECIMAL:
case Kind::BINARY:
case Kind::STRING:
{
Kind k = e->getKind();
// use the literal type rule
return d_literalTypeRules[e->getKind()];
Expr t = d_literalTypeRules[k];
if (t==nullptr)
{
t = d_state.mkBuiltinType(k);
d_literalTypeRules[k] = t;
}
return t;
}
break;
default:
break;
}
Expand Down

0 comments on commit c8dad09

Please sign in to comment.