Bug 6087 – typeof(this) doesn't work outside member function

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-06-01T14:30:00Z
Last change time
2015-06-09T05:13:44Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
bus_dbugzilla

Comments

Comment #0 by bus_dbugzilla — 2011-06-01T14:30:32Z
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 ----------------------
Comment #1 by bus_dbugzilla — 2011-06-01T14:32:46Z
I tested this on DMD 2.053
Comment #2 by k.hara.pg — 2011-10-06T00:04:14Z
Comment #3 by bugzilla — 2011-10-06T02:26:09Z