Przeglądaj źródła

* partly revert 8cd6606970c8fedda95a3411d684dbd57379b46d, resolves #41052

(cherry picked from commit 854d4e6f4a5b53040160f8921d0089167f6b00be)
florian 7 miesięcy temu
rodzic
commit
d147488133
2 zmienionych plików z 28 dodań i 2 usunięć
  1. 2 2
      compiler/nadd.pas
  2. 26 0
      tests/webtbs/tw41052.pp

+ 2 - 2
compiler/nadd.pas

@@ -2825,9 +2825,9 @@ const
             case nodetype of
                equaln,unequaln :
                  begin
-                    if is_voidpointer(right.resultdef) and (left.nodetype<>niln) then
+                    if is_voidpointer(right.resultdef) then
                       inserttypeconv(right,left.resultdef)
-                    else if is_voidpointer(left.resultdef) and (right.nodetype<>niln) then
+                    else if is_voidpointer(left.resultdef) then
                       inserttypeconv(left,right.resultdef)
                     else if not(equal_defs(ld,rd)) then
                       IncompatibleTypes(ld,rd);

+ 26 - 0
tests/webtbs/tw41052.pp

@@ -0,0 +1,26 @@
+program project2;
+
+{$mode objfpc}
+{$inline on}
+
+function Func1(S: PAnsiChar): SizeUInt;
+begin
+  Result := 0;
+end;
+
+function Func2(S: PAnsiChar): SizeUInt; inline;
+begin
+  Result := Func1(S);
+  if S <> nil then S[Result] := #0;
+end;
+
+function Func3(S: PAnsiChar): SizeUInt; inline;
+begin
+  Result := Func1(S);
+  if Assigned(S) then S[Result] := #0;
+end;
+
+begin
+  Func2(nil); // <-- OK
+  Func3(nil); // <-- Error: Incompatible types: got "PAnsiChar" expected "Pointer"
+end.