mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 07:19:14 +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;
|
nDerivedXMustExtendASubClassY = 3114;
|
||||||
nDefaultPropertyNotAllowedInHelperForX = 3115;
|
nDefaultPropertyNotAllowedInHelperForX = 3115;
|
||||||
nHelpersCannotBeUsedAsTypes = 3116;
|
nHelpersCannotBeUsedAsTypes = 3116;
|
||||||
|
nBitWiseOperationsAre32Bit = 3117;
|
||||||
|
|
||||||
// using same IDs as FPC
|
// using same IDs as FPC
|
||||||
nVirtualMethodXHasLowerVisibility = 3250; // was 3050
|
nVirtualMethodXHasLowerVisibility = 3250; // was 3050
|
||||||
@ -307,6 +308,7 @@ resourcestring
|
|||||||
sDerivedXMustExtendASubClassY = 'Derived %s must extend a subclass of "%s" or the class itself';
|
sDerivedXMustExtendASubClassY = 'Derived %s must extend a subclass of "%s" or the class itself';
|
||||||
sDefaultPropertyNotAllowedInHelperForX = 'Default property not allowed in helper for %s';
|
sDefaultPropertyNotAllowedInHelperForX = 'Default property not allowed in helper for %s';
|
||||||
sHelpersCannotBeUsedAsTypes = 'helpers cannot be used as types';
|
sHelpersCannotBeUsedAsTypes = 'helpers cannot be used as types';
|
||||||
|
sBitWiseOperationsAre32Bit = 'Bitwise operations are 32-bit';
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TResolveData - base class for data stored in TPasElement.CustomData }
|
{ TResolveData - base class for data stored in TPasElement.CustomData }
|
||||||
|
@ -6572,8 +6572,15 @@ begin
|
|||||||
eopXor:
|
eopXor:
|
||||||
begin
|
begin
|
||||||
if aResolver<>nil then
|
if aResolver<>nil then
|
||||||
|
begin
|
||||||
UseBitwiseOp:=((LeftResolved.BaseType in btAllJSInteger)
|
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
|
else
|
||||||
UseBitwiseOp:=(GetExpressionValueType(El.left,AContext)=jstNumber)
|
UseBitwiseOp:=(GetExpressionValueType(El.left,AContext)=jstNumber)
|
||||||
or (GetExpressionValueType(El.right,AContext)=jstNumber);
|
or (GetExpressionValueType(El.right,AContext)=jstNumber);
|
||||||
|
@ -257,6 +257,7 @@ type
|
|||||||
Procedure TestInteger;
|
Procedure TestInteger;
|
||||||
Procedure TestIntegerRange;
|
Procedure TestIntegerRange;
|
||||||
Procedure TestIntegerTypecasts;
|
Procedure TestIntegerTypecasts;
|
||||||
|
Procedure TestBitwiseAndNativeIntWarn;
|
||||||
Procedure TestCurrency;
|
Procedure TestCurrency;
|
||||||
Procedure TestForBoolDo;
|
Procedure TestForBoolDo;
|
||||||
Procedure TestForIntDo;
|
Procedure TestForIntDo;
|
||||||
@ -6072,6 +6073,27 @@ begin
|
|||||||
'']));
|
'']));
|
||||||
end;
|
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;
|
procedure TTestModule.TestCurrency;
|
||||||
begin
|
begin
|
||||||
StartProgram(false);
|
StartProgram(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user