On 03.11.2015 17:34, Mattias Gaertner wrote:
codetools use only a simple heuristic to calculate the type of a
binary operator.
The function TFindDeclarationTool.CalculateBinaryOperator needs to be
extended for Alias types (e.g. 'integer' instead of longint) and for
ranges (e.g. if the operands do not fit into an integer).

Maybe you are talking about the same, but just to be sure: IMO using hard-coded alias types is not a good idea (theoretically the user can redefine them). Instead the type evaluation should go to the end type (e.g. from Integer to *longint*) and then the end types should be compared. The comparison can then be done with a hard-coded table (you need it only for the basic types, so it is OK and safe) and the type that wins, will be used as the result type (obviously the originally used alias).

E.g.:

procedure Test;
var
  I: Integer;
  S: SmallInt;
begin
  Res := I + S;
end;

Something like:
1.)
I = (Integer -> longint)
S = SmallInt
2.)
ResultBasicType = Compare(longint, SmallInt) -> longint -> I
3.)
ResultType = ResultBasicType -> I -> *Integer*

Reported:
http://mantis.freepascal.org/view.php?id=28953

Ondrej
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to