This commit is contained in:
Ivan Bondarev 2023-07-02 19:46:57 +02:00
parent df15ece659
commit bb8c9543cf
3 changed files with 27 additions and 2 deletions

11
TestSuite/generics69.pas Normal file
View file

@ -0,0 +1,11 @@
procedure p2<T>;
begin
var a := new T[1];
//Ошибка: Невозможно преобразовать выражение типа array of T к не реализуемому этим типом интерфейсу IReadOnlyCollection<T>
var c := a as System.Collections.Generic.IReadOnlyCollection<T>;
assert(c.Count = 1);
end;
begin
p2&<integer>;
end.

View file

@ -59,6 +59,7 @@ namespace PascalABCCompiler.SystemLibrary
private static compiled_type_node _ienumerable_interface;
private static compiled_type_node _ilist1_interface;
private static compiled_type_node _icollection1_interface;
private static compiled_type_node _ireadonlycollection_interface;
private static compiled_type_node _ienumerable1_interface;
private static compiled_function_node _delegate_combine_method;
@ -1177,6 +1178,9 @@ namespace PascalABCCompiler.SystemLibrary
_icollection_interface = compiled_type_node.get_type_node(typeof(ICollection));
_ienumerable_interface = compiled_type_node.get_type_node(typeof(IEnumerable));
_ilist1_interface = compiled_type_node.get_type_node(typeof(IList<>));
var t = Type.GetType("System.Collections.Generic.IReadOnlyCollection`1");
if (t != null)
_ireadonlycollection_interface = compiled_type_node.get_type_node(t);
_icollection1_interface = compiled_type_node.get_type_node(typeof(ICollection<>));
_ienumerable1_interface = compiled_type_node.get_type_node(typeof(IEnumerable<>));
_assert_method = compiled_function_node.get_compiled_method(typeof(System.Diagnostics.Debug).GetMethod("Assert",new Type[1]{typeof(bool)}));
@ -5259,7 +5263,15 @@ namespace PascalABCCompiler.SystemLibrary
return _ienumerable1_interface;
}
}
public static compiled_type_node ireadonlycollection_interface
{
get
{
return _ireadonlycollection_interface;
}
}
public static compiled_function_node assert_method
{
get

View file

@ -109,7 +109,9 @@ namespace PascalABCCompiler.TreeConverter
comtn.ImplementingInterfaces.Add(SystemLibrary.SystemLibrary.ilist1_interface.get_instance(type_params));
comtn.ImplementingInterfaces.Add(SystemLibrary.SystemLibrary.icollection1_interface.get_instance(type_params));
comtn.ImplementingInterfaces.Add(SystemLibrary.SystemLibrary.ienumerable1_interface.get_instance(type_params));
}
if (SystemLibrary.SystemLibrary.ireadonlycollection_interface != null)
comtn.ImplementingInterfaces.Add(SystemLibrary.SystemLibrary.ireadonlycollection_interface.get_instance(type_params));
}
//SystemLibrary.SystemLibrary.ic
//(ssyy) Убрал 18.05.08
//if (this.convertion_data_and_alghoritms.syntax_tree_visitor.context.converted_namespace != null)