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






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






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





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                   |





-------
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







 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






 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






 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






 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





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






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



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