Invalid greater-than comparisons produce incorrectly ordered error messages

Issue Type: Other
Impact: Low
Frequency: Constantly
Date First Experienced:
Date Last Experienced: 2021-04-21 00:04:00 (+01:00)

Reproduction Steps:
Run the following code in the Studio command bar:

= 0 > nil

Observe the error message in the output window.

This can also be reproduced using the >= operator.


Roblox Studio version 0.475.5.420862 (64bit). No beta features enabled.


Expected Behavior:
The error message should read:

[...] attempt to compare number and nil

Actual Behavior:
The error message reads:

[...] attempt to compare nil and number

Workaround:
Restructure > and >= comparisons to use their < and <= equivalent.

8 Likes

I think this is the expected behavior. According to the Lua 5.1 manual:

I tested this on Lua 5.3 and the behavior is the same as Luau’s.

3 Likes

I noticed that too, but I don’t think a behavior existing in PUC-Rio necessarily means that it shouldn’t be considered a Luau bug. The error message mischaracterizes the issue.

3 Likes

So yeah, I agree that this is a bug but it’s also a bug that’s hard for us to fix cleanly because that requires making the VM noticeably more complicated (+7% opcodes or smth) for no benefit other than error clarity here.

Would it be better if we changed the error message to clearly indicate the operator involved? E.g. attempt to compare number and nil using <= or something along these lines?

11 Likes

That sounds like a good improvement. If possible, placing the operator involved between the value types in the error message (number <= nil) may be even clearer.

6 Likes

That would be amazing! This error has stumped me many times before. That seems like a pretty good fix without having to change too much.

This has shipped:

  print(5 >= nil):1: attempt to compare nil <= number
  Stack Begin
  Script 'print(5 >= nil)', Line 1
  Stack End
7 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.