Skip to content

Commit

Permalink
Add namespaces and super (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: Philippe Elsass <[email protected]>
  • Loading branch information
Philippe and philippe-elsass-deltatre authored May 13, 2021
1 parent fe6ca58 commit 4f48ec8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/plugins/trackCodeFlow/varTracking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BscFile, FunctionExpression, BsDiagnostic, Range, isForStatement, isForEachStatement, isIfStatement, isAssignmentStatement, Expression, isVariableExpression, isBinaryExpression, TokenKind, Scope, CallableContainerMap, DiagnosticSeverity, isLiteralInvalid, isWhileStatement } from 'brighterscript';
import { BscFile, FunctionExpression, BsDiagnostic, Range, isForStatement, isForEachStatement, isIfStatement, isAssignmentStatement, Expression, isVariableExpression, isBinaryExpression, TokenKind, Scope, CallableContainerMap, DiagnosticSeverity, isLiteralInvalid, isWhileStatement, isClassMethodStatement } from 'brighterscript';
import { LintState, StatementInfo, NarrowingInfo, VarInfo } from '.';
import { PluginContext } from '../../util';

Expand Down Expand Up @@ -51,6 +51,10 @@ export function createVarLinter(
args.set(name.toLowerCase(), { name: name, range: p.name.range, isParam: true, isUnsafe: false, isUsed: false });
});

if (isClassMethodStatement(fun.functionStatement)) {
args.set('super', { name: 'super', range: null, isParam: true, isUnsafe: false, isUsed: true });
}

function verifyVarCasing(curr: VarInfo, name: { text: string; range: Range }) {
if (curr && curr.name !== name.text) {
diagnostics.push({
Expand Down Expand Up @@ -353,9 +357,12 @@ function deferredVarLinter(
deferred: ValidationInfo[],
diagnostics: BsDiagnostic[]
) {
const namespaces = new Set<string>();
scope.getAllNamespaceStatements().forEach(ns => namespaces.add(ns.name.toLowerCase()));

deferred.forEach(({ kind, name, local, range }) => {
const key = name?.toLowerCase();
const hasCallable = key ? !!callables.has(key) : false;
const hasCallable = key ? callables.has(key) || namespaces.has(key) : false;
switch (kind) {
case ValidationKind.UninitializedVar:
if (!hasCallable) {
Expand Down
15 changes: 15 additions & 0 deletions test/project1/source/class-methods.bs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ class Bar

end class

class Baz extends Bar
sub new()
super()
print foo.ping()
end sub

override sub ok1(x)
super.ok1(x)
end sub
end class

function ping()
return "pong"
end function

end namespace

0 comments on commit 4f48ec8

Please sign in to comment.