Index: flang/lib/Semantics/check-io.cpp =================================================================== --- flang/lib/Semantics/check-io.cpp +++ flang/lib/Semantics/check-io.cpp @@ -1171,11 +1171,23 @@ void IoChecker::CheckNamelist(const Symbol &namelist, common::DefinedIo which, parser::CharBlock namelistLocation) const { - const auto &details{namelist.GetUltimate().get()}; - for (const Symbol &object : details.objects()) { - context_.CheckIndexVarRedefine(namelistLocation, object); - if (auto *msg{CheckForBadIoType(object, which, namelistLocation)}) { - evaluate::AttachDeclaration(*msg, namelist); + if (!context_.HasError(namelist)) { + const auto &details{namelist.GetUltimate().get()}; + for (const Symbol &object : details.objects()) { + context_.CheckIndexVarRedefine(namelistLocation, object); + if (auto *msg{CheckForBadIoType(object, which, namelistLocation)}) { + evaluate::AttachDeclaration(*msg, namelist); + } else if (which == common::DefinedIo::ReadFormatted) { + if (auto why{WhyNotDefinable(namelistLocation, namelist.owner(), + DefinabilityFlags{}, object)}) { + context_ + .Say(namelistLocation, + "NAMELIST input group must not contain undefinable item '%s'"_err_en_US, + object.name()) + .Attach(std::move(*why)); + context_.SetError(namelist); + } + } } } } Index: flang/lib/Semantics/resolve-names.cpp =================================================================== --- flang/lib/Semantics/resolve-names.cpp +++ flang/lib/Semantics/resolve-names.cpp @@ -5832,6 +5832,7 @@ ApplyImplicitRules(*symbol); } else if (!ConvertToObjectEntity(*symbol)) { SayWithDecl(name, *symbol, "'%s' is not a variable"_err_en_US); + context().SetError(*groupSymbol); } symbol->GetUltimate().set(Symbol::Flag::InNamelist); details->add_object(*symbol); Index: flang/test/Semantics/resolve40.f90 =================================================================== --- flang/test/Semantics/resolve40.f90 +++ flang/test/Semantics/resolve40.f90 @@ -88,3 +88,11 @@ integer :: nl3 nl2 = 1 end + +subroutine s12(x) + real, intent(in) :: x + namelist /nl/x + !ERROR: NAMELIST input group must not contain undefinable item 'x' + !BECAUSE: 'x' is an INTENT(IN) dummy argument + read(*,nml=nl) +end