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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2202 - Error getting type of non-static member of a class
Summary: Error getting type of non-static member of a class
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2008年07月08日 03:07 UTC by Max Samukha
Modified: 2015年06月09日 01:19 UTC (History)
3 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2008年07月08日 03:07:43 UTC
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 Bill Baxter 2008年07月08日 03:51:39 UTC
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 Max Samukha 2008年07月08日 05:16:15 UTC
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 david 2008年07月08日 06:01:56 UTC
in the essence, it's duplicated with bug 515
*** This bug has been marked as a duplicate of 515 ***
Comment 4 Matti Niemenmaa 2008年07月08日 09:06:54 UTC
No, 515 is about whether .offsetof is static or not. This is about whether typeof(Class.nonstatic) should be allowed.
Comment 5 Don 2008年07月08日 09:25:24 UTC
(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 Max Samukha 2008年07月09日 00:21:07 UTC
> It's supposed to take an expression. C.x is an expression.
C.x is not a valid expression?
Comment 7 Don 2009年09月04日 07:18:16 UTC
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 Don 2009年09月04日 08:10:11 UTC
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 Walter Bright 2009年10月06日 02:13:59 UTC
Fixed dmd 1.048 and 2.033


AltStyle によって変換されたページ (->オリジナル) /