pastojs: fixed range check of o.aString[index]

git-svn-id: trunk@40175 -
This commit is contained in:
Mattias Gaertner 2018-11-02 00:06:29 +00:00
parent f116d51fd9
commit 3979f9922a
2 changed files with 21 additions and 2 deletions

View File

@ -7431,7 +7431,10 @@ var
CallEx:=CreateCallExpression(El);
try
if IsRangeCheck then
if IsRangeCheck
and (not (El.Parent is TBinaryExpr)
or (TBinaryExpr(El.Parent).right<>El)
or (TBinaryExpr(El.Parent).OpCode<>eopSubIdent)) then
begin
// read s[index] -> rtl.rcCharAt(s,index-1)
CallEx.Expr:=CreatePrimitiveDotExpr(FBuiltInNames[pbivnRTL]+'.'+FBuiltInNames[pbifnRangeCheckGetCharAt],El);

View File

@ -22422,7 +22422,8 @@ begin
StartProgram(false);
Add([
'{$R+}',
'type TLetter = char;',
'type',
' TLetter = char;',
'var',
' b: TLetter = ''2'';',
' w: TLetter = ''3'';',
@ -22571,29 +22572,44 @@ procedure TTestModule.TestRangeChecks_StringIndex;
begin
StartProgram(false);
Add([
'type',
' TObject = class',
' S: string;',
' end;',
'{$R+}',
'procedure DoIt(var h: string);',
'var',
' s: string;',
' i: longint;',
' c: char;',
' o: tobject;',
'begin',
' c:=s[1];',
' s[i]:=s[i];',
' h[i]:=h[i];',
' c:=o.s[i];',
'end;',
'begin',
'']);
ConvertProgram;
CheckSource('TestRangeChecks_StringIndex',
LinesToStr([ // statements
'rtl.createClass($mod, "TObject", null, function () {',
' this.$init = function () {',
' this.S = "";',
' };',
' this.$final = function () {',
' };',
'});',
'this.DoIt = function (h) {',
' var s = "";',
' var i = 0;',
' var c = "";',
' var o = null;',
' c = rtl.rcc(rtl.rcCharAt(s, 0), 0, 65535);',
' s = rtl.rcSetCharAt(s, i - 1, rtl.rcCharAt(s, i - 1));',
' h.set(rtl.rcSetCharAt(h.get(), i - 1, rtl.rcCharAt(h.get(), i - 1)));',
' c = rtl.rcc(o.S.charAt(i - 1), 0, 65535);',
'};',
'']),
LinesToStr([ // $mod.$main