[Issue 1983] Delegates violate const
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Feb 10 07:26:31 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=1983
--- Comment #29 from ZombineDev <petar.p.kirov at gmail.com> ---
alias Context = void*;
................^^^^^
This is where the problem begins and why I think many fail to recognize the
type system holes. `void*` is just an implementation detail. It really
shouldn't be part of anyone's mental model **as far the type system is
concerned**. Most importantly, the front-end shouldn't even know that the
context pointer is represented as void*. Instead, it should follow the type
system rules, as if the context pointer is correctly specified. For example:
With delegates to struct and class non-static member functions it should be
fairly obvious what is the right type:
---
struct S { int x; char[] cx; ref char foo(); }
S s;
auto dg = &s.foo; // Context = S*;
immutable S s;
auto dg2 = &s.foo; // Context = immutable(S)*;
---
With nested functions is where most people get confused:
---
auto test()
{
int x;
char[] cx;
ref char nested() // Context = (struct { int x; char[] cx; })*;
{ /* ... */ }
return &nested;
}
---
--
More information about the Digitalmars-d-bugs
mailing list