mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-10 09:29:02 +02:00
fcl-passrc: resolver: enum range: assign enum:=enumrange
git-svn-id: trunk@37441 -
This commit is contained in:
parent
7abc3af339
commit
bb15bbec52
@ -11455,11 +11455,12 @@ function TPasResolver.CheckAssignResCompatibility(const LHS,
|
||||
RHS: TPasResolverResult; ErrorEl: TPasElement; RaiseOnIncompatible: boolean
|
||||
): integer;
|
||||
var
|
||||
TypeEl: TPasType;
|
||||
TypeEl, RTypeEl: TPasType;
|
||||
Handled: Boolean;
|
||||
C: TClass;
|
||||
LBT, RBT: TResolverBaseType;
|
||||
LRange: TResEvalValue;
|
||||
RightSubResolved: TPasResolverResult;
|
||||
begin
|
||||
// check if the RHS can be converted to LHS
|
||||
{$IFDEF VerbosePasResolver}
|
||||
@ -11729,8 +11730,29 @@ begin
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else if (LBT=btContext) and (LHS.TypeEl is TPasArrayType) then
|
||||
Result:=CheckAssignCompatibilityArrayType(LHS,RHS,ErrorEl,RaiseOnIncompatible);
|
||||
else if (LBT=btContext) then
|
||||
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;
|
||||
|
||||
if (Result>=0) and (Result<cIncompatible) then
|
||||
|
@ -3100,15 +3100,15 @@ begin
|
||||
' c3: TEnumRg = pred(high(TEnumRg));',
|
||||
' c4: TEnumRg = TEnumRg(2);',
|
||||
'var',
|
||||
' s: TEnumRg;',
|
||||
' er: TEnumRg;',
|
||||
' Enum: TEnum;',
|
||||
'begin',
|
||||
// s:=d;
|
||||
// Enum:=s;
|
||||
// if Enum=s then ;
|
||||
// if s=Enum then ;
|
||||
// if s=c then ;
|
||||
// if c=s then ;
|
||||
' er:=d;',
|
||||
' Enum:=er;',
|
||||
//' if Enum=er then ;',
|
||||
//' if er=Enum then ;',
|
||||
//' if er=c then ;',
|
||||
//' if c=er then ;',
|
||||
'']);
|
||||
ParseProgram;
|
||||
// see also: TestPropertyDefaultValue
|
||||
|
Loading…
Reference in New Issue
Block a user