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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 22 22:51:13 PST 2014


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



--- Comment #7 from Vladimir Panteleev <thecybershadow at gmail.com> 2014-01-23 08:51:03 EET ---
> It's increasing consistency with currently known language concepts:

Yes, this is all fine and well, but it does not justify making code that worked
before now break with an indecipherable error message! The message "need 'this'
to access member f" is an outright lie and is only good at showing a glaring
compiler implementation problem.

(In reply to comment #1)
> template f(alias X)
> {
>     static string f()
>     {
>         //int x = X;
>         return X.stringof; // OK
>     }
> }

This just shows another bug - that you still need "static" (which makes NO
sense for a free function, templated or not), but now you must hide it inside a
template!

> To be more precise, current D language alias template parameter is not designed
> just to take a symbol that is needed just only at compile-time.
> If given template argument has implicit runtime context, compiler will _always_
> try to take runtime context at the same time.

So fix this first before breaking code?

> To ignore the implicit automatic capturing, you need to write the idiom I
> explained in comment#1.

If one needs to go to a bugtracker and learn of a hacky workaround (put a
static function in a template) from a compiler developer to make their code
compile, this is a terrible situation for D.

> As a conclusion: the reported breaking change is necessary due to add more
> consistency to the language spec.

I suggest that consistency bugs are fixed only after there is an immediate and
obvious way to transition code that should not have compiled, to correct code
which functions in the same way. In either case, this bug remains a REGRESSION.

-- 
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