* fix for Mantis #32355: adjust the meaning of the typehelpers modeswitch for Delphi modes in that it enables the "type helper" syntax as it is in the non-Delphi modes; extending primitive types with record helpers is now always enabled in Delphi modes

+ added test

git-svn-id: trunk@37225 -
This commit is contained in:
svenbarth 2017-09-15 21:09:21 +00:00
parent 83f5b27e02
commit 90bd408de4
6 changed files with 53 additions and 6 deletions

1
.gitattributes vendored
View File

@ -13469,6 +13469,7 @@ tests/test/tthlp21.pp svneol=native#text/pascal
tests/test/tthlp22.pp svneol=native#text/pascal
tests/test/tthlp23.pp svneol=native#text/pascal
tests/test/tthlp24.pp svneol=native#text/pascal
tests/test/tthlp25.pp svneol=native#text/pascal
tests/test/tthlp3.pp svneol=native#text/pascal
tests/test/tthlp4.pp svneol=native#text/pascal
tests/test/tthlp5.pp svneol=native#text/pascal

View File

@ -54,7 +54,7 @@ interface
[m_delphi,m_class,m_objpas,m_result,m_string_pchar,
m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
m_out,m_default_para,m_duplicate_names,m_hintdirective,
m_property,m_default_inline,m_except,m_advanced_records,m_type_helpers];
m_property,m_default_inline,m_except,m_advanced_records];
delphiunicodemodeswitches = delphimodeswitches + [m_systemcodepage,m_default_unicodestring];
fpcmodeswitches =
[m_fpc,m_string_pchar,m_nested_comment,m_repeat_forward,

View File

@ -425,8 +425,8 @@ interface
fields in Java) }
m_default_unicodestring, { makes the default string type in $h+ mode unicodestring rather than
ansistring; similarly, char becomes unicodechar rather than ansichar }
m_type_helpers, { allows the declaration of "type helper" (non-Delphi) or "record helper"
(Delphi) for primitive types }
m_type_helpers, { allows the declaration of "type helper" for all supported types
(primitive types, records, classes, interfaces) }
m_blocks, { support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension) }
m_isolike_io, { I/O as it required by an ISO compatible compiler }
m_isolike_program_para, { program parameters as it required by an ISO compatible compiler }

View File

@ -780,7 +780,7 @@ implementation
{ primitive types are allowed for record helpers in mode
delphi }
(hdef.typ<>recorddef) and
not (m_type_helpers in current_settings.modeswitches)
not (m_delphi in current_settings.modeswitches)
) then
Message1(type_e_record_type_expected,hdef.typename)
else

View File

@ -1890,8 +1890,7 @@ implementation
_HELPER:
begin
if hadtypetoken and
{ don't allow "type helper" in mode delphi and require modeswitch typehelpers }
([m_delphi,m_type_helpers]*current_settings.modeswitches=[m_type_helpers]) then
(m_type_helpers in current_settings.modeswitches) then
begin
{ reset hadtypetoken, so that calling code knows that it should not be handled
as a "unique" type }

47
tests/test/tthlp25.pp Normal file
View File

@ -0,0 +1,47 @@
program tthlp25;
{$mode delphi}
{$modeswitch typehelpers}
type
TLongIntHelper = type helper for LongInt
function Test: LongInt;
end;
TTest = record
end;
TTestHelper = record helper for TTest
function Test: LongInt;
end;
TTestHelperSub = type helper(TTestHelper) for TTest
function Test: LongInt;
end;
function TLongIntHelper.Test: LongInt;
begin
Result := Self * 2;
end;
function TTestHelper.Test: LongInt;
begin
Result := 4;
end;
function TTestHelperSub.Test: LongInt;
begin
Result := inherited Test * 2;
end;
var
i: LongInt;
t: TTest;
begin
i := 2;
if i.Test <> 4 then
Halt(1);
if t.Test <> 8 then
Halt(2);
Writeln('ok');
end.