Thread overview
[Issue 23933] auto return type disables DIP1000 scope check
May 24, 2023
Atila Neves
May 24, 2023
RazvanN
May 24, 2023
RazvanN
May 24, 2023
RazvanN
May 24, 2023
Richard Cattermole
May 24, 2023
https://issues.dlang.org/show_bug.cgi?id=23933

Atila Neves <atila.neves@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, safe

--
May 24, 2023
https://issues.dlang.org/show_bug.cgi?id=23933

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
Under the current specification this is not a bug, even though the behavior is surprising. Attributes are inferred for auto functions because you a function body needs to be present. Attributes are not inferred for non-auto functions, even if the body is present.

--
May 24, 2023
https://issues.dlang.org/show_bug.cgi?id=23933

--- Comment #2 from RazvanN <razvan.nitu1305@gmail.com> ---
[...] for auto functions because a function body needs to be present*

--
May 24, 2023
https://issues.dlang.org/show_bug.cgi?id=23933

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
So, if we enable attribute inference for all functions that have a body, this will be fixed as a consequence. Or, the workaround would be to manually annotate `hmm` as scope.

--
May 24, 2023
https://issues.dlang.org/show_bug.cgi?id=23933

Richard Cattermole <alphaglosined@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alphaglosined@gmail.com
         Resolution|---                         |INVALID

--- Comment #4 from Richard Cattermole <alphaglosined@gmail.com> ---
The inference can be seen when you use auto instead of scope inside of safeUsage when you output the AST.

```d
struct Struct
{
        int* p;
        @safe void hmm(int i)
        {
        }
}
```

vs with scope & auto:

```d
struct Struct
{
        int* p;
        auto pure nothrow @nogc @safe void hmm(int i)
        {
        }
}
```

I don't see a bug here. This looks to be working correctly. A method that was not annotated with scope, used with scope, works when inference is turned on. So I'm closing.

--