[fpc-devel] Variable can not be initialized by named constant

Alexander Klenin klenin at gmail.com
Sun Mar 1 15:29:01 CET 2009

Since issue http://bugs.freepascal.org/view.php?id=13256 was marked resolved,
I can not add comments, so I'd like to discuss it here.

Original report claimed that code

const c: SomeType = <value>;
var y: t = c;

Works for primitive types, but not the complex ones.
This was an error on my part, as pointed out on the issue tracker:

>It also does not work with other types for me, unlike what's stated in the "Additional Information" section

It also does not work in Delphi, so this is certainly a design decision.

However, I think this decision is suboptimal.

This is a typical use case:

const EMPTY_RECT: TRect = (Left: 0; Right: 0; Top: 0; Bottom: 0);
  myRect: TRect = EMPTY_RECT;

I think this is quite reasonable to expect this to work.
The writeability of constants is IMNSHO just an ugly leftover from
Delphi history,
and should be disabled in _both_ delphi and objfpc modes:

const x: integer = 1;
  x := 3;

Is rejected by Delphi, but compiled by FPC, which is a compatibility
bug in itself.

So how about re-submitting the issue as a feature request?

Alexander S. Klenin

More information about the fpc-devel mailing list