Fixes for return statement, make Evaluate function on script return value
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
@@ -101,6 +101,8 @@ BoundStatement *Binder::BindFunctionDeclarationStatement(ParsedStatement *statem
|
||||
auto identifier = functionStatement->GetIdentifier();
|
||||
auto returnType = make_shared<ScriptType>(TypeClass::Nil);
|
||||
auto type = make_shared<FunctionScriptType>(returnType, parameterTypes, parameterKeys, scopeIndex);
|
||||
this->_currentFunction = type;
|
||||
|
||||
auto assignment = this->_scope->AssignVariable(identifier.GetHash(), type);
|
||||
if (assignment.GetResult() != VariableAssignmentResult::Ok){
|
||||
this -> _scriptData -> Diagnostics -> LogError(DiagnosticCode::CantAssignVariable, statement->GetStartPosition(), statement->GetLength());
|
||||
@@ -108,6 +110,7 @@ BoundStatement *Binder::BindFunctionDeclarationStatement(ParsedStatement *statem
|
||||
}
|
||||
auto boundBlock = this -> BindBlockStatement(functionStatement->GetBlock());
|
||||
this->_scope->GoOuterScope();
|
||||
this->_currentFunction = nullptr;
|
||||
return new BoundFunctionDeclarationStatement(type, assignment.GetKey(), (BoundBlockStatement*)boundBlock);
|
||||
}
|
||||
|
||||
@@ -117,7 +120,7 @@ BoundStatement *Binder::BindReturnStatement(ParsedStatement* statement){
|
||||
if (this->_currentFunction == nullptr){
|
||||
currentReturnType = this->_scriptData->GetReturnType();
|
||||
} else{
|
||||
currentReturnType = this->_currentFunction;
|
||||
currentReturnType = this->_currentFunction->GetReturnType();
|
||||
}
|
||||
if (expression == nullptr && currentReturnType != nullptr){
|
||||
this -> _scriptData -> Diagnostics -> LogError(DiagnosticCode::InvalidReturnType, statement->GetStartPosition(), statement->GetLength());
|
||||
@@ -125,8 +128,12 @@ BoundStatement *Binder::BindReturnStatement(ParsedStatement* statement){
|
||||
}
|
||||
auto boundExpression = this->BindExpression(expression);
|
||||
auto expresionType = boundExpression->GetType();
|
||||
if (currentReturnType == nullptr){
|
||||
currentReturnType.swap(expresionType);
|
||||
if (currentReturnType == nullptr || currentReturnType->GetClass() == TypeClass::Nil){
|
||||
if (this->_currentFunction == nullptr){
|
||||
this->_scriptData->SetReturnType(expresionType);
|
||||
} else{
|
||||
this->_currentFunction->SetReturnType(expresionType);
|
||||
}
|
||||
return new BoundReturnStatement(boundExpression);
|
||||
}
|
||||
if (currentReturnType.get()->operator!=(expresionType.get())){
|
||||
|
||||
Reference in New Issue
Block a user