Skip to content

Commit

Permalink
- fix SNEX compiler not detecting illegal outer class member access
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Oct 13, 2024
1 parent 0082207 commit 18fa3ac
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion currentGitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c74524c48743ccc455d802694a731daa94a1bf8e
00822079687481f8979f0fe7299029f3e988160b
2 changes: 1 addition & 1 deletion hi_backend/backend/currentGit.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PREVIOUS_HISE_COMMIT "c74524c48743ccc455d802694a731daa94a1bf8e"
#define PREVIOUS_HISE_COMMIT "00822079687481f8979f0fe7299029f3e988160b"
23 changes: 23 additions & 0 deletions hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,29 @@ void Operations::ThisPointer::process(BaseCompiler* compiler, BaseScope* scope)
{
processBaseWithoutChildren(compiler, scope);

COMPILER_PASS(BaseCompiler::ResolvingSymbols)
{
auto cScope = scope->getParentScopeOfType<ClassScope>();

if(auto currentClass = dynamic_cast<StructType*>(cScope->typePtr.get()))
{
auto thisType = dynamic_cast<StructType*>(type.get());

if(thisType != currentClass)
{
// Apparently we need to allow different template parameters to go through
// here so we check the namespaced identifier
auto differentClass = thisType->id != currentClass->id;

if(differentClass)
location.throwError("Can't access outer member from inner class");
}
}



}

#if SNEX_ASMJIT_BACKEND
COMPILER_PASS(BaseCompiler::CodeGeneration)
{
Expand Down
35 changes: 35 additions & 0 deletions tools/snex_playground/test_files/struct/outer_member_access.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
BEGIN_TEST_DATA
f: main
ret: int
args: int
input: 12
output: 12
error: "Line 21(11): Can't access outer member from inner class"
filename: "struct/outer_member_access"
END_TEST_DATA
*/

struct Outer
{
struct Inner
{
int x = 9;

int getV()
{
return v;
}
};

Inner data;

int v = 12;
};

int main(int input)
{
Outer obj;
return obj.data.getV();
}

0 comments on commit 18fa3ac

Please sign in to comment.