Refactoring
This commit is contained in:
@@ -555,6 +555,7 @@ end;
|
||||
|
||||
class function TTypeRules.CanAssign(const Target, Source: IStaticType): Boolean;
|
||||
begin
|
||||
// Basic nil-check for safety.
|
||||
if (not Assigned(Target)) or (not Assigned(Source)) then
|
||||
exit(False);
|
||||
|
||||
@@ -562,6 +563,7 @@ begin
|
||||
if (Target.Kind = stUnknown) or (Source.Kind = stUnknown) then
|
||||
exit(True);
|
||||
|
||||
// Types are always assignable to themselves (identity).
|
||||
if Target.IsEqual(Source) then
|
||||
exit(True);
|
||||
|
||||
@@ -569,17 +571,18 @@ begin
|
||||
if (Target.Kind = stFloat) and (Source.Kind = stOrdinal) then
|
||||
exit(True);
|
||||
|
||||
// Allow discarding the return value of a method (e.g., in a 'do' block).
|
||||
if (Target.Kind = stVoid) and (Source.Kind = stMethod) then
|
||||
exit(True);
|
||||
|
||||
// Allow implicit conversion from Keyword (internally an index) to Ordinal.
|
||||
if (Target.Kind = stOrdinal) and (Source.Kind = stKeyword) then
|
||||
exit(True);
|
||||
|
||||
// TODO: Implement full assignment compatibility rules (e.g., for records/series)
|
||||
|
||||
// Allow assigning a scalar record to a generic record? (Maybe later)
|
||||
// Allow assigning a generic record to a scalar record? (If fields match)
|
||||
|
||||
// Default: Assignment is not allowed if no specific rule matches.
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user