Thread overview
[Issue 7453] Can't return value from within opApply
Apr 20, 2012
Andrej Mitrovic
Apr 20, 2012
Kenji Hara
Apr 20, 2012
Walter Bright
April 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7453



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-04-19 19:07:56 PDT ---
The second sample is fixed because it was a bug in dirEntry's opApply function.

There's just one thing left:

import std.file;

void main(){
    // Error: long has no effect in expression (0)
    foreach (_; dirEntries(".", SpanMode.shallow)) {
        return;
    }
}

void test() {
    // works fine
    foreach (_; dirEntries(".", SpanMode.shallow)) {
        return;
    }
}

Why does the return fail if we're in main()?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7453


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |pull, rejects-valid


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-04-20 01:37:22 PDT ---
Reduced test case:

struct S {
    int opApply(int delegate(string) dg) {
        return 0;
    }
}
void main() {
    foreach (_; S()) {
        return;
        // Error: long has no effect in expression (0)
        // test.d(8): Error: cannot return non-void from void function
    }
}

Pull request: https://github.com/D-Programming-Language/dmd/pull/892

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7453



--- Comment #3 from github-bugzilla@puremagic.com 2012-04-20 12:04:41 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/4d28102c7a20341db6239bd843f406d6a5a45725 fix Issue 7453 - Can't return value from within opApply

Inside main function, and after first semantic, ReturnStatement::exp is filled with IntegerExp(0). Then in second semantic, implicit0 doesn't become 1, and error occurs.

ReturnStatement object should keep implicit0 value for repeating
call of semantic().

https://github.com/D-Programming-Language/dmd/commit/03e8c2656d03c90cd2bda72abb8b6392556f1017 Merge pull request #892 from 9rnsr/fix7453

Issue 7453 - Can't return value from within opApply

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7453


Walter Bright <bugzilla@digitalmars.com> changed:

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


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