I'm running into an issue where I have two subforms with username/password fields, which are required, and depending on the way I fill these fields, the error messages get messed up.

Lets say I just fill "username" field in the first form, and fill nothing in the second one. After validation, I see two messages "Password field is required". It means it is duplicating password field error message and it is not showing username field error message.

Here is why I think it happens: if you go to line 872 of alpha2 release, you can see this piece of code:

$_SESSION['messages']['error'] += $subform_element['#subform_error_messages'];

At this moment, $_SESSION['messages']['error'] is an array with a single element, "Password field is required", while $subform_element['#subform_error_messages'] is an array with two elements, "Username field is required" and "Password field is required". By merging both arrays in this way, the first "Password field is required" message overwrites "Username field is required", causing this issue I'm having.

A possible fix is to array_merge both arrays, then remove duplicates by using array_unique:

$_SESSION['messages']['error'] = array_unique(array_merge($_SESSION['messages']['error'], $subform_element['#subform_error_messages']));

Has anyone faced a similar issue?