Commit graph

269 commits

Author SHA1 Message Date
Jason Yundt
1cc7e7ec33 Improve autoload inheritance error message
Autoloaded scripts should always inherit from Node. When you run a
project that tries to autoload a script which doesn’t inherit from Node,
then Godot gives an error.

Before this change, the error said “Script does not inherit a Node”.
That error message is a little bit misleading. If a class inherits a
Node, then one of its superclasses has a Node. If a class inherits
_from_ Node, then one of its superclasses is Node. This change corrects
that mistake.

Fixes #59884.
2022-04-04 15:51:02 -04:00
Rémi Verschelde
f8ab79e68a Zero initialize all pointer class and struct members
This prevents the pitfall of UB when checking if they have been
assigned something valid by comparing to nullptr.
2022-04-04 19:49:50 +02:00
cdemirer
3c5b9d1be3 Fix issues with multiple bind patterns in match statement 2022-04-04 15:47:08 +08:00
reduz
21637dfc25 Remove VARIANT_ARG* macros
* Very old macros from the time Godot was created.
* Limited arguments to 5 (then later changed to 8) in many places.
* They were replaced by C++11 Variadic Templates.
* Renamed methods that take argument pointers to have a "p" suffix. This was used in some places and not in others, so made it standard.
* Also added a dereference check for Variant*. Helped catch a couple of bugs.
2022-03-09 18:39:13 +01:00
George Marques
1ebcb58e69
GDScript: Check if method signature matches the parent
To guarantee polymorphism, a method signature must be compatible with
the parent. This checks if:

1. Return type is the same.
2. The subclass method takes at least the same amount of parameters.
3. The matching parameters have the same type.
4. If the subclass takes more parameters, all of the extra ones have a
default value.
5. If the superclass has default values, so must have the subclass.

There's a few test cases to ensure this holds up.
2022-03-06 11:16:20 -03:00
strank
7d48afa96d Add test cases for accessing parent elements from child class 2022-03-04 12:41:20 -05:00
cdemirer
3afe50c2fa Fix logic errors in match-statement Array & Dictionary Patterns 2022-03-02 19:05:18 +08:00
Rémi Verschelde
317cd0b19a
Refactor some object type checking code with cast_to
Less stringly typed logic, and less String allocations and comparisons.
2022-02-08 10:08:34 +01:00
Rémi Verschelde
89eb6d372d
Merge pull request #57591 from vnen/gdscript-enum-fixes 2022-02-04 13:49:15 +01:00
George Marques
ceafdf347e
GDScript: Treat enum values as int and enum types as dictionary
Since enums resolve to a dictionary at runtime, calling dictionary
methods on an enum type is a valid use case. This ensures this is true
by adding test cases. This also makes enum values be treated as ints
when used in operations.
2022-02-03 13:32:34 -03:00
George Marques
b013c0d544
GDScript: Allow tests to run on release builds
- Fix compilation issues by disabling warnings on release builds. This
  also strips warnings from expected result before the comparison to
  avoid false mismatches.
- Add a `#debug-only` flag to tests. Must be the first line of the test
  script. Those won't run with release builds. Can be used for test
  cases that rely on checks only available on debug builds.
2022-02-03 13:32:33 -03:00
George Marques
ad6e2e82a9
GDScript: Consolidate behavior for assigning enum types
This makes sure that assigning values to enum-typed variables are
consistent. Same enum is always valid, different enum is always
invalid (without casting) and assigning `int` creates a warning
if there is no casting.

There are new test cases to ensure this behavior doesn't break in
the future.
2022-02-03 13:32:16 -03:00
Rémi Verschelde
e1706be25d
Merge pull request #57052 from KoBeWi/nosort 2022-01-23 00:27:01 +01:00
Rémi Verschelde
182a36db47
Merge pull request #55214 from Scony/fix-gdscript-crash-2
Fix GDScript parser crash on 'dollar mixed with assignment' expression
2022-01-22 20:30:54 +01:00
kobewi
f056cb8ebc Don't sort printed Dictionary 2022-01-22 13:45:02 +01:00
strank
960a26f6c0 GDScript: Fix parsing default parameter values from function calls 2022-01-13 19:28:39 -05:00
bruvzg
c69e0d16bc
Fix multiple missing UTF-8 decoding. 2022-01-06 14:35:22 +02:00
Rémi Verschelde
6d4ed65f4c
Merge pull request #56483 from vnen/gdscript-warning-annotation
Add annotation to ignore warnings
2022-01-05 09:05:56 +01:00
George Marques
fd643c903d
GDScript: Add annotation to ignore warnings 2022-01-04 09:32:43 -03:00
Rémi Verschelde
fe52458154
Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-03 21:27:34 +01:00
luz paz
a124f1effe Fix various typos
Found via ` codespell -q 3 -S ./thirdparty,*.po,./DONORS.md -L ackward,ang,ans,ba,beng,cas,childs,childrens,dof,doubleclick,expct,fave,findn,gird,hist,inout,leapyear,lod,nd,numer,ois,ony,paket,seeked,sinc,switchs,te,uint,varn`
Update editor/import/resource_importer_layered_texture.cpp

Co-authored-by: Raul Santos <raulsntos@gmail.com>
Update doc/classes/TileSetScenesCollectionSource.xml

Co-authored-by: Raul Santos <raulsntos@gmail.com>
Update scene/gui/graph_edit.cpp

Co-authored-by: Raul Santos <raulsntos@gmail.com>
Update scene/resources/animation.cpp

Co-authored-by: Raul Santos <raulsntos@gmail.com>
Update scene/resources/animation.cpp

Co-authored-by: Raul Santos <raulsntos@gmail.com>
Update scene/resources/animation.cpp

Co-authored-by: Raul Santos <raulsntos@gmail.com>
Update scene/gui/rich_text_label.cpp

Co-authored-by: Raul Santos <raulsntos@gmail.com>
Revert previously committed change
2022-01-02 01:03:58 -05:00
Yuri Roubinsky
566895732c Fix shadowed global identifier warning duplication 2021-12-13 11:54:23 +03:00
Nathan Franke
49403cbfa0
Replace String comparisons with "", String() to is_empty()
Also:
- Adds two stress tests to test_string.h
- Changes to .empty() on std::strings
2021-12-09 04:48:38 -06:00
Pawel Lampe
1a15a3adf6 Fix GDScript parser crash on 'dollar mixed with assignment' expression
fixes #53696
2021-11-21 21:18:46 +01:00
Pawel Lampe
86c0e38e8f Fix 'unreachable-code' false-positive, fixes #55154 2021-11-21 15:53:21 +01:00
Yuri Roubinsky
3396b25489 Allow using built-in names for variables, push warnings instead 2021-11-13 21:47:24 +03:00
Max Hilbrunner
626ca50676 Improve GDScript indentation error message 2021-10-28 13:01:53 +02:00
reduz
d03b7fbe09 Refactored Node3D rotation modes
* Made the Basis euler orders indexed via enum.
* Node3D has a new rotation_order property to choose Euler rotation order.
* Node3D has also a rotation_mode property to choose between Euler, Quaternion and Basis

Exposing these modes as well as the order makes Godot a lot friendlier for animators, which can choose the best way to interpolate rotations.
The new *Basis* mode makes the (exposed) transform property obsolete, so it was removed (can still be accessed by code of course).
2021-10-25 14:34:00 -03:00
Rémi Verschelde
4387f9645b
Merge pull request #52940 from groud/toast_notification 2021-10-19 09:57:13 +02:00
Rémi Verschelde
3f888966c0
Merge pull request #53843 from vnen/gdscript-typed-array-subscript-constant
Fix inferred typed array marked as constant
2021-10-15 16:49:29 +02:00
George Marques
540821a264
GDScript: Fix inferred typed array marked as constant 2021-10-15 10:40:50 -03:00
George Marques
056a54db7b
GDScript: Properly return value with await on non-coroutine
If the keyword `await` is used without a coroutine, it should still
return the value synchronally.
2021-10-14 19:58:10 -03:00
Rémi Verschelde
472ff40f71
Merge pull request #53807 from vnen/dont-share-arrays-and-dicts 2021-10-14 20:42:22 +02:00
George Marques
4c14051b3f
Zero Dictionary and Array variants when changing type with reset
So they don't reference to the old values anymore and instead refer to
a new value.
2021-10-14 11:22:17 -03:00
George Marques
bf322bacdd
Merge pull request #53726 from briansemrau/gd-outer-class
GDScript 2.0: Access outer scope classes
2021-10-14 10:12:52 -03:00
Gilles Roudière
0587e5e018 Implement toast notifications in the editor 2021-10-14 13:30:54 +02:00
Brian Semrau
0ff0f64cd4 GDScript: Access outer scope classes 2021-10-13 22:39:12 -04:00
Rémi Verschelde
e4288bf728
Merge pull request #53720 from vnen/gdscript-typed-array-custom-class 2021-10-12 16:51:50 +02:00
George Marques
34288b24a6
GDScript: Fix typed array with custom classes 2021-10-12 10:41:04 -03:00
George Marques
45f546c1d8
GDScript: Make setter parameter type same as variable type 2021-10-12 09:39:23 -03:00
George Marques
f930d54140
Merge pull request #53103 from ZuBsPaCe/gdscript-analyze-properties-fix
GDScript: Report property type errors
2021-10-11 11:01:39 -03:00
mashumafi
575d4e00b6 Enhance and cleanup stringify for Vector 2021-10-09 06:19:25 +00:00
ZuBsPaCe
551ceb590b GDScript: Report property type errors
Inline getters & setters are now FunctionNodes.
Their names are set in the parser, not in the compiler.
GDScript-Analyzer will now run through getter and setter.
Also report wrong type or signature errors regarding getset properties.
Added GDScript tests for getters and setters.
#53102
2021-10-08 22:06:15 +02:00
Rémi Verschelde
49e7e049ab
Merge pull request #53422 from KoBeWi/add_LUA_to_Godot 2021-10-07 23:37:37 +02:00
Rémi Verschelde
98b81ad35c
Merge pull request #53479 from vnen/gdscript-subscript-object-self 2021-10-06 19:48:23 +02:00
George Marques
1f55bd190c
GDScript: Allow subscript on self and object types 2021-10-06 12:01:34 -03:00
George Marques
6bdb28f5e4
GDScript: Avoid hard errors on inferred types
Since inference isn't always correct, they are now treated as unsafe
instead of errors.

This also removes inferred type when a variable is reassigned. Since
it's not aware of branching, the types might become invalid in a later
context.
2021-10-06 11:42:19 -03:00
George Marques
d6c799006a
GDScript: Make all warnings enabled in test generation
The test generation doesn't initialize the language (since it's already
initialized in main), but it still needs the warning enabled so it
matches the actual tests.
2021-10-06 11:39:00 -03:00
kobewi
9e5fdbc79d Fix LUA-style assignment in Dictionary 2021-10-05 12:17:13 +02:00
George Marques
84956fee4b
GDScript: Fix member assignment with operation
It was wrongly updating the assigned value with the result of the
operation.
2021-10-04 14:09:54 -03:00
Lightning_A
c63b18507d Use range iterators for Map 2021-09-30 15:09:12 -06:00
Rémi Verschelde
27d4e2f09f
Merge pull request #53216 from vnen/gdscript-builtin-type-not-id 2021-09-29 17:04:24 +02:00
George Marques
72c07708e8
GDScript: Don't allow builtin type names as identifiers 2021-09-29 11:23:16 -03:00
George Marques
991f4d8527
GDScript: Fix assignment with operation for properties 2021-09-29 10:54:16 -03:00
Rémi Verschelde
679f70c1e1
Merge pull request #52906 from vnen/gdscript-show-error-on-yield 2021-09-21 20:36:39 +02:00
Rémi Verschelde
b3b4860d2e
Merge pull request #52905 from vnen/gdscript-single-line-declaration 2021-09-21 20:35:36 +02:00
George Marques
262d6c6bef
GDScript: Show specific error when "yield" is used
To help people porting code, it gives a hint to use "await" instead of a
generic error.
2021-09-21 14:38:14 -03:00
George Marques
e5ebc9710d
GDScript: Allow classes declaration to be done in single line
Incidentally, allow multiple statements in single line functions when
using semicolon as a terminator.
2021-09-21 14:14:46 -03:00
George Marques
bab0afc821
GDScript: Allow multiple lines in signal parameters declaration 2021-09-21 13:40:39 -03:00
Rémi Verschelde
82c12060b2
Merge pull request #52718 from Calinou/gdscript-add-integration-tests-2 2021-09-21 14:13:24 +02:00
Rémi Verschelde
424ddcba37
Merge pull request #52792 from vnen/gdscript-subscript-missing-index 2021-09-17 20:16:29 +02:00
Rémi Verschelde
7762e8b1c1
Merge pull request #52788 from vnen/gdscript-compare-with-null 2021-09-17 19:35:55 +02:00
George Marques
651319de11
GDScript: Properly catch error when missing index in subscript 2021-09-17 14:31:51 -03:00
George Marques
455e142d37
Allow comparing equality between builtin types and null 2021-09-17 12:33:52 -03:00
George Marques
4e69341c01
GDScript: Avoid inferred types from giving hard errors 2021-09-17 11:52:30 -03:00
Hugo Locurcio
c6ca09dc6f
Add more integration tests to the GDScript test suite
This also fixes a typo in the `bitwise_float_right_operand.gd` test.
2021-09-15 19:57:39 +02:00
Rémi Verschelde
a4187c9235
Merge pull request #52706 from vnen/gdscript-ternary-operator-crash
GDScript: Show error when missing expression after ternary else
2021-09-15 17:20:52 +02:00
George Marques
107af38fd1
GDScript: Show error when missing expression after ternary else 2021-09-15 11:43:36 -03:00
George Marques
d49046938a
GDScript: Show error on unary operators without argument 2021-09-15 11:08:59 -03:00
George Marques
5d31ce4b16
GDScript: Allow string keys on Lua-style dictionaries
Which is useful when the key isn't a valid identifier, such as keys with
spaces or numeric keys.
2021-09-15 09:56:24 -03:00
Hugo Locurcio
c0083c0f90
Add dozens of new integration tests to the GDScript test suite
This also ignores `.out` files in the file format static checks.
2021-09-14 18:42:08 +02:00
ThreeRhinosInAnElephantCostume
2c71134aa4 Fix an undefined behaviour 2021-09-13 22:59:28 +02:00
George Marques
e9186cfebf
Fix GDScript test cases 2021-09-13 15:02:01 -03:00
Rémi Verschelde
0c2ab55a58
Merge pull request #52100 from vnen/gdscript-access-outer-constants
GDScript: Allow access to outer constant and enum values
2021-09-13 18:04:35 +02:00
Rémi Verschelde
4059cf2f02
Merge pull request #52068 from ThreeRhinosInAnElephantCostume/fixgdscript
Fix parse error on statement-less files with only newlines, add a warning for empty files.
2021-09-13 17:30:31 +02:00
ThreeRhinosInAnElephantCostume
e99730340b Fix error on parsing statement-less GDScript files,
add an empty file warning,
add relevant tests.
2021-09-11 20:38:15 +02:00
ZuBsPaCe
1d1aa7a02f GDScript: Removed spurious UNASSIGNED_VARIABLE warning for locals
Variable->assignment needs to be incremented when assigned a value.
Also fixed and improved unit test 'variable_declaration.gd'.
Fixes #52551
2021-09-10 22:26:50 +02:00
kobewi
c7452a9940 Fix crash with consecutive commas in Dictionary 2021-09-10 15:38:24 +02:00
George Marques
1234c2bdd9
Merge pull request #52081 from ThreeRhinosInAnElephantCostume/fixmatchfreeze
Fix gdscript pattern matching expressions
2021-09-10 09:28:18 -03:00
ThreeRhinosInAnElephantCostume
15ccd83ada Added tests for expression matching 2021-09-03 06:59:13 +02:00
Max Hilbrunner
5d2c4faa89
Merge pull request #52164 from mhilbrunner/gd-style-fixup
GDScript test style fix
2021-08-28 20:16:17 +02:00
K. S. Ernest (iFire) Lee
d04aa9a114
Merge pull request #52122 from V-Sekai/autoload_list
Use sorted map for autoloads in ProjectSettings to preserve order.
2021-08-27 14:41:40 -07:00
Max Hilbrunner
f126634434 GDScript test style fix 2021-08-27 21:11:46 +02:00
Max Hilbrunner
4e67e9bca6
Merge pull request #52090 from balloonpopper/bug52060
Correct null and boolean values being capitalised by the str command
2021-08-27 21:05:47 +02:00
Hugo Locurcio
33773a24dc
Merge pull request #52105 from ldmnt/master 2021-08-27 19:28:59 +02:00
Lyuma
31f790299c Use OrderedHashMap for autoloads to preserve order 2021-08-26 21:55:26 -07:00
Balloonpopper
4fae7ae9dc Correct null and boolean values being capitalised by the str command 2021-08-26 17:11:34 +10:00
Louis Dumont
79578a5625 Fixed crash when parsing an empty assignment.
Resolves #51620.
2021-08-25 18:48:08 +02:00
Hugo Locurcio
9c2ec6e697
Add a README to link to the GDScript integration tests documentation
This makes the documentation about creating and running GDScript
integration tests more discoverable.
2021-08-25 16:51:28 +02:00
George Marques
4918df4527
GDScript: Allow access to outer constant and enum values 2021-08-24 14:45:51 -03:00
George Marques
1c8b076502
GDScript: Fix calling builtin static functions 2021-08-18 18:58:41 -03:00
George Marques
2ba4ee9198
GDScript: Fix inner classes and preloaded scripts as types 2021-08-18 18:56:21 -03:00
Paulb23
bcfc591f86 Reorganise text editor settings 2021-08-16 17:18:49 +01:00
Aaron Franke
4e6efd1b07
Use C++ iterators for Lists in many situations 2021-07-23 17:38:28 -04:00
Lightning_A
e28fd07b2b Rename instance()->instantiate() when it's a verb 2021-06-19 20:49:18 -06:00
Pedro J. Estébanez
04688b92ff Rename Reference to RefCounted 2021-06-11 18:48:42 +02:00
Rémi Verschelde
9e328bb5b7
Core: Move DirAccess and FileAccess to core/io
File handling APIs are typically considered part of I/O, and we did have most
`FileAccess` implementations in `core/io` already.
2021-06-11 14:52:39 +02:00
Rémi Verschelde
364ea7f280
Merge pull request #49114 from vnen/gdscript-fix-self-function-type-check
GDScript: Fix function signature check for self calls
2021-05-26 20:59:17 +02:00
George Marques
a23fc45727
GDScript: Fix function signature check for self calls 2021-05-26 15:33:18 -03:00
Marcel Admiraal
da5d7db610 Rename File::get_len() get_length() 2021-05-25 11:54:28 +01:00
George Marques
ea44744e2d
Make Callable not crash on call when the object has been freed
Also add a GDScript test for this case.
2021-05-24 14:23:02 -03:00
George Marques
ffdb3cccd2
GDScript: Fix error handler for tests
This changes the error message to be more clear on the output files and
also fixes an issue with the relative path of the offending file that
was not trimmed correctly.
2021-05-24 14:17:20 -03:00
Rémi Verschelde
169268ae20
Merge pull request #48657 from Calinou/test-add-gdscript
Add a unit test suite for GDScript
2021-05-19 20:49:03 +02:00
Pedro J. Estébanez
469fa47e06
Make all file access 64-bit (uint64_t)
This changes the types of a big number of variables.

General rules:
- Using `uint64_t` in general. We also considered `int64_t` but eventually
  settled on keeping it unsigned, which is also closer to what one would expect
  with `size_t`/`off_t`.
- We only keep `int64_t` for `seek_end` (takes a negative offset from the end)
  and for the `Variant` bindings, since `Variant::INT` is `int64_t`. This means
  we only need to guard against passing negative values in `core_bind.cpp`.
- Using `uint32_t` integers for concepts not needing such a huge range, like
  pages, blocks, etc.

In addition:
- Improve usage of integer types in some related places; namely, `DirAccess`,
  core binds.

Note:
- On Windows, `_ftelli64` reports invalid values when using 32-bit MinGW with
  version < 8.0. This was an upstream bug fixed in 8.0. It breaks support for
  big files on 32-bit Windows builds made with that toolchain. We might add a
  workaround.

Fixes #44363.
Fixes godotengine/godot-proposals#400.

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
2021-05-17 15:06:19 +02:00
Hugo Locurcio
6c528e4fae
Add a unit test suite for GDScript
This tests run-time script loading.
2021-05-12 16:20:57 +02:00
Rémi Verschelde
4e06731346
Merge pull request #47958 from Xrayez/gdscript-rename-test-scripts
Rename GDScript test script filenames to use `snake_case`
2021-05-03 15:44:46 +02:00
George Marques
3155368093
GDScript: Add lambdas to the type analyzer
- Lambdas are always callables (no specific signature match).
- Captures from the current context are evaluated.
2021-04-28 10:56:16 -03:00
George Marques
c6e66a43b0
GDScript: Add lambda syntax parsing
Lambda syntax is the same as a the function syntax (using the same
`func` keyword) except that the name is optional and it can be embedded
anywhere an expression is expected. E.g.:

    func _ready():
        var my_lambda = func(x):
            print(x)
        my_lambda.call("hello")
2021-04-28 10:56:16 -03:00
Hugo Locurcio
5d124c4a8f
Remove uses of auto for better readability and online code reviews
The current code style guidelines forbid the use of `auto`.

Some uses of `auto` are still present, such as in UWP code (which
can't be currently tested) and macros (where removing `auto` isn't
easy).
2021-04-26 14:59:28 +02:00
Andrii Doroshenko (Xrayez)
1e26bf23c2 Rename GDScript test script filenames to use snake_case 2021-04-16 22:16:19 +03:00
George Marques
5f77f38573
Add runner for GDScript testing
This is meant for testing the GDScript implementation, not for testing
user scripts nor testing the engine using scripts.

Tests consists in a GDScript file and a .out file with the expected
output. The .out file format is: expected status (based on the enum
GDScriptTest::TestStatus) on the first line, followed by either an error
message or the resulting output. Warnings are added after the first
line, before the output (or compiler errors) if the parser pass without
any error.

The test script must have a function called `test()` which takes no
argument. Such function will be called by the test runner. The test
should not have any dependency unless it's part of the test too. Global
classes (using `class_name`) are registered before the runner starts, so
those should work if needed.

Use the command `godot --gdscript-generate-tests
godot-source/modules/gdscript/tests/scripts` to update the .out files
with the current output (make sure the output are the expected values
before committing).

The tests themselves are part of the doctest suite so those can be
executed with `godot --test`.

Co-authored-by: Andrii Doroshenko (Xrayez) <xrayez@gmail.com>
2021-04-08 09:34:59 -03:00
Gordon MacPherson
6b4ff3b44b Add unit tests for export templates 2021-03-22 18:57:08 +00:00
Rémi Verschelde
b5334d14f7
Update copyright statements to 2021
Happy new year to the wonderful Godot community!

2020 has been a tough year for most of us personally, but a good year for
Godot development nonetheless with a huge amount of work done towards Godot
4.0 and great improvements backported to the long-lived 3.2 branch.

We've had close to 400 contributors to engine code this year, authoring near
7,000 commit! (And that's only for the `master` branch and for the engine code,
there's a lot more when counting docs, demos and other first-party repos.)

Here's to a great year 2021 for all Godot users 🎆
2021-01-01 20:19:21 +01:00
Marcel Admiraal
5b937d493f Rename empty() to is_empty() 2020-12-28 10:39:56 +00:00
Aaron Franke
02161aad5a
Remove empty lines around braces with the formatting script 2020-11-16 23:38:11 -05:00
reduz
127458ed17 Reorganized core/ directory, it was too fatty already
-Removed FuncRef, since Callable makes it obsolete
-Removed int_types.h as its obsolete in c++11+
-Changed color names code
2020-11-07 20:17:12 -03:00
George Marques
48b91b900d
GDScript: Add initialization for the language before debug tests
This ensures that the tests will use a full environment with correct
settings so global classes and autoloads can be properly found.
2020-10-20 10:07:03 -03:00
Andrii Doroshenko (Xrayez)
0cc05c5a31 Register GDScript test tools as test commands to run via command-line 2020-09-02 01:43:26 +03:00
Andrii Doroshenko (Xrayez)
6b7e50ab34 Move GDScript tests to respective folder under modules 2020-09-02 01:09:32 +03:00