enforcing alias this on derived types

John Colvin john.loughran.colvin at gmail.com
Mon Jul 8 06:16:40 PDT 2013


On Monday, 8 July 2013 at 11:37:31 UTC, JS wrote:
> On Monday, 8 July 2013 at 09:55:29 UTC, John Colvin wrote:
>> On Monday, 8 July 2013 at 09:52:44 UTC, John Colvin wrote:
>>> Most other solutions I tried failed because the compiler 
>>> evaluates the check (e.g. out contracts) in the interface, 
>>> which makes the check either semantically wrong, or 
>>> statically false/failed.
>>
>> Woops, should be "the contract exists in the scope of the 
>> interface", not "the compiler evaluates the check (e.g. out 
>> contracts) in the interface"
>
> Hopefully there is a cleaner way but this beats nothing... 
> thanks.

There could be merit in adding more sophisticated requirements in 
base classes and interfaces. Currently, AFAIK there isn't one.

inherited "static invariant() {}" would be one possibility, run 
at compile-time. Perhaps only run on classes that can be 
explicitly instantiated, but declared in any class/interface 
further up the inheritance tree. All static invariants would have 
to pass, in derived and base classes, i.e. it's a tighten-only 
contract like out.

It's a unittest of sorts, but compile-time and fully class-aware.


More information about the Digitalmars-d-learn mailing list