[Issue 9361] Nasty bug and/or error message for template constaints using this

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 21 06:19:03 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9361



--- Comment #3 from Phil Lavoie <maidenphil at hotmail.com> 2013-01-21 06:19:00 PST ---
(In reply to comment #1)
> Reduced test case:
> 
> struct Unit(A)
> {
>     void butPleaseDontUseMe()()
>     if (is(unitType!((this))))  // !
>     {}
> 
> }
> template isUnit(alias T) if ( is(T)) {}
> template isUnit(alias T) if (!is(T)) {}
> template unitType(alias T) if (isUnit!T) {}
> void main()
> {
>     Unit!int u;
>     u.butPleaseDontUseMe();     // crashes
> }
> 
> ====
> 
> I think the instantiation unitType!((this)) in the template constraint for
> butPleaseDontUseMe template function should always fail, because the 'this'
> symbol yet not has an actual entity while the constraint evaluation.
> 
> That means, the invocation of s.foo() should fail in following.
> 
> template Sym(alias A) { enum Sym = true; }
> struct S {
>     void foo()() if (Sym!(this)) {}
>     // Sym!(this) always make an error, because
>     // Sym template never be able to access
>     // valid 'this' symbol.
> }
> void main() { S s; s.foo(); }

Yes it makes sense, however the error message is clearly not appropriate!
Something like:
dmd: Error: If you use this in template constraint again I will hate you.
Should do :)

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


More information about the Digitalmars-d-bugs mailing list