@@ -685,18 +685,29 @@ ScState::getValue(const SValue& lval, SValue& rval, bool deReference,
685685
686686 // For array access at unknown index any element could be accessed
687687 if (isArr && unkwIndex) {
688- switch (returnUnknown) {
689- case ArrayUnkwnMode::amNoValue:
690- rval = NO_VALUE;
691- return std::pair<bool , bool >(false , false );
692-
693- case ArrayUnkwnMode::amArrayUnknown:
694- rval = llval;
695- return std::pair<bool , bool >(true , true );
696-
697- case ArrayUnkwnMode::amFirstElement:
698- llval = getFirstArrayElementForAny (llval);
699- break ;
688+ bool unkwIndexRec = false ;
689+ if (returnUnknown == ArrayUnkwnMode::amFirstElementRec) {
690+ getBottomArrayForAny (llval, unkwIndexRec, 0 , true );
691+ }
692+
693+ if (unkwIndexRec) {
694+ llval = getFirstArrayElementForAny (llval);
695+
696+ } else {
697+ switch (returnUnknown) {
698+ case ArrayUnkwnMode::amNoValue:
699+ case ArrayUnkwnMode::amFirstElementRec:
700+ rval = NO_VALUE;
701+ return std::pair<bool , bool >(false , false );
702+
703+ case ArrayUnkwnMode::amArrayUnknown:
704+ rval = llval;
705+ return std::pair<bool , bool >(true , true );
706+
707+ case ArrayUnkwnMode::amFirstElement:
708+ llval = getFirstArrayElementForAny (llval);
709+ break ;
710+ }
700711 }
701712 }
702713
@@ -1438,9 +1449,10 @@ bool ScState::isArray(const SValue& val, bool& unkwIndex) const
14381449// Get bottommost array for given value which can be element in array or
14391450// field in record array element.
14401451// \param unkwIndex -- unknown index for bottommost array
1452+ // \param checkRecOnly -- provide unkwIndex for record/MIF array only
14411453// \return bottom array value or NO_VALUE
14421454SValue ScState::getBottomArrayForAny (const SValue& eval, bool & unkwIndex,
1443- unsigned crossModule) const
1455+ unsigned crossModule, bool checkRecOnly ) const
14441456{
14451457 // cout << "getBottomArrayForAny eval " << eval << endl;
14461458
@@ -1452,6 +1464,14 @@ SValue ScState::getBottomArrayForAny(const SValue& eval, bool& unkwIndex,
14521464 unkwIndex = false ;
14531465 for (const SValue& mval : valStack) {
14541466 if (mval.isArray ()) {
1467+ if (checkRecOnly) {
1468+ QualType elmtype = getArrayElementType (mval.getType ());
1469+ if (isPointer (elmtype)) {
1470+ elmtype = elmtype->getPointeeType ();
1471+ }
1472+ if (!isScModularInterface (elmtype) &&
1473+ !isUserDefinedClass (elmtype)) continue ;
1474+ }
14551475 unkwIndex = unkwIndex || mval.getArray ().isUnknown ();
14561476 }
14571477 }
0 commit comments