diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h --- a/flang/include/flang/Semantics/symbol.h +++ b/flang/include/flang/Semantics/symbol.h @@ -255,11 +255,13 @@ std::map &finals() { return finals_; } const std::map &finals() const { return finals_; } bool isForwardReferenced() const { return isForwardReferenced_; } + bool isDefined() const { return isDefined_; } void add_paramName(const SourceName &name) { paramNames_.push_back(name); } void add_paramDecl(const Symbol &symbol) { paramDecls_.push_back(symbol); } void add_component(const Symbol &); void set_sequence(bool x = true) { sequence_ = x; } void set_isForwardReferenced() { isForwardReferenced_ = true; } + void set_isDefined() { isDefined_ = true; } const std::list &componentNames() const { return componentNames_; } @@ -290,6 +292,7 @@ std::map finals_; // FINAL :: subr bool sequence_{false}; bool isForwardReferenced_{false}; + bool isDefined_{false}; friend llvm::raw_ostream &operator<<( llvm::raw_ostream &, const DerivedTypeDetails &); }; diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -833,6 +833,10 @@ void CheckHelper::CheckDerivedType( const Symbol &derivedType, const DerivedTypeDetails &details) { + if (!details.isDefined() && !context_.HasError(derivedType)) { + messages_.Say("The derived type '%s' has not been defined"_err_en_US, + derivedType.name()); + } const Scope *scope{derivedType.scope()}; if (!scope) { CHECK(details.isForwardReferenced()); diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -3953,6 +3953,7 @@ CHECK(scope.symbol()); CHECK(scope.symbol()->scope() == &scope); auto &details{scope.symbol()->get()}; + details.set_isDefined(); std::set paramNames; for (auto ¶mName : std::get>(stmt.statement.t)) { details.add_paramName(paramName.source); diff --git a/flang/lib/Semantics/type.cpp b/flang/lib/Semantics/type.cpp --- a/flang/lib/Semantics/type.cpp +++ b/flang/lib/Semantics/type.cpp @@ -244,6 +244,7 @@ foldingContext.messages().Say(typeSymbol_.name(), "The derived type '%s' was forward-referenced but not defined"_err_en_US, typeSymbol_.name()); + context.SetError(typeSymbol_); return; } EvaluateParameters(context); diff --git a/flang/test/Semantics/bad-forward-type.f90 b/flang/test/Semantics/bad-forward-type.f90 --- a/flang/test/Semantics/bad-forward-type.f90 +++ b/flang/test/Semantics/bad-forward-type.f90 @@ -90,3 +90,10 @@ integer, kind :: n = 3 end type end subroutine s9 + +subroutine s10 + type t + !ERROR: The derived type 'undef' has not been defined + type(undef), pointer :: y + end type +end subroutine s10