Thread overview
[Issue 6087] New: typeof(this) doesn't work outside member function
Jun 01, 2011
Nick Sabalausky
Jun 01, 2011
Nick Sabalausky
Oct 06, 2011
Kenji Hara
Oct 06, 2011
Walter Bright
June 01, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6087

           Summary: typeof(this) doesn't work outside member function
           Product: D
           Version: future
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: cbkbbejeap@mailinator.com


--- Comment #0 from Nick Sabalausky <cbkbbejeap@mailinator.com> 2011-06-01 14:30:32 PDT ---
According to http://www.digitalmars.com/d/2.0/declaration.html
"1. typeof(this) will generate the type of what this would be in a non-static
member function, even if not in a member function. "

But this doesn't work. I have two test cases, each giving a different error (not sure which is more useful):

Test A:
----------------------
template True(T)
{
    immutable True = true;
}
struct Foo
{
    static assert( True!(typeof(this)) );
}
----------------------
>dmd -c testTypeofThisA.d
testTypeofThisA.d(7): Error: this is not in a class or struct scope
testTypeofThisA.d(7): Error: 'this' is only defined in non-static member
functions, not testTypeofThisA
----------------------

Test B:
----------------------
struct Foo
{
    static assert( is(typeof(this) == Foo) );
}
----------------------
>dmd -c testTypeofThisB.d
testTypeofThisB.d(3): Error: static assert  (is(typeof(__error) == Foo)) is
false
----------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 01, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6087



--- Comment #1 from Nick Sabalausky <cbkbbejeap@mailinator.com> 2011-06-01 14:32:46 PDT ---
I tested this on DMD 2.053

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6087


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2011-10-06 00:04:14 PDT ---
https://github.com/D-Programming-Language/dmd/pull/434

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6087


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2011-10-06 02:26:09 PDT ---
https://github.com/D-Programming-Language/dmd/commit/48ad063f127d3b150f4f1ed5cb4b27ff18d9b6fe

https://github.com/D-Programming-Language/dmd/commit/451dbb73e356e3cf530cfc11e1b5094bc2b823af

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