Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions msu/utils/type_checkers.nut
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
::MSU.requireTypeArray("integer", vargv);
}

::MSU.requireUnsigned <- function( ... )
{
::MSU.requireTypeArray("integer", vargv);

@Darxo Darxo Mar 4, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will say this use of the existing require check only seemed good back then.
But in reality this means that failing an unsigned integer check will print a "failed an integer check" message half the time. And that is not fully correct.

Ideally we would copy&paste the integer check logic in this check but swap out the printed exception

foreach (value in vargv)
{
if (value < 0)
{
::logError(value + " must have the type: unsigned");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd argue unsigned isn't actually a type and therefore the error should be something more like.

value + " must have the type: integer, and be greater than or equal to 0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In that same vein what about the function name? Should it be something like requireUInt?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah maybe that's better too

throw ::MSU.Exception.InvalidType(value);
}
}
}

::MSU.requireArray <- function( ... )
{
::MSU.requireTypeArray("array", vargv);
Expand Down