Bug 5204 – Inherited out contract requires lvalue result?
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2010-11-11T16:04:00Z
Last change time
2012-12-28T04:59:47Z
Keywords
contracts, pull, rejects-valid
Assigned to
nobody
Creator
ah08010-d
Comments
Comment #0 by ah08010-d — 2010-11-11T16:04:09Z
Using 2049, this code:
==========
module scratch;
interface collection( ValueT ) {
alias collection!( ValueT ) collection_t;
collection_t clear()
out( result ) { assert( result.length == 0 ); }
@property size_t length();
}
interface mapping( KeyT, ValueT ) : collection!( ValueT ) { /* ... */ }
class aamap( KeyT, ValueT ) : mapping!( KeyT, ValueT ) {
alias aamap!( KeyT, ValueT ) aamap_t;
aamap_t clear( ) { return this; }
}
void main() {
alias aamap!( string, int ) aa_str2int;
}
==========
produces these diagnostics:
==========
$ dmd -run scratch.d
scratch.d(15): Error: cast(collection)__result is not an lvalue
scratch.d(19): Error: template instance scratch.aamap!(string,int) error instantiating
==========
As I understand it, I should be able to code a function like int foo() { return 1+1;} and have an out contract attached. So I don't understand why there is any consideration of the result ever being an lvalue.
Comment #1 by bearophile_hugs — 2010-11-11T17:20:30Z
This may be a reduced test case:
interface IFoo {
IFoo bar()
out {}
}
class Foo : IFoo {
Foo bar() { return null; }
}
void main() {}