Wiki

Ticket #4 (closed defect: fixed)

Opened 10 years ago

Last modified 10 years ago

Don't allow assignment in an assert

Reported by: Chuck.Esterbrook Owned by: Chuck
Priority: major Milestone:
Component: Cobra Workspace Version: 0.7.4
Keywords: Cc:

Description

Asserts should have no side effects as they may be excluded (-include-asserts:no or -turbo). Particularly, the top level expression should not be an assignment as this is usually just a typo where the programmer meant to say "x == y", not "x = y". This often gives a warning:

warning: The expression "..." (of type "...") will always evaluate to true because it is not nilable. You can remove the expression.

It should always give an error with a more appropriate message.

Attachments

assert-assign.patch Download (4.5 KB) - added by hopscc 10 years ago.

Change History

Changed 10 years ago by hopscc

  • owner set to hopscc
  • status changed from new to assigned

Changed 10 years ago by hopscc

Changed 10 years ago by hopscc

I'm providing patch to fix this.

Assignments as an assert condition generate an error
Conditions that generate a 'always true cos not nilable' warning have
the warning message augmented with corrections specific to an assert ( the actual wording of this could probably be improved)

Changed 10 years ago by hopscc

  • owner changed from hopscc to Chuck

Changed 10 years ago by Chuck

  • status changed from assigned to closed
  • resolution set to fixed

I've made a further enhancement to this that if the condition .willChangeVar then an error will be generated. In addition to a top-level assignment expression, this also covers nested expressions, 'out' parameters and all forms of augmented assignment. See changeset:1545

Note: See TracTickets for help on using tickets.