[Issue 21195] New: Delegate to method created without a `this` in certain contexts
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Aug 25 05:07:41 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21195
Issue ID: 21195
Summary: Delegate to method created without a `this` in certain
contexts
Product: D
Version: D2
Hardware: All
URL: http://dlang.org/
OS: All
Status: NEW
Severity: major
Priority: P3
Component: dmd
Assignee: nobody at puremagic.com
Reporter: tomer at weka.io
i had code similar to this
```
import std.stdio;
void function() callback;
struct S {
static void getter() {
callback = &func; <<<< this shouldn't compile, `func` needs `this`
}
void func() {
writefln("func(this=%s)", &this);
}
}
void main() {
S.getter();
callback();
}
```
output:
```
func(this=1)
```
which is obviously means `this` is corrupted and trying to touch any members of
it would segfault.
if instead i write
```
void main() {
S s;
callback = &s.func;
}
```
i get the expected
```
Error: cannot implicitly convert expression &s.func of type void delegate() to
void function()
```
but it seems that in the context of a static function, it skips checking that i
have a `this` to get a delegate
--
More information about the Digitalmars-d-bugs
mailing list