| |
| Posted by user1234 in reply to user1234 | PermalinkReply |
|
user1234
Posted in reply to user1234
| On Thursday, 19 May 2022 at 09:24:21 UTC, user1234 wrote:
> On Thursday, 19 May 2022 at 09:15:50 UTC, Anonymouse wrote:
> I like explicit return types. But I also like inference.
struct SomeContainer(T)
{
/* ... */
auto clear()
{
head = 0;
tail = 0;
buf[] = T.init;
}
}
dscanner -S: Auto function without return statement, prefer an explicit void
Can we please have void clear() auto ?
The problem is when in the body you have an asm block that returns.
In that case the return type cant be inferred.
module runnable ;
auto notVoid()
{
asm
{
naked;
mov AL, 1;
ret;
}
}
void main()
{
auto b = notVoid();
}
> Error: variable runnable.main.b type void is inferred from initializer notVoid() , and variables cannot be of type void
but notVoid() actually returns a ubyte
so... we got an error here because we use the function. The D-Scanner check is just here to show you that "hello there might be a small problem here", and that's it ;). Linting is very opritinatrist.
The logic is
- return type is auto
- there's not return statments
=> take care
|