You're Doing In-Conditions Wrong
FeepingCreature
feepingcreature at gmail.com
Tue Jul 14 15:37:29 UTC 2020
On Tuesday, 14 July 2020 at 13:37:58 UTC, Steven Schveighoffer
wrote:
> I think you mean, invalid code, not syntax. Invalid syntax will
> not pass the parser.
>
Ah, yes, right.
> But I somewhat disagree. Yes, you can write bad contracts, but
> that is not on the compiler, and can't really be checked by the
> compiler. The compiler enforces the rule by ignoring what the
> derived class does if the parent class passes. It doesn't
> enforce the logic of your contract fits the rule.
>
It can be checked by the compiler just fine at runtime. IMO, this
is what unittests are for.
> However, it is tedious that one has to repeat all the super's
> contract if your additive contract is unrelated.
>
> One possibility is to consider a way to say "everything super
> said and ..."
>
> maybe like:
>
> void foo(int i) in(super.in) in(i > 5) {}
>
> -Steve
That would also be nice, but it would be nice regardless of my
proposal.
More information about the Digitalmars-d
mailing list