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

Implicit generation of function when directly calling function on require()d namespace #229

Closed jrfondren closed 10 months ago

jrfondren commented 11 months ago

Bug description

When a library returns a record with functions defined on it, there's no problem with assigning that record to a variable and calling the functions against the variable, but invalid C is generated if the functions are called directly on require()'s return value.

Code example

local M = @record{}
function M.show() print(1) end
return M

When named 'lib.nelua',

$ nelua -i 'local m = require("lib") m.show()'
1
$ nelua -i 'require("lib").show()'
/home/jfondren/.cache/nelua/eval_UX7k2sMerEs.c: In function ‘nelua_main’:
/home/jfondren/.cache/nelua/eval_UX7k2sMerEs.c:82:3: error: implicit declaration of function ‘lib2_M_show’ [-Werror=implicit-function-declaration]
   82 |   lib2_M_show();
      |   ^~~~~~~~~~~
cc1: some warnings being treated as errors
error: C compilation for '/home/jfondren/.cache/nelua/eval_UX7k2sMerEs' failed

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/)