www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2202] New: Error getting type of non-static member of a class

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202

           Summary: Error getting type of non-static member of a class
           Product: D
           Version: 2.015
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: samukha voliacable.com


The following fails with 'Error: this for x needs to be type C not type int':

class C
{
    int x;
}

typeof(C.x) z;


-- 
Jul 08 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202





------- Comment #1 from wbaxter gmail.com  2008-07-08 03:51 -------
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).


-- 
Jul 08 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202





------- Comment #2 from samukha voliacable.com  2008-07-08 05:16 -------
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.


-- 
Jul 08 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202


davidl 126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE




------- Comment #3 from davidl 126.com  2008-07-08 06:01 -------
in the essence, it's duplicated with bug 515

*** This bug has been marked as a duplicate of 515 ***


-- 
Jul 08 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202


matti.niemenmaa+dbugzilla iki.fi changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         OS/Version|Windows                     |All
           Platform|PC                          |All
         Resolution|DUPLICATE                   |




------- Comment #4 from matti.niemenmaa+dbugzilla iki.fi  2008-07-08 09:06
-------
No, 515 is about whether .offsetof is static or not. This is about whether
typeof(Class.nonstatic) should be allowed.


-- 
Jul 08 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202





------- Comment #5 from clugdbug yahoo.com.au  2008-07-08 09:25 -------
(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).
 

--
Jul 08 2008
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202





------- Comment #6 from samukha voliacable.com  2008-07-09 00:21 -------
 It's supposed to take an expression. C.x is an expression.

C.x is not a valid expression? --
Jul 08 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<d-bugmail puremagic.com> wrote in message 
news:g51hs4$rq7$1 digitalmars.com...
 http://d.puremagic.com/issues/show_bug.cgi?id=2202





 ------- Comment #6 from samukha voliacable.com  2008-07-09 00:21 -------
 It's supposed to take an expression. C.x is an expression.

C.x is not a valid expression?

What's it supposed to give? It's an instance variable. It's syntactically an expression, but semantically it makes no sense, it has no value. Interestingly, &C.method works. Thankfully. Hope that never breaks. But that's maybe because functions are statically allocated, unlike instance variables.
Jul 09 2008
parent Max Samukha <maxter ukr.net> writes:
On Wed, 9 Jul 2008 09:31:13 -0400, "Jarrett Billingsley"
<kb3ctd2 yahoo.com> wrote:

<d-bugmail puremagic.com> wrote in message 
news:g51hs4$rq7$1 digitalmars.com...
 http://d.puremagic.com/issues/show_bug.cgi?id=2202





 ------- Comment #6 from samukha voliacable.com  2008-07-09 00:21 -------
 It's supposed to take an expression. C.x is an expression.

C.x is not a valid expression?

What's it supposed to give? It's an instance variable. It's syntactically an expression, but semantically it makes no sense, it has no value.

Sometimes I just fail to express myself. I should have asked "C.x is not a valid expression, is it?", or better: "C.x is an invalid expression, isn't it?" Or something like that.
Interestingly, &C.method works.  Thankfully.  Hope that never breaks.  But 
that's maybe because functions are statically allocated, unlike instance 
variables. 

I rely on &C.method too.
Jul 09 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au




--- Comment #7 from Don <clugdbug yahoo.com.au>  2009-09-04 07:18:16 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 04 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202


Don <clugdbug yahoo.com.au> changed:

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




--- Comment #8 from Don <clugdbug yahoo.com.au>  2009-09-04 08:10:11 PDT ---

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();
-------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 04 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2202


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #9 from Walter Bright <bugzilla digitalmars.com> 2009-10-06
02:13:59 PDT ---
Fixed dmd 1.048 and 2.033

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