www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3125] New: statement foreach semantic opApply should be tried if range funcs not satisfied

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

           Summary: statement foreach semantic opApply should be tried if
                    range funcs not satisfied
           Product: D
           Version: 2.028
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: davidl 126.com


in ForeachStatement::semantic

should be:
        Dsymbol *shead = search_function(ad, idhead);
        if (!shead || !search_function(ad, idnext) || !search_function(ad,
Id::Fempty) )
        goto Lapply;

only try to apply range semantic when all prerequisite func available. 

This makes easier to port legacy code to d2. People won't try to figure why it
tries to call the func called empty/next which doesn't provided in my aggregate
however the func named head had been accidentally added.

This could block tango CircularList

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





--- Comment #1 from david <davidl 126.com>  2009-07-02 01:19:48 PDT ---
why not create something like IUnknown?
e.g. IRange

all classes inherited from IRange get the tag of being a range class.

This is less hackish of testting funcs.

IRange can enforces users to provide those funcs. 
If there're some problems for optimization, IRange can still be an empty
interface for hinting the compiler or treated specially.

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





--- Comment #2 from Sobirari Muhomori <maxmo pochta.ru>  2009-07-02 01:55:05
PDT ---
There was a discussion on introducing concepts to D.

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com




--- Comment #3 from Walter Bright <bugzilla digitalmars.com>  2009-07-02
17:47:19 PDT ---
I need an example, please, as I can't reproduce the problem.

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





--- Comment #4 from david <davidl 126.com>  2009-07-02 19:52:44 PDT ---
Here it is:

class c
{
        int head()
        {
                return 0;
        }
        int opApply(int delegate(ref int x) dg)
        {
                int i;
                i=3;
                dg(i);
                return 1;
        }
}

void main()
{
        c c;
        c= new c;
        foreach(m;c)
        {
                assert(m==3);
        }
}

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


Jarrett Billingsley <jarrett.billingsley gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jarrett.billingsley gmail.c
                   |                            |om




--- Comment #5 from Jarrett Billingsley <jarrett.billingsley gmail.com> 
2009-07-02 20:37:27 PDT ---
(In reply to comment #4)
 Here it is:
 
 class c
 {
         int head()
         {
                 return 0;
         }
         int opApply(int delegate(ref int x) dg)
         {
                 int i;
                 i=3;
                 dg(i);
                 return 1;
         }
 }
 
 void main()
 {
         c c;
         c= new c;
         foreach(m;c)
         {
                 assert(m==3);
         }
 }

You fail it. The error from this code is not related to the reported bug at all. The lines
         c c;
         c= new c;

are illegal. If you change it to
         c c = new c;

it works fine in 2.029. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 02 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3125


Walter Bright <bugzilla digitalmars.com> changed:

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




--- Comment #6 from Walter Bright <bugzilla digitalmars.com>  2009-07-03
00:55:17 PDT ---
I'll close this for now as "WORKSFORME". Please reopen if there's a
reproducible test case.

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


Koroskin Denis <2korden gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |2korden gmail.com




--- Comment #7 from Koroskin Denis <2korden gmail.com>  2009-07-03 01:29:00 PDT
---
Perhaps, it is a duplicate of issue 2984

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