Skip to content

Commit

Permalink
Fixes using upper namespaced function indirectly
Browse files Browse the repository at this point in the history
  • Loading branch information
markwpearce committed Oct 8, 2024
1 parent 9cde191 commit 9c3238f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/bscPlugin/validation/ScopeValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,44 @@ describe('ScopeValidator', () => {
program.validate();
expectZeroDiagnostics(program);
});

it('has error when referencing something in outer namespace directly', () => {
program.setFile('source/main.bs', `
namespace alpha
sub foo()
end sub
namespace beta
sub bar()
foo()
end sub
end namespace
end namespace
`);

program.validate();
expectDiagnostics(program, [
DiagnosticMessages.cannotFindFunction('foo').message
]);
});

it('allows referencing something in outer namespace with namespace in front', () => {
program.setFile('source/main.bs', `
namespace alpha
sub foo()
end sub
namespace beta
sub bar()
alpha.foo()
end sub
end namespace
end namespace
`);

program.validate();
expectZeroDiagnostics(program);
});
});

describe('itemCannotBeUsedAsVariable', () => {
Expand Down
41 changes: 41 additions & 0 deletions src/files/BrsFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,47 @@ describe('BrsFile', () => {
);
});

it('transpiles namespaced functions when used as variables', async () => {
await testTranspile(`
namespace Vertibrates.Birds
function GetAllBirds()
return [
GetDuck(),
GetGoose()
]
end function
function GetDuck()
end function
function GetGoose()
end function
function Test()
duckGetter = Vertibrates.Birds.GetDuck
gooseGetter = GetGoose
end function
end namespace`, `
function Vertibrates_Birds_GetAllBirds()
return [
Vertibrates_Birds_GetDuck()
Vertibrates_Birds_GetGoose()
]
end function
function Vertibrates_Birds_GetDuck()
end function
function Vertibrates_Birds_GetGoose()
end function
function Vertibrates_Birds_Test()
duckGetter = Vertibrates_Birds_GetDuck
gooseGetter = Vertibrates_Birds_GetGoose
end function
`);
});

});

describe('shadowing', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/Statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ export class NamespaceStatement extends Statement implements TypedefProvider {
};
this.nameExpression = options.nameExpression;
this.body = options.body;
this.symbolTable = new SymbolTable(`NamespaceStatement: '${this.name}'`, () => this.parent?.getSymbolTable());
this.symbolTable = new SymbolTable(`NamespaceStatement: '${this.name}'`, () => this.getRoot()?.getSymbolTable());
}

public readonly tokens: {
Expand Down

0 comments on commit 9c3238f

Please sign in to comment.