diff options
| author | Anders Leino <aleino@nvidia.com> | 2025-02-06 10:45:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-06 08:45:11 +0000 |
| commit | 075b10e69055acc6536d74c1cb3399e0fe75338d (patch) | |
| tree | 577a56d61565058047f8e5e5d35215fbd5608816 /source/slang/slang-parser.cpp | |
| parent | 6b63ff0265ee9bdb8229bb12c71c223c00de0ffa (diff) | |
Don't overwrite existing module decl scopes when parsing new source files (#6292)
When a module consists of multiple source files, the module scope gets over-written for
each source file that's parsed into the module.
The result is that if you do something like the following, where source1.slang contains
an import statement, then the imported module will get imported into the module scope
corresponding to source2.slang, but won't be found from the scope of source1.slang.
slangc source1.slang source2.slang # 1 module from 2 source files
This patch fixes this problem by not over-writing existing container decl scope
when parsing new source files into the container.
This closes $6221.
Diffstat (limited to 'source/slang/slang-parser.cpp')
| -rw-r--r-- | source/slang/slang-parser.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 342ac9e55..95eb971ee 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -5127,7 +5127,11 @@ void Parser::parseSourceFile(ContainerDecl* program) currentModule = getModuleDecl(program); - PushScope(program); + // If the program already has a scope, then reuse it instead of overwriting it! + if (program->ownedScope) + PushScope(program->ownedScope); + else + PushScope(program); // A single `ModuleDecl` might span multiple source files, so it // is possible that we are parsing a new source file into a module |
