@@ -4048,27 +4048,10 @@ void SubprogramVisitor::CreateEntry(
4048
4048
attrs = extant->attrs ();
4049
4049
}
4050
4050
}
4051
- bool badResultName{false };
4052
4051
std::optional<SourceName> distinctResultName;
4053
4052
if (suffix && suffix->resultName &&
4054
4053
suffix->resultName ->source != entryName.source ) {
4055
4054
distinctResultName = suffix->resultName ->source ;
4056
- const parser::Name &resultName{*suffix->resultName };
4057
- if (resultName.source == subprogram.name ()) { // C1574
4058
- Say2 (resultName.source ,
4059
- " RESULT(%s) may not have the same name as the function" _err_en_US,
4060
- subprogram, " Containing function" _en_US);
4061
- badResultName = true ;
4062
- } else if (const Symbol * extant{FindSymbol (outer, resultName)}) { // C1574
4063
- if (const auto *details{extant->detailsIf <SubprogramDetails>()}) {
4064
- if (details->entryScope () == &currScope ()) {
4065
- Say2 (resultName.source ,
4066
- " RESULT(%s) may not have the same name as an ENTRY in the function" _err_en_US,
4067
- extant->name (), " Conflicting ENTRY" _en_US);
4068
- badResultName = true ;
4069
- }
4070
- }
4071
- }
4072
4055
}
4073
4056
if (outer.IsModule () && !attrs.test (Attr::PRIVATE)) {
4074
4057
attrs.set (Attr::PUBLIC);
@@ -4104,17 +4087,24 @@ void SubprogramVisitor::CreateEntry(
4104
4087
EntityDetails resultDetails;
4105
4088
resultDetails.set_funcResult (true );
4106
4089
if (distinctResultName) {
4107
- if (!badResultName) {
4108
- // RESULT(x) can be the same explicitly-named RESULT(x) as
4109
- // the enclosing function or another ENTRY.
4110
- if (auto iter{currScope ().find (suffix->resultName ->source )};
4111
- iter != currScope ().end ()) {
4112
- result = &*iter->second ;
4113
- }
4114
- if (!result) {
4115
- result = &MakeSymbol (
4116
- *distinctResultName, Attrs{}, std::move (resultDetails));
4117
- }
4090
+ // An explicit RESULT() can also be an explicit RESULT()
4091
+ // of the function or another ENTRY.
4092
+ if (auto iter{currScope ().find (suffix->resultName ->source )};
4093
+ iter != currScope ().end ()) {
4094
+ result = &*iter->second ;
4095
+ }
4096
+ if (!result) {
4097
+ result =
4098
+ &MakeSymbol (*distinctResultName, Attrs{}, std::move (resultDetails));
4099
+ } else if (!result->has <EntityDetails>()) {
4100
+ Say (*distinctResultName,
4101
+ " ENTRY cannot have RESULT(%s) that is not a variable" _err_en_US,
4102
+ *distinctResultName)
4103
+ .Attach (result->name (), " Existing declaration of '%s'" _en_US,
4104
+ result->name ());
4105
+ result = nullptr ;
4106
+ }
4107
+ if (result) {
4118
4108
Resolve (*suffix->resultName , *result);
4119
4109
}
4120
4110
} else {
@@ -4124,8 +4114,7 @@ void SubprogramVisitor::CreateEntry(
4124
4114
entryDetails.set_result (*result);
4125
4115
}
4126
4116
}
4127
- if (subpFlag == Symbol::Flag::Subroutine ||
4128
- (distinctResultName && !badResultName)) {
4117
+ if (subpFlag == Symbol::Flag::Subroutine || distinctResultName) {
4129
4118
Symbol &assoc{MakeSymbol (entryName.source )};
4130
4119
assoc.set_details (HostAssocDetails{*entrySymbol});
4131
4120
assoc.set (Symbol::Flag::Subroutine);
0 commit comments