April 22, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2873

           Summary: typeof() for member functions evaluated incorrectly
           Product: D
           Version: 2.029
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: dsimcha@yahoo.com


// Copied/pasted from std.range, added pragma.
template hasLength(R)
{
    pragma(msg, typeof(R.init.length).stringof);  // (uint())()
    enum bool hasLength = is(typeof(R.init.length) : ulong);
}

struct Foo {
    uint length() {
        return 0;
    }
}

const Foo foo;

static assert(hasLength!(Foo));  // Fails.

This is pretty serious because it makes important functionality in the new Phobos unusable.  However, an easy workaround to fix Phobos until the underlying DMD bug gets fixed is:

enum bool hasLength = is(typeof(R.init.length) : ulong) ||
                      is(typeof(R.init.length()) : ulong);

Also, what the heck is a (uint())() ?


-- 

May 02, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2873


Masahiro Nakagawa <repeatedly@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k-foley@onu.edu


--- Comment #1 from Masahiro Nakagawa <repeatedly@gmail.com> 2010-05-02 10:04:17 PDT ---
*** Issue 3508 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2873


Masahiro Nakagawa <repeatedly@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |repeatedly@gmail.com
         Resolution|                            |INVALID


--- Comment #2 from Masahiro Nakagawa <repeatedly@gmail.com> 2010-05-04 17:52:04 PDT ---
Since adding @property, this behavior isn't a bug. length method should be a property. Please use @property for length method.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2873


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #3 from bearophile_hugs@eml.cc 2010-05-04 18:30:17 PDT ---
Masahiro Nakagawa, I am not sure I understand this bug report and your answer well. But if I understand them, then then if you are right, and length method should be a property, then the compiler has to give a compile time error if you try to define a non-property length method, otherwise it's too much easy to write a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2873



--- Comment #4 from Masahiro Nakagawa <repeatedly@gmail.com> 2010-05-04 20:33:06 PDT ---
(In reply to comment #3)
> Masahiro Nakagawa, I am not sure I understand this bug report and your answer well.
Old D's property is a syntactic sugar(member function automatically becomes
property), so typeof() should have evaluated .length and .length() correctly.
But now, D has @property. User can choose property or non-property.

> But if I understand them, then then if you are right, and length method
> should be a property, then the compiler has to give a compile time error if you
> try to define a non-property length method, otherwise it's too much easy to
> write a bug.
I agree because I can't image non-property length. I think D's compiler should print warning message if user tries to define non-property length.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home