diff --git a/compiler/semantics.cpp b/compiler/semantics.cpp index 732d7927..592e3fdd 100644 --- a/compiler/semantics.cpp +++ b/compiler/semantics.cpp @@ -2355,9 +2355,14 @@ bool Semantics::TestSymbol(Decl* sym, bool testconst) { default: { auto var = sym->as(); /* a variable */ - if (!var->is_used() && !var->is_public()) { - report(sym, 203) << sym->name(); /* symbol isn't used (and not public) */ - } else if (!var->is_public() && !var->is_read()) { + + // We ignore variables that are marked as public or stock. + if (var->is_public() || var->is_stock()) + break; + + if (!var->is_used()) { + report(sym, 203) << sym->name(); /* symbol isn't used (and not public/stock) */ + } else if (!var->is_read()) { report(sym, 204) << sym->name(); /* value assigned to symbol is never used */ } } diff --git a/tests/compile-only/ok-stock-array-unused b/tests/compile-only/ok-stock-array-unused new file mode 100644 index 00000000..a347a87f --- /dev/null +++ b/tests/compile-only/ok-stock-array-unused @@ -0,0 +1,9 @@ +// warnings_are_errors: true + +stock const char messages[2][] = +{ + "first", + "second" +}; + +public void main() {} diff --git a/tests/compile-only/ok-stock-var-unused.sp b/tests/compile-only/ok-stock-var-unused.sp new file mode 100644 index 00000000..37a416f9 --- /dev/null +++ b/tests/compile-only/ok-stock-var-unused.sp @@ -0,0 +1,5 @@ +// warnings_are_errors: true + +stock const int X = 1; + +public void main() {}