Contradiction in vim9 help?

22 views
Skip to first unread message

Tony Mechelynck

unread,
Feb 6, 2020, 1:24:04 AM2/6/20
to Bram Moolenaar, vim_dev
At lines 234sqq of vim9.txt:

When {return-type} is omitted the return type will be
decided upon by the first encountered `return`
statement in the function. E.g., for: >
return 'message'
< The return type will be "string".

At lines 290sqq:

A function defined with `:def` must declare the return type. If there is no
type then the function doesn't return anything.

Reminder: In functions defined with :function, ":return" is equivalent
with ":return 0" and fall-through to ":endfunction" implies ":return".
Unless the opposite were clearly said, I would expect the same to
apply (mutatis mutandis s/endfunction/enddef/) to new-style function.

So I don't see how it is possible for a function not to declare a
return type either explicitly (in the :def statement) or implicitly
(in the first :return statement, or by fallback to integer if either
the first return is just :return, or there is no explicit :return and
the function returns only by falling through to its endpoint).

Best regards,
Tony.

Bram Moolenaar

unread,
Feb 6, 2020, 6:35:34 AM2/6/20
to vim...@googlegroups.com, Tony Mechelynck
I should remove that text. I first thought it would be OK to get the
return type from the first return statement, like the type of a variable
can be inferred from the initialization. However, the return statement
can be anywhere, making it difficult to find the type. I prefer to
require explicitly specifying the type. It's also more in balance with
the argument types.

The new style functions do require a return statement, there is no
default.

--
hundred-and-one symptoms of being an internet addict:
35. Your husband tells you he's had that beard for 2 months.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages