Skip to content
Merged
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
21 changes: 21 additions & 0 deletions src/Scope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,27 @@ describe('Scope', () => {
]);
});

it('points each duplicate callable at the other declarations, but not itself', () => {
program.setFile('source/file.brs', `
function DoA()
end function

function DoA()
end function
`);
program.validate();
const diagnostics = program.getDiagnostics()
.filter(x => x.code === DiagnosticMessages.duplicateFunctionImplementation('DoA').code)
.sort((a, b) => a.location.range.start.line - b.location.range.start.line);
//only look at the "declared here" entries (the diagnostic manager also adds an "In scope" entry)
expect(diagnostics.map(x => x.relatedInformation.filter(r => r.message === 'Function declared here').map(r => r.location.range))).to.eql([
//the first declaration points at the second one
[util.createRange(4, 26, 4, 29)],
//the second declaration points at the first one
[util.createRange(1, 25, 1, 28)]
]);
});

it('detects calls to unknown callables', () => {
program.setFile('source/file.brs', `
function DoA()
Expand Down
3 changes: 2 additions & 1 deletion src/bscPlugin/validation/ScopeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,8 @@ export class ScopeValidator {
const related = [];
for (const ownCallable of ownCallables) {
const thatNameRange = ownCallable.callable.nameRange;
if (ownCallable.callable.nameRange !== callable.nameRange) {
//skip the callable itself. Compare the callables rather than their ranges, which aren't guaranteed to be the same object
if (ownCallable.callable !== callable) {
related.push({
message: `Function declared here`,
location: util.createLocationFromRange(
Expand Down
Loading