Explorar o código

+ constant postfixoperator_tokens
+ check for postfix operators after string contants, resolves #23136

git-svn-id: trunk@22929 -

florian %!s(int64=12) %!d(string=hai) anos
pai
achega
bc4a8ac63e
Modificáronse 4 ficheiros con 32 adicións e 5 borrados
  1. 1 0
      .gitattributes
  2. 15 5
      compiler/pexpr.pas
  3. 2 0
      compiler/tokens.pas
  4. 14 0
      tests/webtbs/tw23136.pp

+ 1 - 0
.gitattributes

@@ -12967,6 +12967,7 @@ tests/webtbs/tw2305.pp svneol=native#text/plain
 tests/webtbs/tw2306.pp svneol=native#text/plain
 tests/webtbs/tw2307.pp svneol=native#text/plain
 tests/webtbs/tw2311.pp svneol=native#text/plain
+tests/webtbs/tw23136.pp svneol=native#text/pascal
 tests/webtbs/tw2317.pp svneol=native#text/plain
 tests/webtbs/tw2318.pp svneol=native#text/plain
 tests/webtbs/tw23185.pp svneol=native#text/pascal

+ 15 - 5
compiler/pexpr.pas

@@ -2814,6 +2814,11 @@ implementation
                begin
                  p1:=cstringconstnode.createpchar(ansistring2pchar(cstringpattern),length(cstringpattern));
                  consume(_CSTRING);
+                 if token in postfixoperator_tokens then
+                   begin
+                     again:=true;
+                     postfixoperators(p1,again,getaddr);
+                   end;
                end;
 
              _CCHAR :
@@ -2826,6 +2831,11 @@ implementation
                begin
                  p1:=cstringconstnode.createunistr(patternw);
                  consume(_CWSTRING);
+                 if token in postfixoperator_tokens then
+                   begin
+                     again:=true;
+                     postfixoperators(p1,again,getaddr);
+                   end;
                end;
 
              _CWCHAR:
@@ -2842,7 +2852,7 @@ implementation
                  if try_to_consume(_LKLAMMER) then
                   begin
                     p1:=factor(true,false);
-                    if token in [_CARET,_POINT,_LECKKLAMMER] then
+                    if token in postfixoperator_tokens then
                      begin
                        again:=true;
                        postfixoperators(p1,again,getaddr);
@@ -2852,7 +2862,7 @@ implementation
                   end
                  else
                   p1:=factor(true,false);
-                 if token in [_CARET,_POINT,_LECKKLAMMER] then
+                 if token in postfixoperator_tokens then
                   begin
                     again:=true;
                     postfixoperators(p1,again,getaddr);
@@ -2875,9 +2885,9 @@ implementation
                  consume(_LKLAMMER);
                  p1:=comp_expr(true,false);
                  consume(_RKLAMMER);
-                 { it's not a good solution     }
-                 { but (a+b)^ makes some problems  }
-                 if token in [_CARET,_POINT,_LECKKLAMMER] then
+                 { it's not a good solution
+                   but (a+b)^ makes some problems  }
+                 if token in postfixoperator_tokens then
                   begin
                     again:=true;
                     postfixoperators(p1,again,getaddr);

+ 2 - 0
compiler/tokens.pas

@@ -299,6 +299,8 @@ const
   tokenlenmin = 1;
   tokenlenmax = 18;
 
+  postfixoperator_tokens = [_CARET,_POINT,_LECKKLAMMER];
+
   { last operator which can be overloaded, the first_overloaded should
     be declared directly after NOTOKEN }
   first_overloaded = succ(NOTOKEN);

+ 14 - 0
tests/webtbs/tw23136.pp

@@ -0,0 +1,14 @@
+var
+ ws:widestring;
+ s:string;
+begin
+  s:='Aajsljaklsja'[1];
+  if s<>'A' then
+    halt(1);
+
+  ws:=#1234#134#312[1];
+  if ws<>#1234 then
+    halt(1);
+
+  writeln('ok');
+end.