Skip to content

[flang] Catch structure constructor in its own type definition #102241

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
Aug 8, 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
3 changes: 1 addition & 2 deletions flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3026,8 +3026,7 @@ const Symbol *AssumedTypeDummy<parser::PointerObject>(
bool ExpressionAnalyzer::CheckIsValidForwardReference(
const semantics::DerivedTypeSpec &dtSpec) {
if (dtSpec.IsForwardReferenced()) {
Say("Cannot construct value for derived type '%s' "
"before it is defined"_err_en_US,
Say("Cannot construct value for derived type '%s' before it is defined"_err_en_US,
dtSpec.name());
return false;
}
Expand Down
7 changes: 2 additions & 5 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5507,11 +5507,8 @@ void DeclarationVisitor::Post(const parser::DerivedTypeStmt &x) {
std::optional<DerivedTypeSpec> extendsType{
ResolveExtendsType(name, extendsName)};
DerivedTypeDetails derivedTypeDetails;
if (Symbol * typeSymbol{FindInScope(currScope(), name)}; typeSymbol &&
typeSymbol->has<DerivedTypeDetails>() &&
typeSymbol->get<DerivedTypeDetails>().isForwardReferenced()) {
derivedTypeDetails.set_isForwardReferenced(true);
}
// Catch any premature structure constructors within the definition
derivedTypeDetails.set_isForwardReferenced(true);
auto &symbol{MakeSymbol(name, GetAttrs(), std::move(derivedTypeDetails))};
symbol.ReplaceName(name.source);
derivedTypeInfo_.type = &symbol;
Expand Down
3 changes: 2 additions & 1 deletion flang/test/Semantics/bad-forward-type.f90
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ subroutine s8
!ERROR: Cannot construct value for derived type 't2' before it is defined
parameter(y=t2(12.3))
type t2
real :: c
!ERROR: Cannot construct value for derived type 't2' before it is defined
real :: c = transfer(t2(),0.)
end type
end subroutine

Expand Down
Loading