diff --git a/src/Scope.spec.ts b/src/Scope.spec.ts index 1b7bf8022..ea13f8deb 100644 --- a/src/Scope.spec.ts +++ b/src/Scope.spec.ts @@ -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() diff --git a/src/bscPlugin/validation/ScopeValidator.ts b/src/bscPlugin/validation/ScopeValidator.ts index a14c874a3..71b433487 100644 --- a/src/bscPlugin/validation/ScopeValidator.ts +++ b/src/bscPlugin/validation/ScopeValidator.ts @@ -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(