Fix return-statements not being type-checked
This commit is contained in:
parent
1d314808a9
commit
7024b8790d
1 changed files with 8 additions and 9 deletions
|
@ -393,8 +393,9 @@ namespace bolt {
|
||||||
case NodeKind::LetDeclaration:
|
case NodeKind::LetDeclaration:
|
||||||
{
|
{
|
||||||
auto Decl = static_cast<LetDeclaration*>(N);
|
auto Decl = static_cast<LetDeclaration*>(N);
|
||||||
|
bool HasContext = !Decl->Params.empty();
|
||||||
|
|
||||||
if (!Decl->Params.empty()) {
|
if (HasContext) {
|
||||||
Contexts.push_back(Decl->Ctx);
|
Contexts.push_back(Decl->Ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +420,8 @@ namespace bolt {
|
||||||
case NodeKind::LetBlockBody:
|
case NodeKind::LetBlockBody:
|
||||||
{
|
{
|
||||||
auto Block = static_cast<LetBlockBody*>(Decl->Body);
|
auto Block = static_cast<LetBlockBody*>(Decl->Body);
|
||||||
RetType = createTypeVar();
|
ZEN_ASSERT(HasContext);
|
||||||
|
RetType = Decl->Ctx->ReturnType;
|
||||||
for (auto Element: Block->Elements) {
|
for (auto Element: Block->Elements) {
|
||||||
infer(Element);
|
infer(Element);
|
||||||
}
|
}
|
||||||
|
@ -432,16 +434,13 @@ namespace bolt {
|
||||||
RetType = createTypeVar();
|
RetType = createTypeVar();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ParamTypes.empty()) {
|
if (HasContext) {
|
||||||
// Declaration is a plain (typed) variable
|
|
||||||
addConstraint(new CEqual { Decl->Ty, RetType, N });
|
|
||||||
} else {
|
|
||||||
// Declaration is a function
|
// Declaration is a function
|
||||||
addConstraint(new CEqual { Decl->Ty, new TArrow(ParamTypes, RetType), N });
|
addConstraint(new CEqual { Decl->Ty, new TArrow(ParamTypes, RetType), N });
|
||||||
}
|
|
||||||
|
|
||||||
if (!Decl->Params.empty()) {
|
|
||||||
Contexts.pop_back();
|
Contexts.pop_back();
|
||||||
|
} else {
|
||||||
|
// Declaration is a plain (typed) variable
|
||||||
|
addConstraint(new CEqual { Decl->Ty, RetType, N });
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue