Ticket #359 (new defect)
Confusing interaction between Object? instance and bools
Reported by: | nerdzero | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | Cobra Compiler | Version: | 0.9.6 |
Keywords: | truthiness | Cc: |
Description
reported-by: kobi7
The last assertion in the following program fails
class NilableObjectAsBool def main shouldBeFalse as Object? = false assert shouldBeFalse == false shouldBeTrue = not shouldBeFalse assert shouldBeTrue == true
The value of shouldBeTrue actually ends up being 'false'. This is probably because the nilable object has a non-nil value so 'not shouldBeFalse' is returning false.
This is confusing when just examining the code especially if the type of the local variable is inferred from a method call that returns an Object?, It also confusing when adding 'assert shouldBeFalse == not shouldBeFalse' to the program and the assertion passes.
This may be by design or unfixable in which case this ticket can be closed.
Change History
Note: See
TracTickets for help on using
tickets.