[fpc-devel] Tests in Delphi XE3 regarding Type Helpers
Marco van de Voort
marcov at stack.nl
Thu Nov 29 10:39:59 CET 2012
In our previous episode, Sven Barth said:
> For tthlperr2.pas it would have been interesting to see if the same
> error is reported if a helper is in scope, but the method is invalid...
> could you please repeat that test with a string helper and a string
> constant?
tthlperr2.pas(15) Error: E2003 Undeclared identifier: 'DoTest2'
>Or change the type of the int helper to "uint8" which seems to
> have helped in the tthlpsize.pas test...
Only for unsigned constants. I tried, and the results are the same dotest2.
Even with the unsigned value. Only if I change dotest2 to dotest1 I get the
operator not applicable. So somehow the method name has prio over the
literal type mismatch
> > D:\testing\rechelp>dcc32 tthlpminus.pas
> > Embarcadero Delphi for Win32 compiler version 24.0
> > Copyright (c) 1983,2012 Embarcadero Technologies, Inc.
> > tthlpminus.pas(14) Error: E2018 Record, object or class type required
> > tthlpminus.pas(15) Error: E2018 Record, object or class type required
> > tthlpminus.pas(17)
> >
> > 1. Typecasting the "42" literals to integer works
> > 2. changing record helper type to "int64" doesn't.
> > 3. Changing to smaller types (int8,int16) doesn't help.
> > 4. changing to uint8 works for the "42" one, not for the "-42" one.
> Ok... so Delphi does use the minimum required size for the constant.
For unsigned ones yes.
> Good. Does "int8" help for the "-42"? What if you change it to
> "(-42).DoTest"?
Then it passes for the signed (int8) type. So it seems there is no helper
that will accept both positive and negative literals.
> > D:\testing\rechelp>dcc32 tthlpself.pas
> > Embarcadero Delphi for Win32 compiler version 24.0
> > Copyright (c) 1983,2012 Embarcadero Technologies, Inc.
> > tthlpself.pas(36)
> > 37 lines, 0.09 seconds, 18816 bytes code, 13240 bytes data.
> >
> > D:\testing\rechelp>tthlpself
> > -> throws RTE 105
>
> It seems that I forgot a "{$apptype console}" :)
42
21
Type Helper
Hello Type Helper World
> > D:\testing\rechelp>dcc32 tthlpsize.pas
> > Embarcadero Delphi for Win32 compiler version 24.0
> > Copyright (c) 1983,2012 Embarcadero Technologies, Inc.
> > tthlpsize.pas(24) Error: E2003 Undeclared identifier: 'Short'
> > tthlpsize.pas(78) Error: E2015 Operator not applicable to this operand type
> > tthlpsize.pas(80) Error: E2015 Operator not applicable to this operand type
> > tthlpsize.pas(82) Error: E2015 Operator not applicable to this operand type
> > tthlpsize.pas(84) Error: E2015 Operator not applicable to this operand type
> > tthlpsize.pas(87)
> >
> > The first is easily fixable by changing short (which probably should have
> > been shortint) to int16.
> The introduction of the (U)IntXX types was one of the best things I
> remember (and luckily we already have them in FPC as well :) ), as I
> always forget how the smaller types are named... -.-
Why do you think I added them when I found out? :-) I never could either.
(specially smallint and shortint)
> > The remaining errors are the negative values. I didn't find a solution for
> > them with tthlpminus
> So the hexadecimal values work correctly?
Yes
> What if you here also try the
> suggestion "(negativevalue).DoTest"? You might also want to add a
> "{$apptype console}" here.
Strange results. All compile except (-1)
Input:
Writeln(0, #9, 0.DoTest);
// Writeln(-1, #9, (-1).DoTest);
Writeln($ABCD, #9, $ABCD.DoTest);
Writeln(-32987, #9, (-32987).DoTest);
Writeln(2345678, #9, 2345678.DoTest);
Writeln(-2345678, #9, (-2345678).DoTest);
Writeln($1234567887654321, #9, $1234567887654321.DoTest);
Writeln(-9876543211234, #9, (-9876543211234).DoTest);
Writeln(9876543211234, #9, 9876543211234.DoTest);
Output:
0 Byte
43981 Word
-32987 LongInt
2345678 LongInt
-2345678 LongInt
1311768467139281697 Int64
-9876543211234 Int64
9876543211234 Int64
... which seems to have a bias for signed types that I didn't see
in earlier tests.
I played a bit with the minus one value, and got an IE:
Writeln(-129, #9, (-129).DoTest);
caused:
D:\testing\rechelp>dcc32 tthlpsize.pas
Embarcadero Delphi for Win32 compiler version 24.0
Copyright (c) 1983,2012 Embarcadero Technologies, Inc.
tthlpsize.pas(78) Fatal: F2084 Internal Error: SY3502
> Otherwise: Thank you so far. :)
As soon as it is finished, you go back to generics? :-)
More information about the fpc-devel
mailing list