Clue icon indicating copy to clipboard operation
Clue copied to clipboard

Check for errors

Open Enn3Developer opened this issue 2 years ago • 5 comments

At the current state, the compiler doesn't check if a function called in a file from another file is either local or global thus making errors go through the Lua version. Example: main.clue

local test = import("test")

local fn print_var(var) {
    print("Info " .. var)
}

print_var("Hello")
print_var(double(2))
print_var(multiply(2, 2))

test.clue

local fn multiply(a, b) {
    return a * b
}

global fn double(a) {
    return multiply(a, 2)
}

lua main.lua

Info Hello
Info 4
lua: main.lua:40: attempt to call a nil value (global 'multiply')
stack traceback:
        main.lua:40: in local 'cached'
        main.lua:11: in local 'import'
        main.lua:44: in main chunk
        [C]: in ?

Enn3Developer avatar Jun 15 '22 16:06 Enn3Developer

that is intended? if a function is local it cannot be accessed from other files

Maiori44 avatar Jun 15 '22 16:06 Maiori44

yes, but Clue didn't report it during compilation, that's my point

Enn3Developer avatar Jun 15 '22 17:06 Enn3Developer

Clue does not keep track of any variable created, it lets Lua handle that This feature will very probably be added alongside types in Clue 3.0

Edit: 4.0 now...

Maiori44 avatar Jun 15 '22 17:06 Maiori44

in 3.0 it is possible to implement this when using the mlua feature

Markos-Th09 avatar Nov 22 '22 11:11 Markos-Th09

This is why this is for 4.0

Maiori44 avatar Nov 22 '22 11:11 Maiori44