If the consideration or object is partially unlawful, the following rules will be applicable in such cases:

1.    If any part of a single consideration for one or more objects, or any one or any part of any one or several considerations for a single object, is unlawful, the agreement is void.

Example-
A promises to superintend, on behalf of B, a legal manufacture of indigo; and an illegal traffic in other articles. B promises to pay A salary of 10000 rupees a year. The agreement is void, the object of A’s promise and the consideration for B’s promise is in part unlawful. (Illustration to section 24).
      
Case-
A agrees to serve B as his housekeeper and also to leave the adultery with him at a fixed salary. The whole agreement is unlawful and void. A cannot sue even for service rendered as housekeeper because it cannot be ascertained as to what was due on account of adulterous intercourse and what was due for housekeeping. Alice Mary Hill v. William Clarke,(1905), 27 All. 266   


2.    Where there reciprocal promise to do things legal and also other things illegal, and the legal part can be separated from the illegal part (i.e. there is a separate consideration for different promises), the legal part is a contract and the illegal part is avoid agreement. (Section 57).

Example-
A and B agree that A shall sell B a house for Rs.10000 but if B uses it as a gambling house, he shall pay a Rs. 50000 for it. The first part of the agreement is valid and the second part is invalid.

3.    In the case of alternative promise, one branch of which is legal and the other illegal, the legal branch alone can be enforced. (Section 58)

Example-
A and B agree that, A shall pay Rs.1000 for which B shall afterwards deliver to A, either rice or smuggled opium. This is a valid contract to deliver rice and a void agreement as to opium.