Browse Source

Fix for Mantis #29546.

htypechk.pas, tcallcandidates:
  * create_candidate_list: don't check whether the pd is a specialization if the owner is valid; happens if a generic method is used more than once (which should happen here and then :P )

+ added test

git-svn-id: trunk@33037 -
svenbarth 9 years ago
parent
commit
05174f3e67
3 changed files with 31 additions and 4 deletions
  1. 1 0
      .gitattributes
  2. 1 4
      compiler/htypechk.pas
  3. 29 0
      tests/webtbs/tw29546.pp

+ 1 - 0
.gitattributes

@@ -14933,6 +14933,7 @@ tests/webtbs/tw2944.pp svneol=native#text/plain
 tests/webtbs/tw2946.pp svneol=native#text/plain
 tests/webtbs/tw2949.pp svneol=native#text/plain
 tests/webtbs/tw2953.pp svneol=native#text/plain
+tests/webtbs/tw29546.pp svneol=native#text/pascal
 tests/webtbs/tw2956.pp svneol=native#text/plain
 tests/webtbs/tw2958.pp svneol=native#text/plain
 tests/webtbs/tw2966.pp svneol=native#text/plain

+ 1 - 4
compiler/htypechk.pas

@@ -2472,10 +2472,7 @@ implementation
                   )
                 ) or
                 (
-                  (
-                    not pd.is_specialization and
-                    assigned(pd.owner)
-                  ) and
+                  assigned(pd.owner) and
                   (
                     not (pd.owner.symtabletype in [objectsymtable,recordsymtable]) or
                     is_visible_for_object(pd,contextstructdef)

+ 29 - 0
tests/webtbs/tw29546.pp

@@ -0,0 +1,29 @@
+{ %NORUN }
+
+program tw29546;
+
+{$mode objfpc}
+
+type
+  TUtils = class sealed(TObject)
+  public
+    generic class function Iif<T>(ACondition: Boolean;
+      const ATrueValue, AFalseValue: T): T; static;
+  end;
+
+  generic class function TUtils.Iif<T>(ACondition: Boolean;
+    const ATrueValue, AFalseValue: T): T;
+  begin
+    if ACondition then
+      Result := ATrueValue
+    else
+      Result := AFalseValue;
+  end;
+
+var
+  S: string;
+begin
+  S := TUtils.specialize Iif<string>(False, 'YES', 'NO');
+  S := TUtils.specialize Iif<string>(True, 'YES', 'NO');
+end.
+