Browse Source

* explicitly check for stringconstn next to stringdef in nadd, because
a stringconstn is often an arraydef. The result is that they again
get the same typeconversion behaviour as string variables, which is
important in case of overloaded operators (#9021/#9026)

git-svn-id: trunk@8268 -

Jonas Maebe 18 years ago
parent
commit
3f701c96d4
3 changed files with 32 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 3 0
      compiler/nadd.pas
  3. 28 0
      tests/webtbs/tw9026.pp

+ 1 - 0
.gitattributes

@@ -8341,6 +8341,7 @@ tests/webtbs/tw8950.pp svneol=native#text/plain
 tests/webtbs/tw8975.pp svneol=native#text/plain
 tests/webtbs/tw8975a.pp svneol=native#text/plain
 tests/webtbs/tw8977.pp svneol=native#text/plain
+tests/webtbs/tw9026.pp svneol=native#text/plain
 tests/webtbs/tw9054.pp svneol=native#text/plain
 tests/webtbs/tw9059.pp svneol=native#text/plain
 tests/webtbs/tw9073.pp svneol=native#text/plain

+ 3 - 0
compiler/nadd.pas

@@ -1314,6 +1314,9 @@ implementation
            pchar is converted to string }
          else if (rd.typ=stringdef) or
                  (ld.typ=stringdef) or
+                 { stringconstn's can be arraydefs }
+                 (lt=stringconstn) or
+                 (rt=stringconstn) or
                  ((is_pchar(rd) or is_chararray(rd) or is_char(rd) or is_open_chararray(rd) or
                    is_pwidechar(rd) or is_widechararray(rd) or is_widechar(rd) or is_open_widechararray(rd)) and
                   (is_pchar(ld) or is_chararray(ld) or is_char(ld) or is_open_chararray(ld) or

+ 28 - 0
tests/webtbs/tw9026.pp

@@ -0,0 +1,28 @@
+operator := (input:extended) output: string;
+begin
+   str(round(input),output);
+end;
+
+operator + (const s: string; input:extended) output: string;
+begin
+   str(round(input),output);
+   output:=s+output;
+end;
+
+procedure test(a:string);
+begin
+   writeln(a);
+   if (a <> 'help1') then
+     halt(1);
+end;
+
+var
+s: string;
+begin
+   s:='help';
+   test('help'+1);
+   test(s+1);
+   test(s+1.2);
+   test(s+extended(1.2));
+   test(s+string(1.2));
+end.