浏览代码

* give an error when trying to call an interface/protocol/category method
using the type name of the interface/protcol/category (they are not
entities themselves on which you can invoke those methods,
mantis #20661)

git-svn-id: trunk@19651 -

Jonas Maebe 13 年之前
父节点
当前提交
84bf45f0e2
共有 3 个文件被更改,包括 49 次插入0 次删除
  1. 1 0
      .gitattributes
  2. 8 0
      compiler/ncal.pas
  3. 40 0
      tests/webtbf/tw20661.pp

+ 1 - 0
.gitattributes

@@ -11003,6 +11003,7 @@ tests/webtbf/tw2046.pp svneol=native#text/plain
 tests/webtbf/tw2053.pp svneol=native#text/plain
 tests/webtbf/tw2053.pp svneol=native#text/plain
 tests/webtbf/tw2053b.pp svneol=native#text/plain
 tests/webtbf/tw2053b.pp svneol=native#text/plain
 tests/webtbf/tw20580.pp svneol=native#text/pascal
 tests/webtbf/tw20580.pp svneol=native#text/pascal
+tests/webtbf/tw20661.pp svneol=native#text/plain
 tests/webtbf/tw2070.pp svneol=native#text/plain
 tests/webtbf/tw2070.pp svneol=native#text/plain
 tests/webtbf/tw2128.pp svneol=native#text/plain
 tests/webtbf/tw2128.pp svneol=native#text/plain
 tests/webtbf/tw2129.pp svneol=native#text/plain
 tests/webtbf/tw2129.pp svneol=native#text/plain

+ 8 - 0
compiler/ncal.pas

@@ -2971,6 +2971,14 @@ implementation
                   CGMessage(cg_e_cant_call_abstract_method);
                   CGMessage(cg_e_cant_call_abstract_method);
               end;
               end;
 
 
+            { directly calling an interface/protocol/category/class helper
+              method via its type is not possible (always must be called via
+              the actual instance) }
+            if (methodpointer.nodetype=typen) and
+               (is_interface(methodpointer.resultdef) or
+                is_objc_protocol_or_category(methodpointer.resultdef)) then
+              CGMessage1(type_e_class_type_expected,methodpointer.resultdef.typename);
+
             { if an inherited con- or destructor should be  }
             { if an inherited con- or destructor should be  }
             { called in a con- or destructor then a warning }
             { called in a con- or destructor then a warning }
             { will be made                                  }
             { will be made                                  }

+ 40 - 0
tests/webtbf/tw20661.pp

@@ -0,0 +1,40 @@
+{ %fail }
+
+unit tw20661;
+
+{$mode objfpc}{$H+}
+
+interface
+
+const
+  PrescriptionStorageIntfId = '{C2F3C9F6-657C-4974-841A-4EBFF33B2180}';//'blik.prescriptionstorage';
+  DatasetProviderIntfId = '{B0B1501A-9266-48EA-B2E0-7EF23511D799}';
+
+type
+  IDatasetPool = interface
+    ['{F866EB5B-5B32-438E-918E-A56B031C73DA}']
+    procedure ReleaseDataset(Instance: pointer);
+  end;
+
+  { TBlikServices }
+
+  TBlikServices = class
+  public
+    procedure ReleaseDataset(Instance: pointer);
+  end;
+
+var
+  Services: TBlikServices;
+
+implementation
+
+{ TBlikServices }
+
+procedure TBlikServices.ReleaseDataset(Instance: pointer);
+begin
+  IDatasetPool.ReleaseDataset(Instance);
+end;
+
+end.
+
+