View Issue Details

IDProjectCategoryView StatusLast Update
0030518FPCCompilerpublic2021-01-07 22:40
Reportersilvioprog Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionwon't fix 
Product Version3.1.1 
Summary0030518: WRITEABLECONST should be OFF in mode DELPHI
DescriptionHello,

Consider the following type:

=== begin code ===

type
  a = record
    b: Byte;
  end;

const
  c: a = (b: 10);

begin
  Writeln(c.b); // print 10
end.

=== end code ===

On Delphi, if you try:

=== begin code ===

begin
  c.b := 20;
end;

=== end code ===

you get:

=== begin log ===

E2064 Left side cannot be assigned to

=== end log ===

On FPC, it compiles properly in a unit declared as mode DELPHI.

What do you think about WRITEABLECONST=OFF as default in mode Delphi?
Additional InformationPlease delete issue 0030517, I can't do it by myself. (I'll remove this comment after 0030517 deletion ...)
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Jonas Maebe

2016-08-25 23:31

manager   ~0094315

The main purpose of Delphi mode is to get Delphi code to compile in FPC without too many changes. Making this change would not influence that, but it could potentially break a lot of existing code that has been written in {$mode delphi} for FPC. I don't think the gains are that big so as to make it work the backward compatibility hassle.

jamie philbrook

2016-08-25 23:43

reporter   ~0094316

Please don't disable that feature..

 I use it all the time, its a great feature for detecting first time
runs into code or even last time runs and keeps the name local to the
code block..,
  
  Personally I don't understand why anyone would want such a feature turned off in the first place? I'll keep my personal opinions to myself as to why.

 Disabling this feature will simply degrade FPC.

Jonas Maebe

2016-08-25 23:55

manager   ~0094317

This bug report is not about disabling the feature, but about changing the default setting.

silvioprog

2016-08-26 00:37

reporter   ~0094318

@jamie please don't worry, I'm just talking about its default setting, not about disabling it. :-)

@Jonas hm... you are right, it can break many existing code, and it would be really a problem.

It should be documented, because the long strings are off by default in Delphi mode, so I followed the same logic for writable consts. ^^'

Well, I'm going to declare J- in my main include file ... :-)

Thaddy de Koning

2016-08-26 08:25

reporter   ~0094319

Last edited: 2016-08-26 08:41

View 3 revisions

For what it is worth, it is a Delphi feature that lot's of people turn on by hand anyway, i.e. {$J+}. Although of questonable design, this is because they want to maintain state for certain variables in procedures and functions which can be achieved by a typed const in {$J+} mode.

If you would be strict, it should be {$J-} in the default {$delphi} modes.
As Jonas implied it is unlikely that this feature would break porting from Delphi. If {$J+} is used or not in the Delphi code.
The other way around the delphi compiler will throw a descriptive error so the programmer can turn writable constants on in Delphi ;)
It is anyway a good idea to include the modes in your sources and not use the command line.
Both Delphi and FPC will then pick up the right mode.

Florian

2021-01-07 22:40

administrator   ~0128157

As discussed, it harms more than it helps.

Issue History

Date Modified Username Field Change
2016-08-25 22:13 silvioprog New Issue
2016-08-25 23:31 Jonas Maebe Note Added: 0094315
2016-08-25 23:43 jamie philbrook Note Added: 0094316
2016-08-25 23:55 Jonas Maebe Note Added: 0094317
2016-08-26 00:37 silvioprog Note Added: 0094318
2016-08-26 08:25 Thaddy de Koning Note Added: 0094319
2016-08-26 08:39 Thaddy de Koning Note Edited: 0094319 View Revisions
2016-08-26 08:41 Thaddy de Koning Note Edited: 0094319 View Revisions
2021-01-07 22:40 Florian Assigned To => Florian
2021-01-07 22:40 Florian Status new => resolved
2021-01-07 22:40 Florian Resolution open => won't fix
2021-01-07 22:40 Florian FPCTarget => -
2021-01-07 22:40 Florian Note Added: 0128157