From 434f846ee4e64012a89ec7211176015fb6503aea Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Mon, 10 Aug 2020 23:07:02 +0300 Subject: [PATCH] fix #2289 --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 4 ++-- Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- TestSuite/class_interf.pas | 18 ++++++++++++++++++ .../convertion_data_and_alghoritms.cs | 10 ++++++++++ .../TreeConversion/syntax_tree_visitor.cs | 5 ++++- 7 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 TestSuite/class_interf.pas diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index ddd6c8706..797a8a0a2 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "6"; public const string Build = "3"; - public const string Revision = "2616"; + public const string Revision = "2617"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index ebe6a7d93..f02796822 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%COREVERSION%=3 -%REVISION%=2616 %MINOR%=6 +%REVISION%=2617 +%COREVERSION%=3 %MAJOR%=3 diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index 7ef9ebd74..79e193b03 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.6.3.2616 +3.6.3.2617 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index 3ac4356f2..3fe1c1a74 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.6.3.2616' +!define VERSION '3.6.3.2617' diff --git a/TestSuite/class_interf.pas b/TestSuite/class_interf.pas new file mode 100644 index 000000000..f51781283 --- /dev/null +++ b/TestSuite/class_interf.pas @@ -0,0 +1,18 @@ +type + i1 = interface + procedure p; + end; + + c1 = abstract class(i1) + public + procedure p; + begin + Assert(111=111); + end; + end; + c2 = sealed class(c1) end; + +begin + var a := new c2 as i1; + a.P +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs index 5e9d459be..d3c0c4212 100644 --- a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs +++ b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs @@ -1561,6 +1561,16 @@ namespace PascalABCCompiler.TreeConverter return eq_type_nodes(tn1, tn2, false); } + public static bool type_or_base_type_implements_interface(type_node tn, type_node interf) + { + do { + if (tn.ImplementingInterfaces.Contains(interf)) + return true; + tn = tn.base_type; + } while (tn != null); + return false; + } + //Этот метод сверяет не только параметры, но и возвращаемое значение public static bool function_eq_params_and_result(function_node left, function_node right, bool weak = false) { diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 756ccd262..61e9c81de 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -3066,6 +3066,7 @@ namespace PascalABCCompiler.TreeConverter weak_node_test_and_visit(_interface_node.interface_definitions); } + public override void visit(SyntaxTree.typecast_node node) { @@ -3093,7 +3094,9 @@ namespace PascalABCCompiler.TreeConverter { AddError(loc, "EXPECTED_DERIVED_CLASSES"); } - if (en.type.IsSealed && tp.IsInterface && !en.type.ImplementingInterfaces.Contains(tp)) + if (en.type.IsSealed && tp.IsInterface && /*!en.type.ImplementingInterfaces.Contains(tp)*/ + !convertion_data_and_alghoritms.type_or_base_type_implements_interface(en.type,tp) + ) { AddError(loc, "CAN_NOT_CONVERT_TYPE_{0}_TO_INTERFACE_{1}", en.type.PrintableName, tp.PrintableName); }