codetools: var completion of for-var-in-genericarray, from Pascal Riekenberg, issue #37076

git-svn-id: branches/fixes_2_0@63496 -
This commit is contained in:
mattias 2020-07-03 10:23:06 +00:00
parent 0dac7c0aa2
commit b56730e824
2 changed files with 37 additions and 23 deletions

View File

@ -844,7 +844,8 @@ type
function FindEnumerationTypeOfSetType(SetTypeNode: TCodeTreeNode;
out Context: TFindContext): boolean;
function FindElementTypeOfArrayType(ArrayNode: TCodeTreeNode;
out ExprType: TExpressionType; AliasType: PFindContext): boolean;
out ExprType: TExpressionType; AliasType: PFindContext;
ParentParams: TFindDeclarationParams = nil): boolean;
function CheckOperatorEnumerator(Params: TFindDeclarationParams;
const FoundContext: TFindContext): TIdentifierFoundResult;
function CheckModifierEnumeratorCurrent({%H-}Params: TFindDeclarationParams;
@ -12748,7 +12749,7 @@ function TFindDeclarationTool.FindForInTypeAsString(TermPos: TAtomPosition;
begin
AliasType:=CleanFindContext;
if SubExprType.Context.Tool.FindElementTypeOfArrayType(
SubExprType.Context.Node,ExprType,@AliasType)
SubExprType.Context.Node,ExprType,@AliasType,Params)
then begin
Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,@AliasType);
end;
@ -13145,7 +13146,7 @@ end;
function TFindDeclarationTool.FindElementTypeOfArrayType(
ArrayNode: TCodeTreeNode; out ExprType: TExpressionType;
AliasType: PFindContext): boolean;
AliasType: PFindContext; ParentParams: TFindDeclarationParams): boolean;
var
Params: TFindDeclarationParams;
p: LongInt;
@ -13156,6 +13157,14 @@ begin
if (ArrayNode=nil) then exit;
if (ArrayNode.Desc<>ctnOpenArrayType) and (ArrayNode.Desc<>ctnRangedArrayType)
then exit;
if (ArrayNode.Parent <> nil)
and (ArrayNode.Parent.Desc = ctnGenericType)
and (ParentParams <> nil) then begin
ExprType.Desc := xtContext;
ExprType.Context.Node := ParentParams.GenParamValueMappings.SpecializeParamsNode.FirstChild;
ExprType.Context.Tool := ParentParams.GenParamValueMappings.SpecializeParamsTool;
Result:=true;
end else begin
MoveCursorToNodeStart(ArrayNode);
ReadNextAtom; // array
if not UpAtomIs('ARRAY') then exit;
@ -13179,6 +13188,7 @@ begin
Params.Free;
end;
end;
end;
function TFindDeclarationTool.CheckOperatorEnumerator(
Params: TFindDeclarationParams; const FoundContext: TFindContext

View File

@ -111,6 +111,8 @@ type
TOL3 = TOL2;
TOL4 = class(TOL2);
generic TArray<T> = array of T;
var
OL_P1_1: TOL_P1_1;
OL_P1_2: TOL_P1_2;
@ -124,6 +126,7 @@ var
OL2: TOL2;
OL3: TOL3;
OL4: TOL4;
A: specialize TArray<TObj>;
begin
for o_p1_1{guesstype:TObj} in OL_P1_1 do ;
@ -138,6 +141,7 @@ begin
for o2{guesstype:TObj} in OL2 do ;
for o3{guesstype:TObj} in OL3 do ;
for o4{guesstype:TObj} in OL4 do ;
for i{guesstype:TObj} in A do;
end.