fix mask return-type contract regression and add correctness guard for (#47019)