mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 07:39:25 +02:00
pastojs: warn for bitwise and,or,xor with native(u)int
git-svn-id: trunk@41063 -
This commit is contained in:
parent
1a59a4a4a3
commit
4ab30223d3
@ -180,6 +180,7 @@ const
|
||||
nDerivedXMustExtendASubClassY = 3114;
|
||||
nDefaultPropertyNotAllowedInHelperForX = 3115;
|
||||
nHelpersCannotBeUsedAsTypes = 3116;
|
||||
nBitWiseOperationsAre32Bit = 3117;
|
||||
|
||||
// using same IDs as FPC
|
||||
nVirtualMethodXHasLowerVisibility = 3250; // was 3050
|
||||
@ -307,6 +308,7 @@ resourcestring
|
||||
sDerivedXMustExtendASubClassY = 'Derived %s must extend a subclass of "%s" or the class itself';
|
||||
sDefaultPropertyNotAllowedInHelperForX = 'Default property not allowed in helper for %s';
|
||||
sHelpersCannotBeUsedAsTypes = 'helpers cannot be used as types';
|
||||
sBitWiseOperationsAre32Bit = 'Bitwise operations are 32-bit';
|
||||
|
||||
type
|
||||
{ TResolveData - base class for data stored in TPasElement.CustomData }
|
||||
|
@ -6572,8 +6572,15 @@ begin
|
||||
eopXor:
|
||||
begin
|
||||
if aResolver<>nil then
|
||||
begin
|
||||
UseBitwiseOp:=((LeftResolved.BaseType in btAllJSInteger)
|
||||
or (RightResolved.BaseType in btAllJSInteger))
|
||||
or (RightResolved.BaseType in btAllJSInteger));
|
||||
if UseBitwiseOp
|
||||
and (LeftResolved.BaseType in [btIntDouble,btUIntDouble])
|
||||
and (RightResolved.BaseType in [btIntDouble,btUIntDouble]) then
|
||||
aResolver.LogMsg(20190124233439,mtWarning,nBitWiseOperationsAre32Bit,
|
||||
sBitWiseOperationsAre32Bit,[],El);
|
||||
end
|
||||
else
|
||||
UseBitwiseOp:=(GetExpressionValueType(El.left,AContext)=jstNumber)
|
||||
or (GetExpressionValueType(El.right,AContext)=jstNumber);
|
||||
|
@ -257,6 +257,7 @@ type
|
||||
Procedure TestInteger;
|
||||
Procedure TestIntegerRange;
|
||||
Procedure TestIntegerTypecasts;
|
||||
Procedure TestBitwiseAndNativeIntWarn;
|
||||
Procedure TestCurrency;
|
||||
Procedure TestForBoolDo;
|
||||
Procedure TestForIntDo;
|
||||
@ -6072,6 +6073,27 @@ begin
|
||||
'']));
|
||||
end;
|
||||
|
||||
procedure TTestModule.TestBitwiseAndNativeIntWarn;
|
||||
begin
|
||||
StartProgram(false);
|
||||
Add([
|
||||
'var',
|
||||
' i,j: nativeint;',
|
||||
'begin',
|
||||
' i:=i and j;',
|
||||
'']);
|
||||
ConvertProgram;
|
||||
CheckSource('TestBitwiseAndNativeIntWarn',
|
||||
LinesToStr([
|
||||
'this.i = 0;',
|
||||
'this.j = 0;',
|
||||
'']),
|
||||
LinesToStr([
|
||||
'$mod.i = $mod.i & $mod.j;',
|
||||
'']));
|
||||
CheckHint(mtWarning,nBitWiseOperationsAre32Bit,sBitWiseOperationsAre32Bit);
|
||||
end;
|
||||
|
||||
procedure TTestModule.TestCurrency;
|
||||
begin
|
||||
StartProgram(false);
|
||||
|
Loading…
Reference in New Issue
Block a user