pallene-lang / pallene

Pallene Compiler
MIT License
697 stars 29 forks source link

Record tag error message includes record name instead of only "userdata" #595

Closed Vipul-Cariappa closed 7 months ago

Vipul-Cariappa commented 8 months ago

Fixes: #151

Code:

-- main.lua

Mod = require "Shapes"

C1 = Mod.Circle_New(3.0)
R1 = Mod.Rectangle_New(3.0, 4.0)

print(Mod.Circle_Area(R1))
print(Mod.Circle_Area(1)) 
-- Shapes.pln

local Shapes: module = {}

record Circle
    radius: float
end

record Rectangle
    length: float
    width: float
end

function Shapes.Circle_New(r: float): Circle
    local c: Circle = {radius = r}
    return c
end

function Shapes.Circle_Area(c: Circle): float
    return c.radius * c.radius * 3.1415
end

function Shapes.Rectangle_New(l: float, w: float): Rectangle
    local c: Rectangle = {length = l, width = w}
    return c
end

function Shapes.Rectangle_Area(c: Rectangle): float
    return c.length * c.width
end

return Shapes

Old behaviour

❯ lua main.lua                                  
lua: main.lua:8: file Shapes.pln: line 17: wrong type for argument 'c', expected userdata but found userdata
stack traceback:
        [C]: in function 'Shapes.Circle_Area'
        main.lua:8: in main chunk
        [C]: in ?

❯ lua main.lua
lua: main.lua:9: file Shapes.pln: line 17: wrong type for argument 'c', expected userdata but found integer
stack traceback:
        [C]: in function 'Shapes.Circle_Area'
        main.lua:9: in main chunk
        [C]: in ?

New behaviour

❯ lua main.lua
lua: main.lua:8: file Shapes.pln: line 17: wrong type for argument 'c', expected Circle but found Rectangle
stack traceback:
        [C]: in function 'Shapes.Circle_Area'
        main.lua:8: in main chunk
        [C]: in ?

❯ lua main.lua
lua: main.lua:9: file Shapes.pln: line 17: wrong type for argument 'c', expected Circle but found integer
stack traceback:
        [C]: in function 'Shapes.Circle_Area'
        main.lua:9: in main chunk
        [C]: in ?
hugomg commented 7 months ago

Hmm, why is our CI failing? 🤔 The tests are passing on my machine. Is that also the case for you, Vipul?