@@ -376,25 +376,35 @@ static void PropagateSaveAttr(const EquivalenceSet &src, EquivalenceSet &dst) {
376
376
377
377
void EquivalenceSets::AddToSet (const parser::Designator &designator) {
378
378
if (CheckDesignator (designator)) {
379
- Symbol &symbol{*currObject_.symbol };
380
- if (!currSet_.empty ()) {
381
- // check this symbol against first of set for compatibility
382
- Symbol &first{currSet_.front ().symbol };
383
- CheckCanEquivalence (designator.source , first, symbol) &&
384
- CheckCanEquivalence (designator.source , symbol, first);
385
- }
386
- auto subscripts{currObject_.subscripts };
387
- if (subscripts.empty () && symbol.IsObjectArray ()) {
388
- // record a whole array as its first element
389
- for (const ShapeSpec &spec : symbol.get <ObjectEntityDetails>().shape ()) {
390
- auto &lbound{spec.lbound ().GetExplicit ().value ()};
391
- subscripts.push_back (evaluate::ToInt64 (lbound).value ());
379
+ if (Symbol * symbol{currObject_.symbol }) {
380
+ if (!currSet_.empty ()) {
381
+ // check this symbol against first of set for compatibility
382
+ Symbol &first{currSet_.front ().symbol };
383
+ CheckCanEquivalence (designator.source , first, *symbol) &&
384
+ CheckCanEquivalence (designator.source , *symbol, first);
385
+ }
386
+ auto subscripts{currObject_.subscripts };
387
+ if (subscripts.empty ()) {
388
+ if (const ArraySpec * shape{symbol->GetShape ()};
389
+ shape && shape->IsExplicitShape ()) {
390
+ // record a whole array as its first element
391
+ for (const ShapeSpec &spec : *shape) {
392
+ if (auto lbound{spec.lbound ().GetExplicit ()}) {
393
+ if (auto lbValue{evaluate::ToInt64 (*lbound)}) {
394
+ subscripts.push_back (*lbValue);
395
+ continue ;
396
+ }
397
+ }
398
+ subscripts.clear (); // error recovery
399
+ break ;
400
+ }
401
+ }
392
402
}
403
+ auto substringStart{currObject_.substringStart };
404
+ currSet_.emplace_back (
405
+ *symbol, subscripts, substringStart, designator.source );
406
+ PropagateSaveAttr (currSet_.back (), currSet_);
393
407
}
394
- auto substringStart{currObject_.substringStart };
395
- currSet_.emplace_back (
396
- symbol, subscripts, substringStart, designator.source );
397
- PropagateSaveAttr (currSet_.back (), currSet_);
398
408
}
399
409
currObject_ = {};
400
410
}
0 commit comments