Skip to content

Commit

Permalink
Partial fix for #133 ("treat X as block-scoped" will now help)
Browse files Browse the repository at this point in the history
  • Loading branch information
YellowAfterlife committed Oct 14, 2022
1 parent f3c02cb commit 3e333af
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/parsers/linter/GmlLinter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -601,19 +601,23 @@ class GmlLinter {
//
if (!skipIf(nk == KIdent)) break;
var varName = nextVal;
var allowTypeRedefinition = false;
if (mainKind != KGlobalVar && mainKind != KStatic) {
var lk = localKinds[varName];
if (mainKind != KVar || prefs.blockScopedVar) {
var lk = localKinds[varName];
if (lk != null && lk != KGhostVar) {
addWarning('Redefinition of a variable `$varName`');
} else {
allowTypeRedefinition = true;
var arr = localNamesPerDepth[oldDepth];
if (arr == null) {
arr = [];
localNamesPerDepth[oldDepth] = arr;
}
arr.push(varName);
}
} else if (lk == null || lk == KGhostVar) {
allowTypeRedefinition = true;
}
localKinds[varName] = mainKind;
}
Expand Down Expand Up @@ -667,7 +671,11 @@ class GmlLinter {
if (lastVarType == null) {
if (setLocalVars) typeInfo = "type " + varExprType.toString() + " (auto)";
imp.localTypes[varName] = varExprType;
} else if (!varExprType.equals(lastVarType)) {
}
else if (allowTypeRedefinition) {
imp.localTypes[varName] = varExprType;
}
else if (!varExprType.equals(lastVarType)) {
addWarning('Implicit redefinition of type for local variable $varName from '
+ lastVarType.toString() + " to " + varExprType.toString());
}
Expand Down
1 change: 1 addition & 0 deletions tests/TestGMEditGMS23/TestGMEditGMS23.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function v_constructor_function_redefinitions() constructor {
static f1 = function() {
let v = 0;
v += 1;
v += ""; ///want_warn
array_push(v, 1); ///want_warn
}
static f2 = function() {
let v = "hi!";
v += 1; ///want_warn
v += "";
array_push(v, 1); ///want_warn
}
static f3 = function() {
let v = [];
v += 1; ///want_warn
v += ""; ///want_warn
array_push(v, 1);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e333af

Please sign in to comment.