瀏覽代碼

* set addn resultdef when evaluating constant string concatenation
instead of letting the resulting stringconstn decide for itself
(mantis #14174)

git-svn-id: trunk@13419 -

Jonas Maebe 16 年之前
父節點
當前提交
63ce04fd00
共有 3 個文件被更改,包括 42 次插入1 次删除
  1. 1 0
      .gitattributes
  2. 5 1
      compiler/nadd.pas
  3. 36 0
      tests/webtbs/tw14174.pp

+ 1 - 0
.gitattributes

@@ -9211,6 +9211,7 @@ tests/webtbs/tw1414.pp svneol=native#text/plain
 tests/webtbs/tw14143.pp svneol=native#text/plain
 tests/webtbs/tw14155.pp svneol=native#text/plain
 tests/webtbs/tw1416.pp svneol=native#text/plain
+tests/webtbs/tw14174.pp svneol=native#text/plain
 tests/webtbs/tw1430.pp svneol=native#text/plain
 tests/webtbs/tw1433.pp svneol=native#text/plain
 tests/webtbs/tw1445.pp svneol=native#text/plain

+ 5 - 1
compiler/nadd.pas

@@ -666,7 +666,11 @@ implementation
           begin
              case nodetype of
                 addn :
-                  t:=cstringconstnode.createpchar(concatansistrings(s1,s2,l1,l2),l1+l2);
+                  begin
+                    t:=cstringconstnode.createpchar(concatansistrings(s1,s2,l1,l2),l1+l2);
+                    typecheckpass(t);
+                    tstringconstnode(t).changestringtype(resultdef);
+                  end;
                 ltn :
                   t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<0),booltype,true);
                 lten :

+ 36 - 0
tests/webtbs/tw14174.pp

@@ -0,0 +1,36 @@
+program Test;
+
+type
+  TToken = (
+    tkNil,tkEOF,tkNumber,tkOpenBrace,tkCloseBrace,
+    tkPlus,tkMinus,tkTimes,tkSlash,tkCaret,tkSemiColon
+  );
+
+function TokenToStr(const Token: TToken): String;
+
+  function Quote(const S: String): String;
+  inline; // comment out to avoid the internal error
+  begin
+    Quote:='"'+S+'"';
+  end;
+
+begin
+  case Token of
+    tkNil : TokenToStr:=Quote('Unknown');
+    tkEOF : TokenToStr:=Quote('EOF');
+    tkNumber : TokenToStr:=Quote('Number');
+    tkOpenBrace : TokenToStr:=Quote('(');
+    tkCloseBrace: TokenToStr:=Quote(')');
+    tkPlus : TokenToStr:=Quote('+');
+    tkMinus : TokenToStr:=Quote('-');
+    tkTimes : TokenToStr:=Quote('*');
+    tkSlash : TokenToStr:=Quote('/');
+    tkCaret : TokenToStr:=Quote('^');
+    tkSemiColon : TokenToStr:=Quote(';');
+  end;
+end;
+
+begin
+  if (TokenToStr(tkNil)<>'"Unknown"') then
+    halt(1);
+end.