Fix #54: BindPattern is not bound during inference inside a match-expression
This commit is contained in:
parent
521e1f1e4f
commit
60f1e4519e
3 changed files with 19 additions and 2 deletions
|
@ -1637,6 +1637,9 @@ namespace bolt {
|
|||
};
|
||||
|
||||
class MatchCase : public Node {
|
||||
|
||||
Scope* TheScope = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
InferContext* Ctx;
|
||||
|
@ -1657,6 +1660,14 @@ namespace bolt {
|
|||
Token* getFirstToken() const override;
|
||||
Token* getLastToken() const override;
|
||||
|
||||
inline Scope* getScope() override {
|
||||
if (TheScope == nullptr) {
|
||||
TheScope = new Scope(this);
|
||||
}
|
||||
return TheScope;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
class MatchExpression : public Expression {
|
||||
|
|
|
@ -78,6 +78,12 @@ namespace bolt {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case NodeKind::MatchCase:
|
||||
{
|
||||
auto Case = static_cast<MatchCase*>(X);
|
||||
visitPattern(Case->Pattern, Case);
|
||||
break;
|
||||
}
|
||||
case NodeKind::LetDeclaration:
|
||||
{
|
||||
auto Decl = static_cast<LetDeclaration*>(X);
|
||||
|
|
|
@ -508,6 +508,7 @@ namespace bolt {
|
|||
|
||||
auto Instance = static_cast<InstanceDeclaration*>(Let->Parent);
|
||||
auto Class = cast<ClassDeclaration>(Instance->getScope()->lookup({ {}, getCanonicalText(Instance->Name) }, SymbolKind::Class));
|
||||
// TODO check if `Class` is nullptr
|
||||
auto SigLet = cast<LetDeclaration>(Class->getScope()->lookupDirect({ {}, Let->getNameAsString() }, SymbolKind::Var));
|
||||
|
||||
auto Params = addClassVars(Class, false);
|
||||
|
@ -1297,7 +1298,7 @@ namespace bolt {
|
|||
auto Y = static_cast<ReferenceExpression*>(N);
|
||||
auto Def = Y->getScope()->lookup(Y->getSymbolPath());
|
||||
// Name lookup failures will be reported directly in inferExpression().
|
||||
if (Def == nullptr || Def->getKind() == NodeKind::SourceFile) {
|
||||
if (Def == nullptr || Def->getKind() != NodeKind::LetDeclaration) {
|
||||
return;
|
||||
}
|
||||
// This case ensures that a deeply nested structure that references a
|
||||
|
@ -1307,7 +1308,6 @@ namespace bolt {
|
|||
RefGraph.addEdge(Stack.top(), Def->Parent);
|
||||
return;
|
||||
}
|
||||
ZEN_ASSERT(Def->getKind() == NodeKind::LetDeclaration);
|
||||
if (!Stack.empty()) {
|
||||
RefGraph.addEdge(Def, Stack.top());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue