Refactoring

This commit is contained in:
Michael Schimmel
2025-11-01 13:00:22 +01:00
parent df12db2595
commit 3869c98652
3 changed files with 32 additions and 30 deletions
+5 -2
View File
@@ -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;