Weight gain is a result of eating more calories than you burn on a regular basis, not when you eat. If one gains weight by eating late at night, it is due to the excess calorie intake, not the time of eating. The body’s enzymes cannot tell the time! After 7pm they do not preferentially store carbohydrates as fat. As long as our calorie intake does not exceed the calories expended weight gain will not occur.
However, if you want to avoid bloating, it is best to eat your complex carbohydrates in the evening, eg: vegetables, sweet potatoes, squash etc.