edubart / nelua-lang

Minimal, efficient, statically-typed and meta-programmable systems programming language heavily inspired by Lua, which compiles to C and native code.
https://nelua.io
MIT License
1.99k stars 64 forks source link

C code tries to initialize nltype with 0 in strange errorhandling / assert / module interaction #230

Closed jrfondren closed 10 months ago

jrfondren commented 11 months ago

Bug description

This is a warning with gcc, and an error with tcc. I found it naturally while using nester to test a module that used utf8.codepoint()

Code example

with modcheck.nelua:

require 'errorhandling'
local M = @record{}
local function f() assert(true) return 1 end
local x = f()
function M.f() return f() end
return M

You can observe the error with:

$ nelua -C -i 'require("modcheck")'
warning: using error handling module, it is highly experimental and incomplete!
/home/jfondren/.cache/nelua/eval_2jNUNGZEoYm.c: In function ‘nelua_require_modcheck’:
/home/jfondren/.cache/nelua/eval_2jNUNGZEoYm.c:2205:23: warning: excess elements in struct initializer
 2205 |       return (nltype){0};
      |                       ^
/home/jfondren/.cache/nelua/eval_2jNUNGZEoYm.c:2205:23: note: (near initialization for ‘(anonymous)’)

Where the larger context is

nltype nelua_require_modcheck(nlniltype modname) {
  ({
    int64_t __callret = modcheck_f();
    if(nelua_error_status) {
      return (nltype){0};
    }   
    __callret;
  });
  return NELUA_NIL;
}

Environment

x86_64 linux Nelua 0.2.0-dev Build number: 1588 Git date: 2023-09-16 16:20:44 -0300 Git hash: 596fcca5c77932da8a07c249de59a9dff3099495 Semantic version: 0.2.0-dev.1588+596fcca5 Copyright (C) 2019-2022 Eduardo Bart (https://nelua.io/)

edubart commented 11 months ago

Error handling module is not finished, it is full of issues. Maybe I should remove from standard library or leave in an experimental folder.

jrfondren commented 11 months ago

I wasn't using 'errorhandling' directly, I was using nester from nelua-batteries.

edubart commented 10 months ago

Fixed in https://github.com/edubart/nelua-lang/commit/decf713ca4bfd99b7bb9ae3c5f66b87761fd8621