| 13351 | |
| 13352 | |
| 13353 | void Script::WarnUnassignedVar(Var *var, Line *aLine) |
| 13354 | { |
| 13355 | auto warnMode = g_Warn_VarUnset; |
| 13356 | if (!warnMode) |
| 13357 | return; |
| 13358 | |
| 13359 | // Currently only the first reference to each var generates a warning even when using |
| 13360 | // StdOut/OutputDebug, since MarkAlreadyWarned() is used to suppress warnings for any |
| 13361 | // var which is checked with IsSet(). |
| 13362 | //if (warnMode == WARNMODE_MSGBOX) |
| 13363 | { |
| 13364 | // The following check uses a flag separate to IsAssignedSomewhere() because setting |
| 13365 | // that one for the purpose of preventing multiple MsgBoxes would cause other callers |
| 13366 | // of IsAssignedSomewhere() to get the wrong result if a MsgBox has been shown. |
| 13367 | if (var->HasAlreadyWarned()) |
| 13368 | return; |
| 13369 | var->MarkAlreadyWarned(); |
| 13370 | } |
| 13371 | |
| 13372 | bool isUndeclaredLocal = (var->Scope() & (VAR_LOCAL | VAR_DECLARED)) == VAR_LOCAL; |
| 13373 | LPCTSTR sameNameAsGlobal = isUndeclaredLocal && FindGlobalVar(var->mName) ? _T(" (same name as a global)") : _T(""); |
| 13374 | TCHAR buf[DIALOG_TITLE_SIZE]; |
| 13375 | sntprintf(buf, _countof(buf), _T("%s %s%s"), Var::DeclarationType(var->Scope()), var->mName, sameNameAsGlobal); |
| 13376 | ScriptWarning(warnMode, WARNING_ALWAYS_UNSET_VARIABLE, buf, aLine); |
| 13377 | } |
| 13378 | |
| 13379 | |
| 13380 |
no test coverage detected