fcl-passrc: resolver: enum range: assign enum:=enumrange

git-svn-id: trunk@37441 -
This commit is contained in:
Mattias Gaertner 2017-10-10 08:28:12 +00:00
parent 7abc3af339
commit bb15bbec52
2 changed files with 32 additions and 10 deletions

View File

@ -11455,11 +11455,12 @@ function TPasResolver.CheckAssignResCompatibility(const LHS,
RHS: TPasResolverResult; ErrorEl: TPasElement; RaiseOnIncompatible: boolean RHS: TPasResolverResult; ErrorEl: TPasElement; RaiseOnIncompatible: boolean
): integer; ): integer;
var var
TypeEl: TPasType; TypeEl, RTypeEl: TPasType;
Handled: Boolean; Handled: Boolean;
C: TClass; C: TClass;
LBT, RBT: TResolverBaseType; LBT, RBT: TResolverBaseType;
LRange: TResEvalValue; LRange: TResEvalValue;
RightSubResolved: TPasResolverResult;
begin begin
// check if the RHS can be converted to LHS // check if the RHS can be converted to LHS
{$IFDEF VerbosePasResolver} {$IFDEF VerbosePasResolver}
@ -11729,8 +11730,29 @@ begin
end; end;
end; end;
end end
else if (LBT=btContext) and (LHS.TypeEl is TPasArrayType) then else if (LBT=btContext) then
Result:=CheckAssignCompatibilityArrayType(LHS,RHS,ErrorEl,RaiseOnIncompatible); begin
TypeEl:=ResolveAliasType(LHS.TypeEl);
if (TypeEl.ClassType=TPasArrayType) then
Result:=CheckAssignCompatibilityArrayType(LHS,RHS,ErrorEl,RaiseOnIncompatible)
else if TypeEl.ClassType=TPasEnumType then
begin
if (RHS.BaseType=btRange) and (RHS.SubType=btContext) then
begin
RTypeEl:=ResolveAliasType(RHS.TypeEl);
if RTypeEl.ClassType=TPasRangeType then
begin
ComputeElement(TPasRangeType(RTypeEl).RangeExpr.left,RightSubResolved,[rcConstant]);
if (RightSubResolved.BaseType=btContext)
and IsSameType(TypeEl,RightSubResolved.TypeEl,true) then
begin
// enumtype := enumrange
Result:=cExact;
end;
end;
end;
end;
end;
end; end;
if (Result>=0) and (Result<cIncompatible) then if (Result>=0) and (Result<cIncompatible) then

View File

@ -3100,15 +3100,15 @@ begin
' c3: TEnumRg = pred(high(TEnumRg));', ' c3: TEnumRg = pred(high(TEnumRg));',
' c4: TEnumRg = TEnumRg(2);', ' c4: TEnumRg = TEnumRg(2);',
'var', 'var',
' s: TEnumRg;', ' er: TEnumRg;',
' Enum: TEnum;', ' Enum: TEnum;',
'begin', 'begin',
// s:=d; ' er:=d;',
// Enum:=s; ' Enum:=er;',
// if Enum=s then ; //' if Enum=er then ;',
// if s=Enum then ; //' if er=Enum then ;',
// if s=c then ; //' if er=c then ;',
// if c=s then ; //' if c=er then ;',
'']); '']);
ParseProgram; ParseProgram;
// see also: TestPropertyDefaultValue // see also: TestPropertyDefaultValue