2020-05-02 00:14:56 +02:00
/**************************************************************************/
/* gdscript_warning.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
2022-07-23 23:41:51 +02:00
# ifndef GDSCRIPT_WARNING_H
# define GDSCRIPT_WARNING_H
2020-05-02 00:14:56 +02:00
# ifdef DEBUG_ENABLED
2022-03-23 03:44:30 +01:00
# include "core/object/object.h"
2020-11-07 23:33:38 +01:00
# include "core/string/ustring.h"
# include "core/templates/vector.h"
2020-05-02 00:14:56 +02:00
class GDScriptWarning {
public :
2022-03-23 03:44:30 +01:00
enum WarnLevel {
IGNORE ,
WARN ,
ERROR
} ;
2020-05-02 00:14:56 +02:00
enum Code {
2020-06-12 00:31:28 +02:00
UNASSIGNED_VARIABLE , // Variable used but never assigned.
UNASSIGNED_VARIABLE_OP_ASSIGN , // Variable never assigned but used in an assignment operation (+=, *=, etc).
UNUSED_VARIABLE , // Local variable is declared but never used.
UNUSED_LOCAL_CONSTANT , // Local constant is declared but never used.
2024-02-28 15:23:11 +01:00
UNUSED_PRIVATE_CLASS_VARIABLE , // Class variable is declared private ("_" prefix) but never used in the class.
2020-06-12 00:31:28 +02:00
UNUSED_PARAMETER , // Function parameter is never used.
2024-02-28 15:23:11 +01:00
UNUSED_SIGNAL , // Signal is defined but never explicitly used in the class.
2023-04-28 17:20:41 +02:00
SHADOWED_VARIABLE , // Variable name shadowed by other variable in same class.
SHADOWED_VARIABLE_BASE_CLASS , // Variable name shadowed by other variable in some base class.
SHADOWED_GLOBAL_IDENTIFIER , // A global class or function has the same name as variable.
2020-06-12 00:31:28 +02:00
UNREACHABLE_CODE , // Code after a return statement.
UNREACHABLE_PATTERN , // Pattern in a match statement after a catch all pattern (wildcard or bind).
STANDALONE_EXPRESSION , // Expression not assigned to a variable.
2023-04-28 17:20:41 +02:00
STANDALONE_TERNARY , // Return value of ternary expression is discarded.
2020-06-12 00:31:28 +02:00
INCOMPATIBLE_TERNARY , // Possible values of a ternary if are not mutually compatible.
2023-09-22 19:57:24 +02:00
UNTYPED_DECLARATION , // Variable/parameter/function has no static type, explicitly specified or implicitly inferred.
INFERRED_DECLARATION , // Variable/constant/parameter has an implicitly inferred static type.
2020-06-12 00:31:28 +02:00
UNSAFE_PROPERTY_ACCESS , // Property not found in the detected type (but can be in subtypes).
UNSAFE_METHOD_ACCESS , // Function not found in the detected type (but can be in subtypes).
2023-10-27 10:08:54 +02:00
UNSAFE_CAST , // Casting a `Variant` value to non-`Variant`.
2023-04-28 17:20:41 +02:00
UNSAFE_CALL_ARGUMENT , // Function call argument is of a supertype of the required type.
2023-01-27 21:54:07 +01:00
UNSAFE_VOID_RETURN , // Function returns void but returned a call to a function that can't be type checked.
2023-04-28 17:20:41 +02:00
RETURN_VALUE_DISCARDED , // Function call returns something but the value isn't used.
STATIC_CALLED_ON_INSTANCE , // A static method was called on an instance of a class instead of on the class itself.
REDUNDANT_STATIC_UNLOAD , // The `@static_unload` annotation is used but the class does not have static data.
REDUNDANT_AWAIT , // await is used but expression is synchronous (not a signal nor a coroutine).
2020-06-12 00:31:28 +02:00
ASSERT_ALWAYS_TRUE , // Expression for assert argument is always true.
ASSERT_ALWAYS_FALSE , // Expression for assert argument is always false.
2023-04-28 17:20:41 +02:00
INTEGER_DIVISION , // Integer divide by integer, decimal part is discarded.
NARROWING_CONVERSION , // Float value into an integer slot, precision is lost.
2023-01-22 09:32:05 +01:00
INT_AS_ENUM_WITHOUT_CAST , // An integer value was used as an enum value without casting.
INT_AS_ENUM_WITHOUT_MATCH , // An integer value was used as an enum value without matching enum member.
2023-04-28 17:20:41 +02:00
EMPTY_FILE , // A script file is empty.
DEPRECATED_KEYWORD , // The keyword is deprecated and should be replaced.
RENAMED_IN_GODOT_4_HINT , // A variable or function that could not be found has been renamed in Godot 4.
2023-01-19 02:56:00 +01:00
CONFUSABLE_IDENTIFIER , // The identifier contains misleading characters that can be confused. E.g. "usе r" (has Cyrillic "е " instead of Latin "e").
2023-07-25 13:21:49 +02:00
CONFUSABLE_LOCAL_DECLARATION , // The parent block declares an identifier with the same name below.
CONFUSABLE_LOCAL_USAGE , // The identifier will be shadowed below in the block.
2023-02-02 15:57:22 +01:00
INFERENCE_ON_VARIANT , // The declaration uses type inference but the value is typed as Variant.
NATIVE_METHOD_OVERRIDE , // The script method overrides a native one, this may not work as intended.
GET_NODE_DEFAULT_WITHOUT_ONREADY , // A class variable uses `get_node()` (or the `$` notation) as its default value, but does not use the @onready annotation.
ONREADY_WITH_EXPORT , // The `@onready` annotation will set the value after `@export` which is likely not intended.
2024-02-28 15:23:11 +01:00
# ifndef DISABLE_DEPRECATED
PROPERTY_USED_AS_FUNCTION , // Function not found, but there's a property with the same name.
CONSTANT_USED_AS_FUNCTION , // Function not found, but there's a constant with the same name.
FUNCTION_USED_AS_PROPERTY , // Property not found, but there's a function with the same name.
# endif
2020-05-02 00:14:56 +02:00
WARNING_MAX ,
} ;
2023-02-02 15:57:22 +01:00
constexpr static WarnLevel default_warning_levels [ ] = {
WARN , // UNASSIGNED_VARIABLE
WARN , // UNASSIGNED_VARIABLE_OP_ASSIGN
WARN , // UNUSED_VARIABLE
WARN , // UNUSED_LOCAL_CONSTANT
WARN , // UNUSED_PRIVATE_CLASS_VARIABLE
WARN , // UNUSED_PARAMETER
2023-04-28 17:20:41 +02:00
WARN , // UNUSED_SIGNAL
WARN , // SHADOWED_VARIABLE
WARN , // SHADOWED_VARIABLE_BASE_CLASS
WARN , // SHADOWED_GLOBAL_IDENTIFIER
2023-02-02 15:57:22 +01:00
WARN , // UNREACHABLE_CODE
WARN , // UNREACHABLE_PATTERN
WARN , // STANDALONE_EXPRESSION
2023-04-28 17:20:41 +02:00
WARN , // STANDALONE_TERNARY
2023-02-02 15:57:22 +01:00
WARN , // INCOMPATIBLE_TERNARY
2023-09-05 19:56:37 +02:00
IGNORE , // UNTYPED_DECLARATION // Static typing is optional, we don't want to spam warnings.
2023-09-22 19:57:24 +02:00
IGNORE , // INFERRED_DECLARATION // Static typing is optional, we don't want to spam warnings.
2023-02-02 15:57:22 +01:00
IGNORE , // UNSAFE_PROPERTY_ACCESS // Too common in untyped scenarios.
IGNORE , // UNSAFE_METHOD_ACCESS // Too common in untyped scenarios.
IGNORE , // UNSAFE_CAST // Too common in untyped scenarios.
IGNORE , // UNSAFE_CALL_ARGUMENT // Too common in untyped scenarios.
WARN , // UNSAFE_VOID_RETURN
2023-04-28 17:20:41 +02:00
IGNORE , // RETURN_VALUE_DISCARDED // Too spammy by default on common cases (connect, Tween, etc.).
WARN , // STATIC_CALLED_ON_INSTANCE
WARN , // REDUNDANT_STATIC_UNLOAD
WARN , // REDUNDANT_AWAIT
2023-02-02 15:57:22 +01:00
WARN , // ASSERT_ALWAYS_TRUE
WARN , // ASSERT_ALWAYS_FALSE
2023-04-28 17:20:41 +02:00
WARN , // INTEGER_DIVISION
WARN , // NARROWING_CONVERSION
2023-02-02 15:57:22 +01:00
WARN , // INT_AS_ENUM_WITHOUT_CAST
WARN , // INT_AS_ENUM_WITHOUT_MATCH
2023-04-28 17:20:41 +02:00
WARN , // EMPTY_FILE
WARN , // DEPRECATED_KEYWORD
WARN , // RENAMED_IN_GODOT_4_HINT
2023-02-02 15:57:22 +01:00
WARN , // CONFUSABLE_IDENTIFIER
2023-07-25 13:21:49 +02:00
WARN , // CONFUSABLE_LOCAL_DECLARATION
WARN , // CONFUSABLE_LOCAL_USAGE
2023-02-02 15:57:22 +01:00
ERROR , // INFERENCE_ON_VARIANT // Most likely done by accident, usually inference is trying for a particular type.
ERROR , // NATIVE_METHOD_OVERRIDE // May not work as expected.
ERROR , // GET_NODE_DEFAULT_WITHOUT_ONREADY // May not work as expected.
ERROR , // ONREADY_WITH_EXPORT // May not work as expected.
2024-02-28 15:23:11 +01:00
# ifndef DISABLE_DEPRECATED
WARN , // PROPERTY_USED_AS_FUNCTION
WARN , // CONSTANT_USED_AS_FUNCTION
WARN , // FUNCTION_USED_AS_PROPERTY
# endif
2023-02-02 15:57:22 +01:00
} ;
static_assert ( ( sizeof ( default_warning_levels ) / sizeof ( default_warning_levels [ 0 ] ) ) = = WARNING_MAX , " Amount of default levels does not match the amount of warnings. " ) ;
2020-05-02 00:14:56 +02:00
Code code = WARNING_MAX ;
2020-06-12 00:31:28 +02:00
int start_line = - 1 , end_line = - 1 ;
int leftmost_column = - 1 , rightmost_column = - 1 ;
2020-05-02 00:14:56 +02:00
Vector < String > symbols ;
String get_name ( ) const ;
String get_message ( ) const ;
2022-03-23 03:44:30 +01:00
static int get_default_value ( Code p_code ) ;
static PropertyInfo get_property_info ( Code p_code ) ;
2020-05-02 00:14:56 +02:00
static String get_name_from_code ( Code p_code ) ;
2022-03-23 03:44:30 +01:00
static String get_settings_path_from_code ( Code p_code ) ;
2020-05-02 00:14:56 +02:00
static Code get_code_from_name ( const String & p_name ) ;
} ;
# endif // DEBUG_ENABLED
2022-07-23 23:41:51 +02:00
# endif // GDSCRIPT_WARNING_H