-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prettify function tostring #2870
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, forgot to update the tostring post making functions store their arguments and return types
@@ -76,6 +76,9 @@ end | |||
---@field ret string | |||
local Function = {} | |||
Function.__index = Function | |||
Function.__tostring = function(self) | |||
return "function(" .. self.arg_sig .. ")" .. (self.ret and ": " .. self.ret or "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "function(" .. self.arg_sig .. ")" .. (self.ret and ": " .. self.ret or "") | |
return "function(" .. self.arg_sig .. ")" .. (self.ret and (": " .. self.ret)) or "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the LuaLS upset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need another set of parens wrapping or ""
I assume
Actually, should functions be allowed in arrays? |
@@ -1868,7 +1868,9 @@ local CompileVisitors = { | |||
---@type E2Lambda | |||
local f = expr(state) | |||
|
|||
if f.arg_sig ~= sig then | |||
if not f then | |||
state:forceThrow("Trying to call function that doesn't exist!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set the default function to one that throws this error. This is adding overhead to every function call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to do that but then it gives an error for bad parameters instead, which I thought would be unideal.
let BadFunc = table()[1, function]
BadFunc(1) # Error: Expected void
If you think that's worth sacrificing, then that's fine. The error stems from the same root I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a compromise, maybe the error could be thrown after if f.arg_sig ~= sig
? Then it would only be adding that overhead to errors. Compare it to a nofunction
constant.
Forgot |
Ok. I'm at my PC. Can we please not make completely different changes to a PR after already getting an accepting review (basically making it pointless?) Either leave it as draft or make another PR. |
At this point I'm just leaning toward not having a default value for |
0188744
to
81cd727
Compare
Right, my bad. |
Outputs
function(ARGS): RET
for tostring operations includingprintTable
.