D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4785 - auto return of a function with in contract
Summary: auto return of a function with in contract
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: contracts, patch, rejects-valid
: 7060 (view as issue list)
Depends on:
Blocks:
 
Reported: 2010-09-01 10:38 UTC by bearophile_hugs
Modified: 2012-05-02 20:40 UTC (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-09-01 10:38:41 UTC
auto foo()
    in {}
    body { return 0; }
void main() {
    foo();
}


DMD 2.048 prints:
test.d(2): no identifier for declarator foo
test.d(2): semicolon expected, not 'in'
test.d(2): Declaration expected, not 'in'
test.d(3): unrecognized declaration
Comment 1 jens.k.mueller 2011-03-30 10:29:23 UTC
I also hit this bug but on Linux and I suppose it fails on all platforms.

My test code is

auto foo()
body { // does not compile if body is specified
    return 0;
}

void main() {}

It fails with latest dmd (v2.052)
test.d(2): function declaration without return type. (Note that constructors are always named 'this')
test.d(2): no identifier for declarator foo()

This bug makes using contracts and auto return type impossible. Maybe it's importance should therefore be increased.
Comment 2 kennytm 2011-04-20 12:03:17 UTC
Maybe issue 5867 is the same as this.
Comment 3 Maksim Zholudev 2011-06-10 06:53:11 UTC
DMD v2.053 on Linux do not accept the following code:

----------
auto F1() {return 0;} // OK

int F2() body {return 0;} // OK

auto F3() body {return 0;} // ERROR: function declaration without return type...

void main()
{
   F1();
   F2();
   F3();
}
----------
Comment 5 Kenji Hara 2011-12-03 10:04:27 UTC
*** Issue 7060 has been marked as a duplicate of this issue. ***
Comment 6 SomeDude 2012-04-21 15:34:01 UTC
DMD 2.059:

PS E:\DigitalMars\dmd2\samples> rdmd bug.d
bug.d(1): function declaration without return type. (Note that constructors are
always named 'this')
bug.d(2): no identifier for declarator foo()
PS E:\DigitalMars\dmd2\samples>
Comment 7 bearophile_hugs 2012-04-24 18:32:31 UTC
I hope the patch will be merged in some more months.
Comment 8 github-bugzilla 2012-05-02 18:25:29 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/bd0e45f56f869da03baf89d8b530a9a2afc5f561
Issue 4785 - auto return of a function with in contract

https://github.com/D-Programming-Language/dmd/commit/007b936e0970666c7698ad7c3b2c2b3da2d8cbc0
Merge pull request #147 from 9rnsr/fix4785

Issue 4785 & 5039 Allow auto return function with contracts