NOTE: The description below was generated by AI. I've personally gone through both the code fixes and the description. I hope you don't mind, as I believe it's easier for both me and you to read through this than through a hand-written explanation, which would certainly take more time from both of us :).
Setting: IdentifiersCase = 4 ("Use first occurrence")
An identifier sharing its spelling with a keyword/directive is merged with it (case-insensitively) into one first-occurrence entry, so the directive's casing wins.
// Expected
property MyEnum: TMyEnum read FMyEnum write FMyEnum default TMyEnum.Read;
// Actual
property MyEnum: TMyEnum read FMyEnum write FMyEnum default TMyEnum.read;
TIdentifiersList.AddIdentifier (Source/Formatter/Engine/GX_CodeFormatterParser.pas) adds every word to the first-occurrence pool, including reserved words/directives. Their casing is already handled by ReservedCase/StandDirectivesCase, so they must not be in the pool.
Skip reserved words/directives in the rfFirstOccurrence branch:
rfFirstOccurrence:
if ReservedWordList.FindWord(_s, ResvdType) then
Result := _s
else if not FSettings.CapNames.Find(_s, WordIndex) then
Result := Strings[Add(_s)]
else
Result := FSettings.CapNames[WordIndex];
(adds a ResvdType: TReservedType; local).
No config exercised rfFirstOccurrence (AdjustSettings_twm overrides it to rfUnchanged), so a new SpecialCases test was added.
Adjuster in UnitTestsFormatter/source/DelForExSpecialCasesTests.pas:
procedure AdjustSettings_FirstOccurrenceCase(var _cfg: TCodeFormatterEngineSettings);
begin
_cfg.IdentifiersCase := rfFirstOccurrence;
end;
Input Testcases/SpecialCases/FirstOccurrenceCase/input/testfile_PropertyAccessorVsEnumValue.pas:
unit testfile_PropertyAccessorVsEnumValue;
interface
type
TMyClass = class
private
FMyEnum: TMyEnum;
FOther: TMyEnum;
published
property MyEnum: TMyEnum read FMyEnum write FMyEnum default TMyEnum.Read;
property Other: TMyEnum read FOther write FOther default TMyEnum.Write;
end;
implementation
end.
fixed in revision #5471
Also added the proposed unit test
(And no: I don't mind AI generated bug reports and fixes as long as they have been checked by the submitter.)