Bug 2202 – Error getting type of non-static member of a class

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-07-08T03:07:00Z
Last change time
2015-06-09T01:19:35Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
samukha

Comments

Comment #0 by samukha — 2008-07-08T03:07:43Z
The following fails with 'Error: this for x needs to be type C not type int': class C { int x; } typeof(C.x) z;
Comment #1 by wbaxter — 2008-07-08T03:51:39Z
Not sure if that's really a bug or not. I lean towards "no" since typeof is supposed to take a variable, and C.x is not a variable. You can get what you want with typeof(C.init.x).
Comment #2 by samukha — 2008-07-08T05:16:15Z
I'm not sure either as it worked before but is not mentioned in the specs. I wouldn't post it as bug if the following compiled: static assert (!is(typeof(C.x))); // Fails with the same error, should pass static assert (!__traits(compiles, C.x)); // Should pass ... and if this didn't compile: struct S { int x; } typeof(S.x) y; // Why this compiles then? So it is either a regression or we have other bugs and inconsistencies.
Comment #3 by davidl — 2008-07-08T06:01:56Z
in the essence, it's duplicated with bug 515 *** This bug has been marked as a duplicate of 515 ***
Comment #4 by matti.niemenmaa+dbugzilla — 2008-07-08T09:06:54Z
No, 515 is about whether .offsetof is static or not. This is about whether typeof(Class.nonstatic) should be allowed.
Comment #5 by clugdbug — 2008-07-08T09:25:24Z
(In reply to comment #1) > Not sure if that's really a bug or not. I lean towards "no" since typeof is > supposed to take a variable, and C.x is not a variable. It's supposed to take an expression. C.x is an expression. > > You can get what you want with typeof(C.init.x). >
Comment #6 by samukha — 2008-07-09T00:21:07Z
> It's supposed to take an expression. C.x is an expression. C.x is not a valid expression?
Comment #7 by clugdbug — 2009-09-04T07:18:16Z
This example shows it's definitely a bug (1.047): class C { int x; } alias C.x F; static assert(is(typeof(F) == int)); // OK static assert(is(typeof(C.x) == int)); //Error: static assert (is(int == int)) is false
Comment #8 by clugdbug — 2009-09-04T08:10:11Z
PATCH: mtype.c, in TypeClass::dotExp(), around line 6350 in D2.032. Don't convert class.x into this.x if inside a typeof() and we don't have a 'this'. -------- /* It's: * Class.d */ if (d->isTupleDeclaration()) { e = new TupleExp(e->loc, d->isTupleDeclaration()); e = e->semantic(sc); return e; } - else if (d->needThis() && (hasThis(sc) || !d->isFuncDeclaration())) + else if (d->needThis() && (hasThis(sc) || (!sc->intypeof && !d->isFuncDeclaration()))) { if (sc->func) { ClassDeclaration *thiscd; thiscd = sc->func->toParent()->isClassDeclaration(); -------
Comment #9 by bugzilla — 2009-10-06T02:13:59Z
Fixed dmd 1.048 and 2.033