Diagnostic Messages
Certain constructs may be flagged by the engine as potentially
unintended or deprecated. In these cases, the engine will, by default,
emit a warning to the log file.
On occasion, these constructs are in fact intended by the script
author. In order to avoid unwanted warning messages hiding more important
messages, the engine supports selectively suppressing a warning category
for parts of a script.
Suppression and re-enablement is handled by the
#warning
directive. The directive must be placed on a separate line.
Warnings can be controlled using this syntax:
#warning {enable|disable} [warning_category [warning_category...]]
If no category is given, the engine will suppress or enable all messages,
including those that are not enabled by default. A category remains
disabled or enabled until the next directive that affects it, or until
the end of the script. A script linked to via the
#include
or #appendto
directives does not affect, and is itself not
affected by, the warning settings of the current script.
It is not an error to specify a category that does not exist; the
invalid category is simply ignored. No separate warning is emitted.
Warning Categories
The following warning categories currently exist:
Category | Description |
---|---|
invalid_escape_sequence |
The engine found an escape sequence inside a string that it
did not recognize.
"\p" |
invalid_hex_escape |
The engine found the start of a hexadecimal escape sequence
inside a string, but no hexadecimal digits followed it.
"\xGN" |
type_name_used_as_par_name |
A function parameter was declared without an explicit type
specification, but with a name that is the same as a built-in type.
func f(array)
This warning is not enabled by default.
¹
|
empty_parameter_in_call |
In a function call, a parameter was left empty. The engine is
passing
nil in its place.
CreateObject(Clonk,, 30, 100);
This warning is not enabled by default.
¹
|
empty_parameter_in_array |
In an array literal, an entry was left empty. The engine is
using
nil in its place.
[1, 2,, 3, 4]
This warning is not enabled by default.
¹
|
implicit_range_loop_var_decl |
The loop variable of a for-in loop was not declared either in the
loop header itself nor in the containing function. This is only
accepted for backwards compatibility and may be removed in a
future release. Explicitly declare the variable by adding the
var keyword.
func f() { for (i in [1, 2, 3]) { } } |
non_global_var_is_never_const |
A variable has been declared as
const , but is not
global. At this time, non-global variables are always mutable.
const local a = {} |
variable_shadows_variable |
The declaration of a variable uses the same name as a variable
in a greater scope. Changes to the shadowing variable will not
affect the shadowed variable.
static foo; func f() { var foo = 3; } |
redeclaration |
A variable has been redeclared in the same scope. Make sure
you do not accidentally overwrite values another part of the
code relies upon.
func f() { var i; var i; } |
variable_out_of_scope |
A variable has been used outside of the block it has been
declared in. This is accepted only for backwards compatibility
and may be removed in a future release.
func f(a) { i = 0; if (a) { var i = 1; } return i; } |
undeclared_varargs |
Use of
Par inside a function
implicitly declares it as using a variable number of arguments.
This is not immediately obvious to callers of the function, and
should be explicitly declared in the function signature by
adding a final ... parameter.
func f(a) { return Par(a); } // Better: func g(a, ...) { return Par(a); } |
arg_count_mismatch |
A function call passes more parameters than the function will
accept.
GetDir(0) |
arg_type_mismatch |
The parameter given in a function call is of a different type
than the called function expects. The call will likely fail at
runtime.
Sin("huh?") |
empty_if |
An
if conditional is controlling an empty statement.
Use the empty block {} if this is intentional, or
remove the conditional entirely.
if (true); |
suspicious_assignment |
An assignment was found where an expression was expected. While
an assignment returns its own value, usually a comparison was
intended instead.
if (a = b + 1) { /* Do something */}
If the assignment is intentional, make this more obvious by
extracting it to a separate statement, or explicitly handle the
boolean conversion by adding a comparison operator.
|
Examples
func f(string s) { Sin(s); // WARNING: parameter 0 of call to 'Sin' passes string (int expected) #warning disable arg_type_mismatch Sin(s); #warning enable arg_type_mismatch Sin(s); // WARNING: parameter 0 of call to 'Sin' passes string (int expected) }