Skip to content

[flang] Catch attempt to type a subroutine #82704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3709,13 +3709,17 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) {
bool SubprogramVisitor::Pre(const parser::PrefixSpec &x) {
// Save this to process after UseStmt and ImplicitPart
if (const auto *parsedType{std::get_if<parser::DeclarationTypeSpec>(&x.u)}) {
FuncResultStack::FuncInfo &info{DEREF(funcResultStack().Top())};
if (info.parsedType) { // C1543
Say(currStmtSource().value(),
"FUNCTION prefix cannot specify the type more than once"_err_en_US);
if (FuncResultStack::FuncInfo * info{funcResultStack().Top()}) {
if (info->parsedType) { // C1543
Say(currStmtSource().value(),
"FUNCTION prefix cannot specify the type more than once"_err_en_US);
} else {
info->parsedType = parsedType;
info->source = currStmtSource();
}
} else {
info.parsedType = parsedType;
info.source = currStmtSource();
Say(currStmtSource().value(),
"SUBROUTINE prefix cannot specify a type"_err_en_US);
}
return false;
} else {
Expand Down
4 changes: 4 additions & 0 deletions flang/test/Semantics/typed-subr.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! ERROR: SUBROUTINE prefix cannot specify a type
integer subroutine foo
end