|
@@ -2,7 +2,7 @@
|
|
This file is part of the Free Component Library
|
|
This file is part of the Free Component Library
|
|
|
|
|
|
Pascal resolver
|
|
Pascal resolver
|
|
- Copyright (c) 2019 Mattias Gaertner [email protected]
|
|
|
|
|
|
+ Copyright (c) 2020 Mattias Gaertner [email protected]
|
|
|
|
|
|
See the file COPYING.FPC, included in this distribution,
|
|
See the file COPYING.FPC, included in this distribution,
|
|
for details about the copyright.
|
|
for details about the copyright.
|
|
@@ -25646,9 +25646,19 @@ function TPasResolver.CheckAssignCompatibilityArrayType(const LHS,
|
|
|
|
|
|
procedure CheckRange(ArrType: TPasArrayType; RangeIndex: integer;
|
|
procedure CheckRange(ArrType: TPasArrayType; RangeIndex: integer;
|
|
Values: TPasResolverResult; ErrorEl: TPasElement);
|
|
Values: TPasResolverResult; ErrorEl: TPasElement);
|
|
|
|
+ var
|
|
|
|
+ ElTypeResolved: TPasResolverResult;
|
|
|
|
+
|
|
|
|
+ procedure CheckArrOfCharAssignString;
|
|
|
|
+ begin
|
|
|
|
+ ComputeElement(ArrType.ElType,ElTypeResolved,[rcType]);
|
|
|
|
+ if ElTypeResolved.BaseType in btAllChars then
|
|
|
|
+ Result:=cTypeConversion; // ArrOfChar:=aString
|
|
|
|
+ end;
|
|
|
|
+
|
|
var
|
|
var
|
|
Range, Value, Expr: TPasExpr;
|
|
Range, Value, Expr: TPasExpr;
|
|
- RangeResolved, ValueResolved, ElTypeResolved: TPasResolverResult;
|
|
|
|
|
|
+ RangeResolved, ValueResolved: TPasResolverResult;
|
|
i, ExpectedCount, ValCnt: Integer;
|
|
i, ExpectedCount, ValCnt: Integer;
|
|
IsLastRange, IsConstExpr: Boolean;
|
|
IsLastRange, IsConstExpr: Boolean;
|
|
ArrayValues: TPasExprArray;
|
|
ArrayValues: TPasExprArray;
|
|
@@ -25752,19 +25762,18 @@ function TPasResolver.CheckAssignCompatibilityArrayType(const LHS,
|
|
ExpectedCount:=-1;
|
|
ExpectedCount:=-1;
|
|
if length(ArrType.Ranges)=0 then
|
|
if length(ArrType.Ranges)=0 then
|
|
begin
|
|
begin
|
|
- // dynamic array
|
|
|
|
|
|
+ // dynamic or open array
|
|
if (Expr<>nil) then
|
|
if (Expr<>nil) then
|
|
begin
|
|
begin
|
|
if Expr.ClassType=TArrayValues then
|
|
if Expr.ClassType=TArrayValues then
|
|
ExpectedCount:=length(TArrayValues(Expr).Values)
|
|
ExpectedCount:=length(TArrayValues(Expr).Values)
|
|
else if (Expr.ClassType=TParamsExpr) and (TParamsExpr(Expr).Kind=pekSet) then
|
|
else if (Expr.ClassType=TParamsExpr) and (TParamsExpr(Expr).Kind=pekSet) then
|
|
ExpectedCount:=length(TParamsExpr(Expr).Params)
|
|
ExpectedCount:=length(TParamsExpr(Expr).Params)
|
|
- else if (Values.BaseType in btAllStringAndChars) and IsVarInit(Expr) then
|
|
|
|
|
|
+ else if (Values.BaseType in btAllStringAndChars) then
|
|
begin
|
|
begin
|
|
- // const a: dynarray = string
|
|
|
|
- ComputeElement(ArrType.ElType,ElTypeResolved,[rcType]);
|
|
|
|
- if ElTypeResolved.BaseType in btAllChars then
|
|
|
|
- Result:=cExact;
|
|
|
|
|
|
+ // e.g. const a: dynarray = string
|
|
|
|
+ // or e.g. pass a string literal to an open array
|
|
|
|
+ CheckArrOfCharAssignString;
|
|
exit;
|
|
exit;
|
|
end
|
|
end
|
|
else
|
|
else
|
|
@@ -25777,7 +25786,15 @@ function TPasResolver.CheckAssignCompatibilityArrayType(const LHS,
|
|
begin
|
|
begin
|
|
// type check
|
|
// type check
|
|
if (Values.BaseType<>btContext) or (Values.LoTypeEl.ClassType<>TPasArrayType) then
|
|
if (Values.BaseType<>btContext) or (Values.LoTypeEl.ClassType<>TPasArrayType) then
|
|
|
|
+ begin
|
|
|
|
+ // RHS is not an array
|
|
|
|
+ if (Values.BaseType in btAllStringAndChars) then
|
|
|
|
+ begin
|
|
|
|
+ // e.g. pass a string literal to an open array
|
|
|
|
+ CheckArrOfCharAssignString;
|
|
|
|
+ end;
|
|
exit;
|
|
exit;
|
|
|
|
+ end;
|
|
RArrayType:=TPasArrayType(Values.LoTypeEl);
|
|
RArrayType:=TPasArrayType(Values.LoTypeEl);
|
|
if length(RArrayType.Ranges)>0 then
|
|
if length(RArrayType.Ranges)>0 then
|
|
begin
|
|
begin
|