[Issue 11946] "need 'this' to access member" when passing field to template parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 23 18:48:38 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=11946



--- Comment #13 from Vladimir Panteleev <thecybershadow at gmail.com> 2014-01-24 04:48:25 EET ---
After some thinking:

"static" must not affect whether alias parameters receive context pointers.
Currently, there can only be one context pointer per function, but this
limitation will hopefully be lifted in the future. When that happens, there
will be no way to decide whether each alias parameter carries along a context
pointer or not. Therefore, "static" must only untie the function from its
immediate surrounding declaration context (struct, class or function frame).

As I understand, currently, if a declaration CAN have a context pointer, the
compiler seems to demand it at all times when passing it as an alias parameter.

Instead, it should pass a context pointer if and only if if it is actually
available at the scope of the template instantiation.

For example, it will be available when calling a templated function from a
non-static method, but it will not be available when declaring an enum, or
calling from a static method.

Later, if the template function's code attempts to do anything with the alias
parameter which ACTUALLY requires its context, for example reading/writing it
or taking its address, then it should raise an error. So, the context pointer
check needs to stop being eager and be made as late as possible.

Additionally, if you want to explicitly choose whether you want to pass an
alias parameter WITH or WITHOUT a context pointer, I think the language already
has the necessary syntax, and for class/struct fields it is quite intuitive:
C.x (no context pointer) vs. c.x (c is the context pointer), or this.x vs.
typeof(this).x etc. It is more complicated with local variables, but I think
__traits(getMember, __traits(parent, n), "n") would work. However, I believe
this should not be necessary at all, since the compiler should not demand a
context pointer without even bothering to check if the template actually needs
it.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list