Good catch @Beliavsky, I agree compilers should have better error messages for this case (I created an issue for LFortran here: Give a better error message when `contains` is missing · Issue #7207 · lfortran/lfortran · GitHub).
I also agree with @sblionel’s comment. For those reasons I think a compiler should not try to guess.
However, I think it can still try to suggest, or even just ask a leading question, to help the user. For example in the above, it could say “help: did you mean to put contains or interface above?” or something like that. Kind of like most modern compilers recommend a different variable name if a misspelling was found (“error: use of undeclared identifier ‘my_it’; did you mean ‘my_int’?”). Users need to learn not to blindly apply such suggestions, but think about if that’s what they meant.