Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/source/pl/core/ast/ast_node_match_statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace pl::core::ast {
std::vector<std::shared_ptr<ptrn::Pattern>> newPatterns;
node->createPatterns(evaluator, newPatterns);
for (auto &pattern : newPatterns) {
pattern->setSection(evaluator->getSectionId());
scope.push_back(std::move(pattern));
}

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ set(AVAILABLE_TESTS
DuplicateVariableFail
StaticArrayRangeOverflowFail
Dollar
SectionStatements
InVariableDefault
InVariableOverride
SetEntriesSortedConsistency
Expand Down
57 changes: 57 additions & 0 deletions tests/include/test_patterns/test_pattern_section_statements.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once

#include "test_pattern.hpp"

namespace pl::test {

class TestPatternSectionStatements : public TestPattern {
public:
TestPatternSectionStatements(core::Evaluator *evaluator) : TestPattern(evaluator, "SectionStatements") {
}
~TestPatternSectionStatements() override = default;

[[nodiscard]] std::string getSourceCode() const override {
return R"(
auto section = builtin::std::mem::create_section("data");
builtin::std::mem::copy_value_to_section("ABCDEFGHIJKL", section, 0);

struct Inner {
u8 a;
};

struct S {
u8 plain;
match (plain) {
(_): u8 inMatch;
}
if (true) {
u8 inIf;
}
try {
u8 inTry;
} catch { }
try {
u8 failing[1] @ 0x100;
u8 failed = failing[1];
} catch {
u8 inCatch;
}
Inner inner;
match (plain) {
(_): Inner structInMatch;
}
};

S s @ 0x00 in section;
std::assert(s.plain == 0x41, "Struct member did not read from section");
std::assert(s.inMatch == 0x42, "Match arm member did not read from section");
std::assert(s.inIf == 0x43, "If body member did not read from section");
std::assert(s.inTry == 0x44, "Try body member did not read from section");
std::assert(s.inCatch == 0x45, "Catch body member did not read from section");
std::assert(s.inner.a == 0x46, "Nested struct member did not read from section");
std::assert(s.structInMatch.a == 0x47, "Struct in match arm did not read from section");
)";
}
};

}
2 changes: 2 additions & 0 deletions tests/source/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "test_patterns/test_pattern_extended_semantics.hpp"
#include "test_patterns/test_pattern_error_semantics.hpp"
#include "test_patterns/test_pattern_dollar.hpp"
#include "test_patterns/test_pattern_section_statements.hpp"
#include "test_patterns/test_pattern_in_variable_defaults.hpp"
#include "test_patterns/test_pattern_set_entries_sorted_consistency.hpp"
#include "test_patterns/test_pattern_allowed_redefinitions.hpp"
Expand Down Expand Up @@ -112,6 +113,7 @@ std::array Tests = {
TEST(DuplicateVariableFail),
TEST(StaticArrayRangeOverflowFail),
TEST(Dollar),
TEST(SectionStatements),
TEST(InVariableDefault),
TEST(InVariableOverride),
TEST(SetEntriesSortedConsistency),
Expand Down
Loading