Index: flang/lib/Semantics/expression.cpp =================================================================== --- flang/lib/Semantics/expression.cpp +++ flang/lib/Semantics/expression.cpp @@ -1817,6 +1817,12 @@ if (context_.HasError(sym)) { return std::nullopt; } + if (!IsProcedure(*sym)) { + AttachDeclaration( + Say(sc.component.source, "'%s' is not a procedure"_err_en_US, + sc.component.source), + *sym); + } if (auto *dtExpr{UnwrapExpr>(*base)}) { if (sym->has()) { AdjustActuals adjustment{ @@ -2081,10 +2087,16 @@ return CalleeAndArguments{ semantics::SymbolRef{*symbol}, std::move(arguments)}; } - } else { + } else if (IsProcedure(*symbol)) { return CalleeAndArguments{ ProcedureDesignator{*symbol}, std::move(arguments)}; } + if (!context_.HasError(*symbol)) { + AttachDeclaration( + Say(name.source, "'%s' is not a callable procedure"_err_en_US, + name.source), + *symbol); + } } else if (std::optional specificCall{ context_.intrinsics().Probe( CallCharacteristics{ Index: flang/lib/Semantics/resolve-names.cpp =================================================================== --- flang/lib/Semantics/resolve-names.cpp +++ flang/lib/Semantics/resolve-names.cpp @@ -6161,16 +6161,10 @@ symbol = &MakeSymbol(context().globalScope(), name.source, Attrs{}); } Resolve(name, *symbol); - if (symbol->has()) { - SayWithDecl(name, *symbol, - "Use of '%s' as a procedure conflicts with its declaration"_err_en_US); - return; - } if (!symbol->attrs().test(Attr::INTRINSIC)) { - if (!CheckImplicitNoneExternal(name.source, *symbol)) { - return; + if (CheckImplicitNoneExternal(name.source, *symbol)) { + MakeExternal(*symbol); } - MakeExternal(*symbol); } ConvertToProcEntity(*symbol); SetProcFlag(name, *symbol, flag); Index: flang/test/Semantics/call19.f90 =================================================================== --- /dev/null +++ flang/test/Semantics/call19.f90 @@ -0,0 +1,34 @@ +! RUN: %S/test_errors.sh %s %t %flang_fc1 +! Ensures that things that aren't procedures aren't allowed to be called. +module m + integer :: i + integer, pointer :: ip + type :: t + end type + type :: pdt(k,len) + integer, kind :: k + integer, len :: len + end type + type(pdt(1,2)) :: x + namelist /nml/i + contains + subroutine s(d) + real d + !ERROR: 'm' is not a callable procedure + call m + !ERROR: Cannot call function 'i' like a subroutine + call i + !ERROR: Cannot call function 'ip' like a subroutine + call ip + !ERROR: 't' is not a callable procedure + call t + !ERROR: 'k' is not a procedure + call x%k + !ERROR: 'len' is not a procedure + call x%len + !ERROR: Use of 'nml' as a procedure conflicts with its declaration + call nml + !ERROR: Cannot call function 'd' like a subroutine + call d + end subroutine +end Index: flang/test/Semantics/resolve09.f90 =================================================================== --- flang/test/Semantics/resolve09.f90 +++ flang/test/Semantics/resolve09.f90 @@ -71,9 +71,9 @@ block import, none integer :: i - !ERROR: Use of 'm' as a procedure conflicts with its declaration + !ERROR: 'm' is not a callable procedure i = m() - !ERROR: Use of 'm' as a procedure conflicts with its declaration + !ERROR: 'm' is not a callable procedure call m() end block end