Bug 5039 – Cannot use invariant() with auto methods

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-11T01:04:00Z
Last change time
2012-05-02T20:41:52Z
Keywords
contracts, patch, rejects-valid
Assigned to
nobody
Creator
ah08010-d
Blocks
7337

Comments

Comment #0 by ah08010-d — 2010-10-11T01:04:38Z
This code: ========== module scratch; class C { int x; invariant() { assert( x < int.max ); } auto foo() { return x; } } ========= Reports this error: $ dmd scratch.d scratch.d(10): Error: function scratch.C.foo post conditions are not supported if the return type is inferred Removing the invariant eliminates the error message. Converting the 'auto' to an explicit return type eliminates the error message. Given that the compiler must eventually figure out the return type of the method, I have no idea why this error is occurring.
Comment #1 by k.hara.pg — 2011-07-14T04:29:09Z
Comment #2 by github-bugzilla — 2012-05-02T18:25:34Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd 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