Kampfkarren / selene

A blazing-fast modern Lua linter written in Rust

Home Page:https://kampfkarren.github.io/selene/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect definition of os.exit in Lua 5.2

Zash opened this issue · comments

os.exit() in Lua 5.1 takes one argument, and this is correctly specified in

os.exit:
args:
- required: false
type: number

However in Lua 5.2+, os.exit() takes an extra close argument.

So given test.lua

os.exit(2, true)

selene test.lua results in:

error[incorrect_standard_library_use]: standard library function `os.exit` requires 0 parameters, 2 passed
  ┌─ test.lua:1:1
  │
1 │ os.exit(2, true)
  │ ^^^^^^^^^^^^^^^^

Results:
1 errors
0 warnings
0 parse errors

I attempted to patch this in lua52.yml with

diff --git a/selene-lib/default_std/lua52.yml b/selene-lib/default_std/lua52.yml
index d247070..a05b2bc 100644
--- a/selene-lib/default_std/lua52.yml
+++ b/selene-lib/default_std/lua52.yml
@@ -68,6 +68,12 @@ globals:
       - type: number
       - required: false
         type: number
+  os.exit:
+    args:
+      - type: number
+        required: false
+      - type: boolean
+        required: false
   package.config:
     property: read-only
   rawlen:

but this panics selene for some reason:

$ RUST_BACKTRACE=1 selene test.lua
The application panicked (crashed).
Message:  default standard library 'lua52' failed deserialization: globals.os.exit: data did not match any variant of untagged enum FieldKindSerde at line 72 column 5
Location: selene-lib/src/standard_library/mod.rs:331

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 8 frames hidden ⋮                               
   9: selene_lib::standard_library::StandardLibrary::from_builtin_name::h79f2d8e772e790e5
      at <unknown source file>:<unknown line>
  10: selene_lib::standard_library::StandardLibrary::from_name::hb4d19ebbebf99cf3
      at <unknown source file>:<unknown line>
  11: selene::standard_library::collect_standard_library::h1fa496d44eb1a576
      at <unknown source file>:<unknown line>
  12: selene::start::h013a75484ab36752
      at <unknown source file>:<unknown line>
  13: selene::main::h8bc3cbc1ffe1547c
      at <unknown source file>:<unknown line>
  14: std::sys_common::backtrace::__rust_begin_short_backtrace::h23a7a3f880fa71ca
      at <unknown source file>:<unknown line>
  15: std::rt::lang_start::{{closure}}::h339fe53a367fe8cf
      at <unknown source file>:<unknown line>
  16: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb1327dc2ef3fecdf
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:287
  17: std::panicking::try::do_call::h4044173225fe83dd
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485
  18: std::panicking::try::hd8a722c09d156a53
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449
  19: std::panic::catch_unwind::hd2ca07971cf0119b
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140
  20: std::rt::lang_start_internal::{{closure}}::h26d89d595cf47b70
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148
  21: std::panicking::try::do_call::hf47aa1aa005e5f1a
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485
  22: std::panicking::try::h73d246b2423eaf4e
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449
  23: std::panic::catch_unwind::hbaaeae8f1b2f9915
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140
  24: std::rt::lang_start_internal::h76f3e81e6b8f13f9
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148
  25: main<unknown>
      at <unknown source file>:<unknown line>
  26: __libc_start_call_main<unknown>
      at ./csu/../sysdeps/nptl/libc_start_call_main.h:58
  27: __libc_start_main_impl<unknown>
      at ./csu/../csu/libc-start.c:381
  28: _start<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.

boolean is not a valid arg type. It should be bool.