5039 – Cannot use invariant() with auto methods

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5039 - Cannot use invariant() with auto methods
Summary: Cannot use invariant() with auto methods
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
Depends on:
Blocks: 7337
Show dependency tree / graph
Reported: 2010年10月11日 01:04 UTC by Austin Hastings
Modified: 2012年05月02日 20:41 UTC (History)
3 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Austin Hastings 2010年10月11日 01:04:38 UTC
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 Kenji Hara 2011年07月14日 04:29:09 UTC
https://github.com/D-Programming-Language/dmd/pull/147 
Comment 2 github-bugzilla 2012年05月02日 18:25:34 UTC
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


AltStyle によって変換されたページ (->オリジナル) /