Making sense out of scope and function calls

0xEAB desisma at heidel.beer
Sun Nov 13 19:06:40 UTC 2022


```d
struct Foo { /* … */
     hstring[] getHeader(LowerCaseToken name) scope return
     {
         return _headers[name].values;
     }

     hstring[] getHeader(hstring name)() scope return
     {
         enum token = LowerCaseToken.makeConverted(name);
         return this.getHeader(token); // line 605
     }
}
```

```d
struct Foo { /* … */
     hstring[] getHeader(LowerCaseToken name) scope return
     {
         return _headers[name].values;
     }

     hstring[] getHeader(hstring name)() scope return
     {
         enum token = LowerCaseToken.makeConverted(name);
         return _headers[token].values; // line 605
     }
}
```

Why does only the latter sample compile?
The former leads to the following warning:

```
beyond.d(605,30): Deprecation: cannot take address of `scope` 
variable `this` since `scope` applies to first indirection only
beyond.d(605,30): Deprecation: cannot take address of `scope` 
variable `this` since `scope` applies to first indirection only
```

(and why is the deprecation message printed twice?)



More information about the Digitalmars-d-learn mailing list