Fixing CARBON-14782, and addding testcases.

Signed-off-by: Jayanga Dissanayake <jsdjayanga@yahoo.com>