Skip to content

Commit

Permalink
Don't overwrite existing module decl scopes when parsing new source f…
Browse files Browse the repository at this point in the history
…iles (#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.
  • Loading branch information
aleino-nv authored Feb 6, 2025
1 parent 6b63ff0 commit 075b10e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion source/slang/slang-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 075b10e

Please sign in to comment.