Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use full type validation in Array::append_array #54940

Conversation

briansemrau
Copy link
Contributor

@briansemrau briansemrau commented Nov 13, 2021

Fixes #54939
Might fix #52485 or at least a part of it

Lightly tested. Probably needs some test cases added.

I'm not happy with how this currently looks. This was copied and modified from Array::_assign. Not sure if there's a way to reduce code duplication here without losing performance.

@briansemrau briansemrau requested a review from a team as a code owner November 13, 2021 08:18
@Chaosus Chaosus added this to the 4.0 milestone Nov 13, 2021
Variant src_val = p_array._p->array[i];
if (src_val.get_type() == _p->typed.type) {
new_array.write[i] = src_val;
} else if (Variant::can_convert_strict(src_val.get_type(), _p->typed.type)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this create an inconsistency:

var int_array: Array[int] = [1, 2, 3]
func _ready():
    int_array.append_array([1.23])     # would be allowed
    int_array.append(1.23)             # still not allowed
    int_array[0] = 1.23                # still not allowed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally am in favor of allowing these assignments to do implicit casting. An inconsistency, yes, but the other operations you've listed I would consider a little restrictive.

@akien-mga
Copy link
Member

Checked briefly in a PR review meeting and we agreed that fixing these bugs makes sense. @vnen should have a proper look at the implementation before merging (maybe also adding GDScript unit tests to validate the different scenarios?).

@YuriSizov
Copy link
Contributor

Both linked bugs are now fixed, and there has been many changes to GDScript since this PR has been last updated. Closing as superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants