March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9630



--- Comment #10 from Vladimir Panteleev <thecybershadow@gmail.com> 2013-03-02 08:09:16 EET ---
> auto x = typeof(arr.map!(x => x*2).filter!(x > 4).array[0]).max;

Well, I don't know about how this fits with backwards compatibility and such, but the above line looks wrong to me as well, since it's passing a non-existent variable (arr) to a function (map). This is as much "runtime evaluated" as taking its index.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9630



--- Comment #11 from Kenji Hara <k.hara.pg@gmail.com> 2013-03-01 22:15:23 PST ---
(In reply to comment #6)
> 2. In expr.aFieldVariable, if expr is just a variable that needs this, the "need this" error for aFieldVariable access is specially delayed.
> 
>   This is more specialized 'exception' than #1.
>   The chain of field access like following would be accepted by this.
> 
>   Type.field1.field2.field3.staticFieldOrFunction

Why it is explicitly allowed? The reason of rule #2 is "a variable access can be regarded as a symbol access". For example, symbol access is already allowed in template argument.

template X(alias symbol) {}
struct S {
    T field1;
    struct T { int field2; }
}
void main() {
    alias x = X!(S.field1.field2);     // access symbol S.T.field2
    auto y = S.field1.field2.offsetof; // access symbol S.T.field2
}

This is consistent behavior.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9630



--- Comment #12 from Vladimir Panteleev <thecybershadow@gmail.com> 2013-03-02 08:17:28 EET ---
OK, I'm clearly in over my head so I'll take your word for it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9630



--- Comment #13 from Kenji Hara <k.hara.pg@gmail.com> 2013-03-01 22:27:27 PST ---
(In reply to comment #10)
> > auto x = typeof(arr.map!(x => x*2).filter!(x > 4).array[0]).max;
> 
> Well, I don't know about how this fits with backwards compatibility and such, but the above line looks wrong to me as well, since it's passing a non-existent variable (arr) to a function (map). This is as much "runtime evaluated" as taking its index.

Using non-static variable directly under the typeof should be allowed.
If you use 'typeof', you means "I want to just get the type of specified
expression, and does not consider whether the expression can be evaluate in
runtime." In this point, D accepts it explicitly.

Moreover, that is necessary for the use at out of function scope.

struct S {
    int field1;
    typeof(field1) field2;  // field1 access has no "valid this", but allowed
    static void foo() {
        typeof(field1) x;   // field1 access has no "valid this", but allowed
    }
}

This is also consistent behavior.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9630


Kenji Hara <k.hara.pg@gmail.com> changed:

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


--- Comment #14 from Kenji Hara <k.hara.pg@gmail.com> 2013-03-01 22:29:36 PST ---
(In reply to comment #12)
> OK, I'm clearly in over my head so I'll take your word for it.

Thanks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9630


bearophile_hugs@eml.cc changed:

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


--- Comment #15 from bearophile_hugs@eml.cc 2013-03-02 05:31:13 PST ---
(In reply to comment #2)

> Workaround:
> 
> assert(0 < typeof(i[0]).max);

This is acceptable.


This program:

struct Foo {
    int i[1];
    static void bar() {
        assert(0 < i[0].max);
    }
}


Currently gives:

temp.d(4): Error: need 'this' for i type int[1u].


But is it possible for the error message to suggest your solution to fix the error?

temp.d(4): Error: need 'this' for i type int[1]. Use typeof(i[0]).max instead

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9630



--- Comment #16 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-02 07:24:23 PST ---
(In reply to comment #15)
> Currently gives:
> 
> temp.d(4): Error: need 'this' for i type int[1u].

This is already a bad message. 'i' should be quoted and the wording should be improved:

> temp.d(4): Error: need 'this' for 'i' of type int[1u].

Feel free to open an enhancement for these.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9630



--- Comment #17 from bearophile_hugs@eml.cc 2013-03-02 12:08:43 PST ---
(In reply to comment #16)

> Feel free to open an enhancement for these.

OK, filed as Issue 9635

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
1 2
Next ›   Last »