Skip to content

Commit

Permalink
m should be typed as roAssociativeArray for all inline functions (#…
Browse files Browse the repository at this point in the history
…1272)

* Makes all inline functions have m as AA in symbol table

* Added hover test
  • Loading branch information
markwpearce authored Aug 6, 2024
1 parent 825b2ce commit 0b7f553
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/bscPlugin/hover/HoverProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,26 @@ describe('HoverProcessor', () => {
let hover = program.getHover(file.srcPath, util.createPosition(6, 40))[0];
expect(hover?.contents).eql([fence('MyIFace.member as invalid')]);
});

it('has m as an AA in inline function', () => {
const file = program.setFile('source/main.bs', `
class Test
sub method()
stub = function()
m.whatever = false
end function
end sub
end class
`);
program.validate();

// |m.whatever = false
let hover = program.getHover(file.srcPath, util.createPosition(4, 29))[0];
expect(hover?.contents).eql([fence('m as roAssociativeArray')]);
// m.what|ever = false
hover = program.getHover(file.srcPath, util.createPosition(4, 35))[0];
expect(hover?.contents).eql([fence('whatever as dynamic')]);
});
});

describe('callFunc', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/bscPlugin/validation/BrsFileValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isAALiteralExpression, isAliasStatement, isArrayType, isBlock, isBody, isClassStatement, isConditionalCompileConstStatement, isConditionalCompileErrorStatement, isConditionalCompileStatement, isConstStatement, isDottedGetExpression, isDottedSetStatement, isEnumStatement, isForEachStatement, isForStatement, isFunctionExpression, isFunctionStatement, isImportStatement, isIndexedGetExpression, isIndexedSetStatement, isInterfaceStatement, isLibraryStatement, isLiteralExpression, isNamespaceStatement, isTypecastStatement, isUnaryExpression, isVariableExpression, isWhileStatement } from '../../astUtils/reflection';
import { isAliasStatement, isArrayType, isBlock, isBody, isClassStatement, isConditionalCompileConstStatement, isConditionalCompileErrorStatement, isConditionalCompileStatement, isConstStatement, isDottedGetExpression, isDottedSetStatement, isEnumStatement, isForEachStatement, isForStatement, isFunctionExpression, isFunctionStatement, isImportStatement, isIndexedGetExpression, isIndexedSetStatement, isInterfaceStatement, isLibraryStatement, isLiteralExpression, isMethodStatement, isNamespaceStatement, isTypecastStatement, isUnaryExpression, isVariableExpression, isWhileStatement } from '../../astUtils/reflection';
import { createVisitor, WalkMode } from '../../astUtils/visitors';
import { DiagnosticMessages } from '../../DiagnosticMessages';
import type { BrsFile } from '../../files/BrsFile';
Expand Down Expand Up @@ -150,7 +150,8 @@ export class BrsFileValidator {
},
FunctionExpression: (node) => {
const funcSymbolTable = node.getSymbolTable();
if (!funcSymbolTable?.hasSymbol('m', SymbolTypeFlag.runtime) || node.findAncestor(isAALiteralExpression)) {
const isInlineFunc = !(isFunctionStatement(node.parent) || isMethodStatement(node.parent));
if (!funcSymbolTable?.hasSymbol('m', SymbolTypeFlag.runtime) || isInlineFunc) {
if (!isTypecastStatement(node.body?.statements?.[0])) {
funcSymbolTable?.addSymbol('m', { isInstance: true }, new AssociativeArrayType(), SymbolTypeFlag.runtime);
}
Expand Down
28 changes: 28 additions & 0 deletions src/bscPlugin/validation/ScopeValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,34 @@ describe('ScopeValidator', () => {
program.validate();
expectZeroDiagnostics(program);
});

it('allows anything on m in an anonymous function', () => {
program.setFile('source/main.bs', `
function test()
stub = function()
m.something = true
end function
return stub
end function
`);
program.validate();
expectZeroDiagnostics(program);
});

it('allows anything on m in an anonymous function in a class method', () => {
program.setFile('source/main.bs', `
class SomeKlass
function test()
stub = function()
m.something = true
end function
return stub
end function
end class
`);
program.validate();
expectZeroDiagnostics(program);
});
});

describe('itemCannotBeUsedAsVariable', () => {
Expand Down

0 comments on commit 0b7f553

Please sign in to comment.