Fix modules without return type throwing segmentation fault
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
80f3af22ac
commit
3a9f1f976a
|
@ -25,7 +25,7 @@ Porygon::Script::Script(const u16string& s, ScriptOptions* options)
|
||||||
: Diagnostics(make_shared<Diagnostics::DiagnosticsHolder>(s)),
|
: Diagnostics(make_shared<Diagnostics::DiagnosticsHolder>(s)),
|
||||||
_boundScript(nullptr),
|
_boundScript(nullptr),
|
||||||
_scriptVariables(new map<Utilities::HashedString, EvalValuePointer>()),
|
_scriptVariables(new map<Utilities::HashedString, EvalValuePointer>()),
|
||||||
_scriptTypes(new unordered_map<Utilities::HashedString, shared_ptr<ScriptType>>{}),
|
_scriptTypes(new unordered_map<Utilities::HashedString, shared_ptr<const ScriptType>>{}),
|
||||||
_scriptOptions(options)
|
_scriptOptions(options)
|
||||||
{
|
{
|
||||||
_evaluator = new Evaluator(this -> _scriptVariables, this -> GetScriptOptions());
|
_evaluator = new Evaluator(this -> _scriptVariables, this -> GetScriptOptions());
|
||||||
|
@ -63,7 +63,7 @@ void Porygon::Script::Parse(const u16string& script) {
|
||||||
delete v.second;
|
delete v.second;
|
||||||
}
|
}
|
||||||
for (const auto& v : variableTypes){
|
for (const auto& v : variableTypes){
|
||||||
this->_scriptTypes -> insert({v.first, nullptr});
|
this->_scriptTypes -> insert({v.first, v.second});
|
||||||
}
|
}
|
||||||
scriptScope.clear();
|
scriptScope.clear();
|
||||||
variableTypes.clear();
|
variableTypes.clear();
|
||||||
|
@ -109,7 +109,7 @@ Porygon::Script::Script(shared_ptr<BoundScriptStatement> boundScript,
|
||||||
: _boundScript(std::move(boundScript)),
|
: _boundScript(std::move(boundScript)),
|
||||||
Diagnostics(std::move(diagnostics)),
|
Diagnostics(std::move(diagnostics)),
|
||||||
_scriptVariables(new map<Utilities::HashedString, EvalValuePointer>()),
|
_scriptVariables(new map<Utilities::HashedString, EvalValuePointer>()),
|
||||||
_scriptTypes(new unordered_map<Utilities::HashedString, shared_ptr<ScriptType>>{}),
|
_scriptTypes(new unordered_map<Utilities::HashedString, shared_ptr<const ScriptType>>{}),
|
||||||
_scriptOptions(nullptr)
|
_scriptOptions(nullptr)
|
||||||
{
|
{
|
||||||
_evaluator = new Evaluator(_scriptVariables, this -> GetScriptOptions());
|
_evaluator = new Evaluator(_scriptVariables, this -> GetScriptOptions());
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Porygon{
|
||||||
class Script {
|
class Script {
|
||||||
Evaluator* _evaluator;
|
Evaluator* _evaluator;
|
||||||
map<Utilities::HashedString, EvalValuePointer>* _scriptVariables;
|
map<Utilities::HashedString, EvalValuePointer>* _scriptVariables;
|
||||||
unordered_map<Utilities::HashedString, shared_ptr<ScriptType>>* _scriptTypes;
|
unordered_map<Utilities::HashedString, shared_ptr<const ScriptType>>* _scriptTypes;
|
||||||
shared_ptr<Binder::BoundScriptStatement> _boundScript;
|
shared_ptr<Binder::BoundScriptStatement> _boundScript;
|
||||||
shared_ptr<const ScriptType> _returnType = nullptr;
|
shared_ptr<const ScriptType> _returnType = nullptr;
|
||||||
ScriptOptions* _scriptOptions;
|
ScriptOptions* _scriptOptions;
|
||||||
|
|
|
@ -24,7 +24,14 @@ local module = {
|
||||||
}
|
}
|
||||||
return module
|
return module
|
||||||
)")
|
)")
|
||||||
}
|
},
|
||||||
|
{"simple_no_return", Script::Create(u"foo = 500")},
|
||||||
|
{"no_return_with_local", Script::Create(uR"(
|
||||||
|
local foo = 684
|
||||||
|
function bar()
|
||||||
|
return foo
|
||||||
|
end
|
||||||
|
)")},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,5 +113,31 @@ return list.contains({"foo", "bar"}, "bar")
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Simple no return module", "[integration]" ) {
|
||||||
|
ModuleHandler::Initialize();
|
||||||
|
auto script = Script::Create(uR"(
|
||||||
|
require("simple_no_return")
|
||||||
|
return foo
|
||||||
|
)");
|
||||||
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
|
auto result = script->Evaluate();
|
||||||
|
CHECK(result->EvaluateInteger() == 500);
|
||||||
|
|
||||||
|
delete script;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Simple no return module with local variable", "[integration]" ) {
|
||||||
|
ModuleHandler::Initialize();
|
||||||
|
auto script = Script::Create(uR"(
|
||||||
|
require("no_return_with_local")
|
||||||
|
return bar()
|
||||||
|
)");
|
||||||
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
|
auto result = script->Evaluate();
|
||||||
|
CHECK(result->EvaluateInteger() == 684);
|
||||||
|
|
||||||
|
delete script;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue