[swift-evolution] Proposal: Initialization should not be required in precondition(false) case.

Dmitri Gribenko gribozavr at gmail.com
Fri Feb 12 11:24:17 CST 2016


On Fri, Feb 12, 2016 at 9:15 AM, Amir Michail via swift-evolution
<swift-evolution at swift.org> wrote:
>
>> On Feb 12, 2016, at 12:09 PM, Radosław Pietruszewski <radexpl at gmail.com> wrote:
>>
>> I think what you mean is `fatalError()`.
>>
>> You can’t do what you suggest, because you can’t prove that the expression passed to precondition will evaluate to false. (You theoretically could if the compiler checked for you passing `false`, but that makes no sense. Just go with `fatalError` or `preconditionFailure`.)
>>
>
> What’s wrong with having the compiler explicitly check for “false”?

How far would you require the compiler to go?  precondition(2 < 1)?
precondition(someFunctionThatAlwaysReturnsFalse())?
precondition(isFermatsLastTheoremTrue())?

This is important to define precisely since the answer to this
question changes the set of the programs that the compiler accepts.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list