Skip to content

Commit

Permalink
Allow implicit function return types (#2866)
Browse files Browse the repository at this point in the history
Resolves #2865
  • Loading branch information
Vurv78 authored Nov 19, 2023
1 parent 2fdfd38 commit 9add762
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion data/expression2/tests/runtime/base/userfunctions/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,18 @@ try {
error("unreachable")
} catch(Err) {
assert(Err == "No such function defined at runtime: undefined()")
}
}

function implicit() {
return 55
}

assert( implicit() == 55 )

function implicit_lambda() {
return function() {
return 5
}
}

assert( implicit_lambda()()[number] == 5 )
6 changes: 5 additions & 1 deletion lua/entities/gmod_wire_expression2/base/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,11 @@ local CompileVisitors = {
end
end)

self:Assert(fn.ret == return_type, "Function " .. name.value .. " expects to return type (" .. (return_type or "void") .. ") but got type (" .. (fn.ret or "void") .. ")", trace)
if return_type then
self:Assert(fn.ret == return_type, "Function " .. name.value .. " expects to return type (" .. return_type .. ") but got type (" .. (fn.ret or "void") .. ")", trace)
else
return_type = fn.ret
end

local sig = name.value .. "(" .. (meta_type and (meta_type .. ":") or "") .. sig .. ")"
local fn = fn.op
Expand Down

0 comments on commit 9add762

Please sign in to comment.