E08274: a negation applied to a negation - word 'not', '~' or unary '-' in any mix, parenthesised or not ('not not b', 'not (not b)', '~~b', '- -x', '-(-x)') - cancels out: write the operand, or a single negation if one was meant
What went wrong
A negation is applied to another negation. Word 'not', '~' and unary '-' are ONE operator, the negation ('_negate'), in three spellings - 'not' is the loose one, '~' and '-' the tight ones - so two of them, in any mix of spellings, cancel out and the expression is just its operand. Parentheses group, they do not change what is negated, so the same with parentheses is the same error. Each of these is E08274:
twice <- not not done //this is 'done' tilde <- ~~done mixed <- not ~done mixedAgain <- ~not done minus <- - -amount //this is 'amount' minusNot <- -not done //Parentheses group; they do not change what is negated grouped <- not (not done) groupedTilde <- ~(~done) groupedMinus <- -(-amount)
That is almost always a slip: a doubled word, or one negation too many left behind by an edit. EK9 cannot know whether you meant the operand or a single negation, so it does not change the source for you.
A chain is reported once, on its outermost negation, with the fix its count gives: an even number of negations is the operand, an odd number is one negation, spelt as the one next to the operand - 'not not not done' is 'not done', '- - -amount' is '-amount'. A negative literal counts too: '- -5' is '5'.
Subtraction is not a negation: '-(first - second)' and 'first - -second' are legal. And '--' is the decrement token, never two negations ('--amount' does not parse; write 'amount--' to decrement).
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 2160 (What is EK9's operator precedence - does 'and' bind tighter than 'or', and where does 'not' sit?)
Each of these is fine:
- //What the double negation meant
- same <- done
- //If a single negation was meant
- flipped <- not done
- //The tight spelling of the same thing
- tight <- ~done
- //A negation of a subtraction
- opposite <- -(first - second)
How to fix it
- Delete both negations and write the operand: 'done', 'amount'.
- Or, if one negation was meant, keep exactly one: 'not done', '~done' or '-amount'.
Common causes
- A doubled word: 'not not ready' typed or pasted twice
- Negating a condition that an earlier edit had already negated, then adding parentheses around it
- Converting '!!x' from JavaScript (a 'to boolean' idiom there; an EK9 Boolean is already one)
- Mixing the spellings, 'not ~flag' or '- ~bits', expecting them to mean different things
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E08274: a negation applied to a negation - word 'not', '~' or unary '-' in any mix, parenthesised or not ('not not b', 'not (not b)', '~~b', '- -x', '-(-x)') - cancels out: write the operand, or a single negation if one was meant
#!ek9 defines module error.e08274.bad defines function stillDone() -> done as Boolean <- rtn as Boolean? rtn: not not done everySpelling() -> done as Boolean amount as Integer twice <- not not done //this is 'done' tilde <- ~~done mixed <- not ~done mixedAgain <- ~not done minus <- - -amount //this is 'amount' minusNot <- -not done //Parentheses group; they do not change what is negated grouped <- not (not done) groupedTilde <- ~(~done) groupedMinus <- -(-amount)
Fixed: Write the operand itself
#!ek9 defines module error.e08274.good defines function stillDone() -> done as Boolean <- rtn as Boolean? rtn: done
Fixed: Write the operand, or exactly one negation; a negated subtraction is fine
#!ek9 defines module error.e08274.good.forms defines function readings() -> done as Boolean first as Integer second as Integer <- rtn as String? //What the double negation meant same <- done //If a single negation was meant flipped <- not done //The tight spelling of the same thing tight <- ~done //A negation of a subtraction opposite <- -(first - second) rtn: `${same} ${flipped} ${tight} ${opposite}`
Questions and answers
These Q&A entries show E08274 and its fix: