From 05174f3e6795b7ce2964bd3e5399d12a718b3a01 Mon Sep 17 00:00:00 2001
From: svenbarth <pascaldragon@googlemail.com>
Date: Sun, 31 Jan 2016 17:14:44 +0000
Subject: [PATCH] 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 -
---
 .gitattributes          |  1 +
 compiler/htypechk.pas   |  5 +----
 tests/webtbs/tw29546.pp | 29 +++++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 4 deletions(-)
 create mode 100644 tests/webtbs/tw29546.pp

diff --git a/.gitattributes b/.gitattributes
index dc4dac28ec..fb0bf4ad74 100644
--- a/.gitattributes
+++ b/.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
diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas
index c776735542..78e092dea2 100644
--- a/compiler/htypechk.pas
+++ b/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)
diff --git a/tests/webtbs/tw29546.pp b/tests/webtbs/tw29546.pp
new file mode 100644
index 0000000000..31174b77d3
--- /dev/null
+++ b/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.
+