Commit graph

200 commits

Author SHA1 Message Date
Yuri Roubinsky
566895732c Fix shadowed global identifier warning duplication 2021-12-13 11:54:23 +03:00
kobewi
4682f22293 Improve various texts 2021-11-23 12:20:57 +01:00
Benjamin Navarro
560d9a4cc0 Fix incorrect debug check for setters
the check read the return type of the setter, which doesn't exist and
lead to a segmentation fault. Now we check the first function parameter.
Probably a bad copy/paste of the getter case
2021-10-18 09:01:16 +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
84abb9a76c
GDScript: Fix typing for await expression
Don't grab the type of the awaited value unless it's constant (which
makes it synchronous) or call (which always use the proper return type).
2021-10-14 20:30:06 -03:00
George Marques
749d89ae38
GDScript: Remove error when coroutine is called without await
In the case the call happens as a statement, since the return value
isn't used in this case.
2021-10-14 20:12:01 -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
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
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
George Marques
3a856b4fcc
GDScript: Use getter return type for the property type
The PropertyInfo hints are more relevant for the inspector. The getter
return type is more reliable and less likely to be incorrect and it is
what's going to be called in the end.
2021-10-07 20:22:19 -03: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
7725ebf3d2
GDScript: Use path cache when checking preloaded scripts
The path itself might not always be set in some cases, especially when
the script is just created and is already in the resource cache. Using
get_path() in this case gets the correct resource path.

This also adds a null check for safety in case the path is incorrect or
missing, to avoid a crash in the engine.
2021-10-04 20:48:39 -03:00
Rémi Verschelde
4a4995524c
Merge pull request #53338 from briansemrau/gdscript-handle-for-with-null-list 2021-10-04 17:11:43 +02:00
kobewi
cb28469281 Allow void as return type for constructors 2021-10-03 21:16:54 +02:00
Brian Semrau
dc046e5cbe GDScript Check for null list in for loop 2021-10-02 13:53:56 -04:00
Lightning_A
c63b18507d Use range iterators for Map 2021-09-30 15:09:12 -06:00
Rémi Verschelde
d2b8560d7a
Revert "GdScript: Use reduced constant expression result when doing binary operations. Fixes #50293"
This reverts commit 6207708607.

It broke a GDScript test (which didn't exist back when the PR was made,
so was missed prior to the merge).

It choked on:
```
prints("a", test_instance.a, test_instance.a == Named.VALUE_A)
```
With:
```
Invalid operands "VALUE_A (enum value)" and "int" for "==" operator.
```
2021-09-30 18:57:59 +02:00
Rémi Verschelde
7f8e50801e
Merge pull request #51818 from MarianoGnu/gdscript2-enum-fixes 2021-09-30 18:35:49 +02:00
George Marques
72c07708e8
GDScript: Don't allow builtin type names as identifiers 2021-09-29 11:23:16 -03:00
George Marques
5107f9190b
GDScript: Remove conversion assign mistakenly done when unneeded 2021-09-21 11:58:57 -03:00
George Marques
b8fdeb6467
Merge pull request #51671 from RandomShaper/fix_gdscript_crash
Fix some GDScript bugs
2021-09-17 12:29:40 -03:00
George Marques
4e69341c01
GDScript: Avoid inferred types from giving hard errors 2021-09-17 11:52:30 -03:00
George Marques
a5c299630d
Merge pull request #50456 from Blackiris/fix-extends-parent-relative
Fix extends with relative path to parent script
2021-09-15 11:12:24 -03:00
Rémi Verschelde
c23823ac54
Merge pull request #52582 from jmb462/Prevent-non-explicit-inferring-parameter-from-null 2021-09-15 15:50:42 +02:00
Rémi Verschelde
45d9df2e63
Merge pull request #52632 from vnen/autoload-global-script-class-conflict
Disallow class names to be the same as global names
2021-09-13 21:10:50 +02: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
George Marques
2e5fa124f4
Disallow class names to be the same as global names
Also forbid autoloads to have the same name as global script class.
2021-09-13 10:51:29 -03:00
jmb462
b9219bedf7 Prevent non explicit inferring parameter from null 2021-09-11 21:11:10 +02:00
Pedro J. Estébanez
7c79e361f5 Fix parameter type resolution in GDScript 2021-09-11 11:35:25 +02:00
Pedro J. Estébanez
d72f12a561 Implement iterator variable typing in GDScript 2021-09-11 11:35:25 +02:00
George Marques
6da061faf5
Merge pull request #49897 from Blackiris/fix-dollar-point-crash-on-editor
Fix crash when writing $. in the editor
2021-09-10 10:55:11 -03:00
Julien Nguyen
a92d2c447b Fix extends with relative path to parent script 2021-09-05 00:11:04 +02:00
Max Hilbrunner
8c82e305ba
Merge pull request #52329 from ZuBsPaCe/gdscript-unused-private-class-variable-fix
GDScript: Fix for UNUSED_PRIVATE_CLASS_VARIABLE
2021-09-03 10:04:11 +02:00
ZuBsPaCe
c76ad6b158 GDScript: Count usages of member variables.
Otherwise private member variables will always lead to UNUSED_PRIVATE_CLASS_VARIABLE.
2021-09-03 07:44:46 +02:00
SaracenOne
84852585b9 Check for GDScript member and class naming conflicts in a variety of conditions. 2021-09-02 07:16:06 +01:00
Wilson E. Alvarez
d11c1afc04
Rename String::is_rel_path to String::is_relative_path 2021-08-29 20:41:29 -04:00
George Marques
4918df4527
GDScript: Allow access to outer constant and enum values 2021-08-24 14:45:51 -03:00
George Marques
2e84a46a0f
GDScript: Make singleton functions be seen as static
Since those can be called without an instance.
2021-08-20 10:52:58 -03:00
George Marques
1c8b076502
GDScript: Fix calling builtin static functions 2021-08-18 18:58:41 -03:00
George Marques
47545aeb1a
GDScript: Fix issue when calling new() on its own 2021-08-18 18:56:21 -03:00
George Marques
2ba4ee9198
GDScript: Fix inner classes and preloaded scripts as types 2021-08-18 18:56:21 -03:00
Mariano Suligoy
6207708607 GdScript: Use reduced constant expression result when doing binary operations. Fixes #50293 2021-08-18 09:19:09 -03:00
Mariano Suligoy
70c5feb32c Accept non unnamed enums as valid values for enums. Fixes #49357 2021-08-17 19:44:27 -03:00
Mariano Suligoy
7f37e2987a When analyzing GdScript sources, consider Enums as Dictionaries. Fixes #45558 2021-08-17 19:44:27 -03:00
Max Hilbrunner
5161c97c9c Remove underscore hacks
Way less cruft. :)

Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
2021-08-17 16:10:28 +02:00
Aaron Franke
4e6efd1b07
Use C++ iterators for Lists in many situations 2021-07-23 17:38:28 -04:00
Julien Nguyen
bf8795c7af Fix crash when writing $. in the editor 2021-07-08 20:49:57 +02:00
Lightning_A
e28fd07b2b Rename instance()->instantiate() when it's a verb 2021-06-19 20:49:18 -06:00
Rémi Verschelde
a9c53fa599
Merge pull request #49287 from reduz/expose-variant-internal-binders
Make some Variant internal functions public.
2021-06-19 01:11:03 +02:00
George Marques
c4fcc678df
Merge pull request #49449 from SpectralDragon/fix-enum-equal-operation
Fix equal operation for typed enums
2021-06-18 17:18:44 -03:00
George Marques
b5f1e88b2e
GDScript: Fix setting type of operator return value
Also write type adjust when needed for binary operators.
2021-06-18 13:09:35 -03: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
Владислав Прусаков
6449c5f246 Fix equal operation for typed enums 2021-06-09 02:52:21 +03:00
Marcel Admiraal
8acd13a456 Rename Quat to Quaternion 2021-06-04 18:14:32 +01:00
Aaron Franke
08a85352fb
Rename Variant TRANSFORM to TRANSFORM3D
Also _transform to _transform3d
2021-06-03 07:30:01 -04: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
George Marques
c7459e3855
GDScript: Use analyzer data to decide assignment conversion
Since there might be tricky cases in the analyzer (in the case of unsafe
lines) which would need to be properly checked again. Instead, this
splits the code generator in two functions and use information set by
the analyzer to tell which function to use, without a need to re-check.
2021-05-26 14:09:00 -03:00
George Marques
ec783dd885
GDScript: Add support for builtin static method calls 2021-05-16 11:54:33 -03:00
George Marques
9ed0f0384c
GDScript: Fix crash when base of an attribute is invalid
In attribute expressions (`a.b`) it's possible that the base has an
incorrect syntax and thus become a nullptr expression in the tree. This
commit add the check for this case to fail gracefully instead of
crashing.
2021-04-28 11:09:40 -03:00
George Marques
c201b212c7
GDScript: Implement lambdas compilation and runtime 2021-04-28 11:09:38 -03: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
George Marques
c7511de02e
GDScript: Fix resolution of dictionary keys
There was a mixup between String and StringName keys. Now they're
clearly separated. This also means you have to consider which type
you're using for the dictionary keys and how you are accessing them.
2021-04-23 15:42:33 -03:00
Rémi Verschelde
737f09895d
Merge pull request #47131 from vnen/gdscript-export-fix
Fix a few issues with @export in GDScript
2021-03-30 15:12:04 +02:00
George Marques
5d9585d83b
GDScript: Fix array type check on constants
They mistakenly pointing to the wrong union member (variable instead of
constant).
2021-03-30 09:09:13 -03:00
George Marques
577a17980d
Move GDSript annotation application after type-checking
This ensures that annotations that rely on the datatype (such as
@export) can validated it timely, allowing compound expressions instead
of only literal values.
2021-03-30 08:29:36 -03:00
George Marques
85e316a5d5
Add typed arrays to GDScript
- Use `Array[type]` for type-hints. e.g.:
  `var array: Array[int] = [1, 2, 3]`
- Array literals are typed if their storage is typed (variable
  asssignment of as argument in function all). Otherwise they are
  untyped.
2021-03-29 10:45:48 -03:00
Rémi Verschelde
51992250e6
Merge pull request #43176 from mateosss/crash-uninit-const
Fix crash by adding nullcheck for uninitialized constants
2021-01-11 14:00:54 +01:00
Rémi Verschelde
8363c44265
Merge pull request #44719 from ThakeeNathees/assert-argument-bug-fixed
GDScript assert message parsing bug fixed
2021-01-11 13:51:44 +01:00
Rémi Verschelde
a2021588ca
Merge pull request #44672 from ThakeeNathees/array-dict-const-fold-bug-fix
Array/Dictionary marked as not safe to const fold
2021-01-11 13:51:31 +01:00
Rémi Verschelde
aaf6725150
Merge pull request #44889 from ThakeeNathees/builtin-invalid-call-crash-fix
GDScript invalid method call on built-in crash fix
2021-01-11 13:51:07 +01:00
Thakee Nathees
01c11ec29b GDScript builtin invalid function call crash fix
Fix: #44852
2021-01-03 18:44:01 +05:30
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
Thakee Nathees
ebade0e454 GDScript assert message parsing bug fixed
Fix: #43540
2020-12-27 13:13:50 +05:30
Thakee Nathees
16bb01adfb Array/Dictionary marked as not safe to const fold
Fix: #44459
2020-12-25 12:33:55 +05:30
Rémi Verschelde
abfc528439
Merge pull request #43890 from vnen/gdscript-builtin-functions-refactor
GDScript: Refactor builtin functions
2020-12-15 20:51:38 +01:00
Rémi Verschelde
9c30c83aee
Merge pull request #44011 from KoBeWi/red_roses_minus_blue_violets
Fix subtracting colors and quats
2020-12-03 14:44:52 +01:00
Tomasz Chabora
4c232e4222 Fix subtracting colors and quats 2020-12-03 14:22:12 +01:00
Rémi Verschelde
d1231be1c8
Merge pull request #41095 from ThakeeNathees/GDScript-Documentation
GDScript(2.0) Documentation generation system
2020-12-02 14:15:38 +01:00
George Marques
a604e72dc9
GDScript: Don't construct ref values in compiler
Values that are passed by reference are not suited for being constructed
at compile time because in this case they would be shared across all the
construction statements.
2020-11-30 09:42:22 -03:00
Thakee Nathees
d0e7d9b62f Documentation generation for GDScript
- ClassDoc added to GDScript and property reflection data were extracted
from parse tree

- GDScript comments are collected from tokenizer for documentation and
applied to the ClassDoc by the GDScript compiler

- private docs were excluded (name with underscore prefix and doesn't
have any doc comments)

- default values (of non exported vars), arguments are extraced from the
parser

- Integrated with GDScript 2.0 and new enums were added.

- merge conflicts fixed
2020-11-29 19:45:36 +05:30
Rémi Verschelde
9f9b269d32
Merge pull request #43914 from ThakeeNathees/range-argument-type-bug-fix
GDScript: range function type check bug fixed
2020-11-27 15:08:02 +01:00
Thakee Nathees
f0613a91be GDScript range function typecheck bug fixed
Fix: #43586
2020-11-27 18:23:35 +05:30
Rémi Verschelde
ed2f84735b
Merge pull request #43895 from vnen/gdscript-operators-fix
GDScript: Improve handling of operators
2020-11-26 21:19:31 +01:00
George Marques
0cb185927c
GDScript: Improve handling of operators
- Use the new functions in Variant to determine the validity and resulting
  type of operators.
- Split the operator function in codegen between binary and unary, since
  the unary ones have now a special requirement of having the second
  argument to be the NIL type when requesting info.
2020-11-26 14:41:55 -03:00
George Marques
627ca7f30e
GDScript: Don't clear depended parsers too soon
It can wait until the analyzer itself is destructed, otherwise other
phases might be using freed parsers.
2020-11-26 14:14:29 -03:00
George Marques
817fb3d702
GDScript: Give an error if dependency can't be parsed
Otherwise this may lead to a crash when the dependency is not present.
2020-11-26 12:27:48 -03:00
George Marques
c7b6a7adcc
GDScript: Refactor builtin functions
They are now called "utility functions" to avoid confusion with methods
of builtin types, and be consistent with the naming in Variant.

Core utility functions are now available in GDScript. The ones missing
in core are added specifically to GDScript as helpers for convenience.

Some functions were remove when there are better ways to do, reducing
redundancy and cleaning up the global scope.
2020-11-26 12:05:42 -03:00
George Marques
fb3dc2670a
GDScript: Fix range() being treated as array when optimized out
The call of range() in a for loop is optimized to use int or vectors, to
avoid allocating an array, however the type was set as array still. With
the new typed VM this is an issue as the type mismatch the actual value,
resulting in wrong instructions to be selected.
2020-11-25 11:35:07 -03:00
Rémi Verschelde
9d2e8f2f27
Variant: Rename Type::_RID to Type::RID
The underscore prefix was used to avoid the conflict between the `RID` class
name and the matching enum value in `Variant::Type`.

This can be fixed differently by prefixing uses of the `RID` class in `Variant`
with the scope resolution operator, as done already for `AABB`.
2020-11-09 16:29:04 +01:00
reduz
221a2a1742 Refactored variant constructor logic 2020-11-09 08:54:43 -03:00