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

C#: Untyped to typed ArgumentNullException #83051

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented Oct 9, 2023

Originally part of #82983, before one of the discussions prompted me to check if adding ArgumentNullException to the untyped→typed constructors would break compatability. As it turns out, it would not, because they always expect the underlying collection to be valid. However, this does mean that it wasn't throwing an exception earlier, only when an actual function is called, so the exception in the constructor is warranted

In addition, this adds missing exception/returns documentation for the two files. It was already warranted for the constructors having a new exception, but this ensures similar relevant functions have appropriate documentation if it was similarly missing


Test case::

var array = (Godot.Collections.Array)null;
var intArray = new Godot.Collections.Array<int>(array);
intArray.Add(123);

Old behavior log, caught on line 3:

Array.cs:1514 @ Boolean Godot.Collections.Array`1.get_IsReadOnly(): System.NullReferenceException: Object reference not set to an instance of an object.

New behavior log, caught on line 2:

Array.cs:1129 @ Godot.Collections.Array`1..ctor(Godot.Collections.Array): System.ArgumentNullException: Value cannot be null. (Parameter 'array')

• Add some missing exception/return documentation
@Repiteo Repiteo requested a review from a team as a code owner October 9, 2023 15:26
@raulsntos raulsntos added this to the 4.2 milestone Oct 9, 2023
Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

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

Looks good to me, since it was already resulting in exceptions I think it's fine to move the exception to the constructor.

@akien-mga akien-mga changed the title C#: untyped to typed ArgumentNullException C#: Untyped to typed ArgumentNullException Oct 9, 2023
@akien-mga akien-mga merged commit 9694f1d into godotengine:master Oct 9, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@Repiteo Repiteo deleted the c#-untyped-to-typed-argumentnullexception branch October 9, 2023 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants