Log error when variable is unknown type.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0fbca3f01e
commit
ce3d92e0a5
@ -1,10 +1,11 @@
|
|||||||
#include "Binder.hpp"
|
#include "Binder.hpp"
|
||||||
#include "../CoreData/PrimitiveTypes.hpp"
|
#include "../CoreData/PrimitiveTypes.hpp"
|
||||||
#include "../Diagnostics/Logger.hpp"
|
|
||||||
using namespace MalachScript::Parser;
|
using namespace MalachScript::Parser;
|
||||||
using namespace MalachScript::Diagnostics;
|
using namespace MalachScript::Diagnostics;
|
||||||
|
|
||||||
namespace MalachScript::Binder {
|
namespace MalachScript::Binder {
|
||||||
|
static const BoundType* UnknownType = new BoundType("???"_id, ClassAttr::None, 0);
|
||||||
|
|
||||||
void Binder::Bind(BoundNamespace* ns, const std::vector<const MalachScript::Parser::ParsedStatement*>& statements,
|
void Binder::Bind(BoundNamespace* ns, const std::vector<const MalachScript::Parser::ParsedStatement*>& statements,
|
||||||
const Binder::log_func& log) {
|
const Binder::log_func& log) {
|
||||||
for (const auto* s : statements) {
|
for (const auto* s : statements) {
|
||||||
@ -195,7 +196,9 @@ namespace MalachScript::Binder {
|
|||||||
// FIXME: Resolve namespace of scoped identifier
|
// FIXME: Resolve namespace of scoped identifier
|
||||||
auto type = ResolveType(ns, typeStatement->GetScopedIdentifier().GetIdentifier());
|
auto type = ResolveType(ns, typeStatement->GetScopedIdentifier().GetIdentifier());
|
||||||
if (!type.has_value()) {
|
if (!type.has_value()) {
|
||||||
throw std::logic_error("Shouldn't be reached");
|
log(DiagnosticLevel::Error, DiagnosticType::UnknownType, typeStatement->GetSpan(),
|
||||||
|
{typeStatement->GetScopedIdentifier().GetIdentifier().GetStdString()});
|
||||||
|
type = UnknownType;
|
||||||
}
|
}
|
||||||
if (activeType.has_value()) {
|
if (activeType.has_value()) {
|
||||||
activeType.value()->AddField(var->GetIdentifier(),
|
activeType.value()->AddField(var->GetIdentifier(),
|
||||||
|
@ -312,27 +312,31 @@ namespace MalachScript::Parser {
|
|||||||
}
|
}
|
||||||
ScopedIdentifier scopedIdentifier;
|
ScopedIdentifier scopedIdentifier;
|
||||||
ParseScope(scopedIdentifier.GetScope(), current, log);
|
ParseScope(scopedIdentifier.GetScope(), current, log);
|
||||||
|
auto end = current->GetSpan().GetEnd();
|
||||||
if (!ParseDataType(scopedIdentifier.GetIdentifier(), current, log)) {
|
if (!ParseDataType(scopedIdentifier.GetIdentifier(), current, log)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO: Generics.
|
// TODO: Generics.
|
||||||
if (current->GetKind() == LexTokenKind::OpenBlockParenthesisSymbol) {
|
if (current->GetKind() == LexTokenKind::OpenBlockParenthesisSymbol) {
|
||||||
|
end = current->GetSpan().GetEnd();
|
||||||
PROGRESS_TOKEN(current);
|
PROGRESS_TOKEN(current);
|
||||||
if (current->GetKind() != LexTokenKind::CloseBlockParenthesisSymbol) {
|
if (current->GetKind() != LexTokenKind::CloseBlockParenthesisSymbol) {
|
||||||
logUnexpectedToken(CloseCurlyParenthesisSymbol, current);
|
logUnexpectedToken(CloseCurlyParenthesisSymbol, current);
|
||||||
} else {
|
} else {
|
||||||
|
end = current->GetSpan().GetEnd();
|
||||||
PROGRESS_TOKEN(current);
|
PROGRESS_TOKEN(current);
|
||||||
isArray = true;
|
isArray = true;
|
||||||
}
|
}
|
||||||
} else if (current->GetKind() == LexTokenKind::AtSymbol) {
|
} else if (current->GetKind() == LexTokenKind::AtSymbol) {
|
||||||
isHandle = true;
|
isHandle = true;
|
||||||
|
end = current->GetSpan().GetEnd();
|
||||||
PROGRESS_TOKEN(current);
|
PROGRESS_TOKEN(current);
|
||||||
if (current->GetKind() == LexTokenKind::ConstKeyword) {
|
if (current->GetKind() == LexTokenKind::ConstKeyword) {
|
||||||
isConst = true;
|
isConst = true;
|
||||||
|
end = current->GetSpan().GetEnd();
|
||||||
PROGRESS_TOKEN(current);
|
PROGRESS_TOKEN(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto end = current->GetSpan().GetEnd();
|
|
||||||
currentToken = current;
|
currentToken = current;
|
||||||
out = new ParsedTypeStatement(ScriptTextSpan(start, end, current->GetSpan().GetScriptName()), isConst, isArray,
|
out = new ParsedTypeStatement(ScriptTextSpan(start, end, current->GetSpan().GetScriptName()), isConst, isArray,
|
||||||
isHandle, scopedIdentifier);
|
isHandle, scopedIdentifier);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user