Skip to content

Commit

Permalink
Fix some potential after-dispose crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Jul 8, 2024
1 parent 46538e5 commit 4a6b4a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ describe('Program', () => {
program.dispose();
});

it('does not throw exception after calling validate() after dispose()', () => {
program.setFile('source/themes/alpha.bs', `
sub main()
end sub
`);
program.dispose();
program.validate();
});

it('Does not crash for file not referenced by any other scope', async () => {
program.setFile('tests/testFile.spec.bs', `
function main(args as object) as object
Expand Down
6 changes: 3 additions & 3 deletions src/Scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export class Scope {

//get callables from own files
this.enumerateOwnFiles((file) => {
for (let callable of file.callables) {
for (let callable of file?.callables ?? []) {
result.push({
callable: callable,
scope: this
Expand Down Expand Up @@ -843,7 +843,7 @@ export class Scope {
* Find various function collisions
*/
private diagnosticDetectFunctionCollisions(file: BscFile) {
for (let func of file.callables) {
for (let func of file?.callables ?? []) {
const funcName = func.getName(ParseMode.BrighterScript);
const lowerFuncName = funcName?.toLowerCase();
if (lowerFuncName) {
Expand Down Expand Up @@ -932,7 +932,7 @@ export class Scope {
*/
private diagnosticDetectFunctionCallsWithWrongParamCount(file: BscFile, callableContainersByLowerName: CallableContainerMap) {
//validate all function calls
for (let expCall of file.functionCalls) {
for (let expCall of file?.functionCalls ?? []) {
let callableContainersWithThisName = callableContainersByLowerName.get(expCall.name.toLowerCase());

//use the first item from callablesByLowerName, because if there are more, that's a separate error
Expand Down
2 changes: 1 addition & 1 deletion src/bscPlugin/validation/ScopeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class ScopeValidator {
protected validateCreateObjectCalls(file: BrsFile) {
const diagnostics: BsDiagnostic[] = [];

for (const call of file.functionCalls) {
for (const call of file?.functionCalls ?? []) {
//skip non CreateObject function calls
if (call.name?.toLowerCase() !== 'createobject' || !isLiteralExpression(call?.args[0]?.expression)) {
continue;
Expand Down
2 changes: 0 additions & 2 deletions src/lsp/ProjectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ export class ProjectManager {
*/
@TrackBusyStatus
private async flushDocumentChanges(event: FlushEvent) {
this.logger.log('flushDocumentChanges', event.actions.map(x => x.srcPath));

//ensure that we're fully initialized before proceeding
await this.onInitialized();

Expand Down

0 comments on commit 4a6b4a7

Please sign in to comment.