[Issue 21195] Delegate to method created without a `this` in certain contexts

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 27 09:16:56 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21195

--- Comment #3 from Tomer Filiba (weka) <tomer at weka.io> ---
Simen, it's not the type of `S.func` or whatever, it's the & operator -- it
should fail when trying to create a delegate to a method without a `this`

The actual production code had a copy-paste error, it was more of the
following:
```
struct Client {
   __gshared static PoolDict(int, Client, 1024) dict;

    static Client* getClient(int key) {
        if (key !in dict) {
             dict[key] = Client(...);
             registerTimer(5.minutes, &closeInactive);
        }
    }

    void closeInactive() {
        // a happy little method
    }
}
```

if should have been 
```
             registerTimer(5.minutes, &dict[key].closeInactive);

```

don't worry about dict, it has a pool for the values, so it will not move
objects. taking pointers to it is safe.

my point is that 
```
&closeInactive
```

shouldn't compile, because this expression cannot be a (correct) type

--


More information about the Digitalmars-d-bugs mailing list