Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2015-01

Ambiguity between function result and overloaded function

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

luiz americo pereira camara

I have the following methods.

I was expecting that Result := Save; would call Save method but in fact
Save refers to the function result variable.

Is it by design?

function TSqlite3JSONObjectResource.Save(IdValue: Variant): Boolean;
begin
  if not VarIsEmpty(IdValue) then
  begin
    [..]
  end
  else
  begin
    Result := Save; <- this does not call the overloaded method
    Result := Save(); <- this calls the overloaded method
  end;
end;
function TSqlite3JSONObjectResource.Save: Boolean;
begin
[..]
end;

Reply by email

Marcos Douglas
to Jonas Maebe
Jonas Maebe wrote 12 lines
On 05 Jan 2015, at 21:20, luiz americo pereira camara wrote: > I have the following methods. > > I was expecting that Result := Save; would call Save method but in fact > Save refers to the function result variable. > > Is it by design? Yes. See e.g. http://bugs.freepascal.org/view.php?id=22344

Hi Jonas,

There you said: "If you don't like that (by design), use the TP or Delphi dialects as mentioned before."
If this "problem" not occurs using delphi dialects, do not you think it's better all dialects work as Delphi works? Only in this case, of course.

IMHO this is an inconsistency in the language. Sometimes use "()" sometimes not?

Best regards,
Marcos Douglas

Reply by email

Jonas Maebe
to Marcos Douglas
Marcos Douglas wrote 5 lines
There you said: "If you don't like that (by design), use the TP or Delphi dialects as mentioned before." If this "problem" not occurs using delphi dialects, do not you think it's better all dialects work as Delphi works? Only in this case, of course.

It would break compatibility with a lot of existing code written in FPC and ObjFPC modes. This bug/feature has been in FPC dialects since more or less the beginning (since before Delphi and its somewhat cleaner "result" solution to the same problem existed).

IMHO this is an inconsistency in the language. Sometimes use "()" sometimes not?

If you want, you can always use () when calling a function.

Jonas

Reply by email