This commit is contained in:
parent
3725e0fc65
commit
198faa5bf5
21
TestSuite/implicitexplicit15.pas
Normal file
21
TestSuite/implicitexplicit15.pas
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
type TClass = auto class
|
||||
i: integer;
|
||||
end;
|
||||
|
||||
function operator implicit<T>(s: sequence of T): array of T; extensionmethod;
|
||||
begin
|
||||
Result := s.ToArray;
|
||||
end;
|
||||
|
||||
begin
|
||||
var a: array of TClass;
|
||||
var s := Seq(new TClass(1), new TClass(2));
|
||||
a := s;
|
||||
assert(a[0].i = 1);
|
||||
assert(a[1].i = 2);
|
||||
var a2: array of integer;
|
||||
var s2 := Seq(1, 2);
|
||||
a2 := s2;
|
||||
assert(a2[0] = 1);
|
||||
assert(a2[1] = 2);
|
||||
end.
|
||||
20
TestSuite/implicitexplicit16.pas
Normal file
20
TestSuite/implicitexplicit16.pas
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
type
|
||||
t1 = class
|
||||
|
||||
public static function operator implicit<T>(a: array of T): t1 := nil;
|
||||
|
||||
end;
|
||||
|
||||
procedure p1<T>;
|
||||
begin
|
||||
//Ошибка: Нельзя преобразовать тип array of T к t1
|
||||
var o: t1 := new T[5];
|
||||
assert(o = nil);
|
||||
end;
|
||||
|
||||
begin
|
||||
//Ошибка: Нельзя преобразовать тип array of byte к t1
|
||||
var o: t1 := new byte[5];
|
||||
assert(o = nil);
|
||||
p1&<integer>;
|
||||
end.
|
||||
|
|
@ -1106,7 +1106,9 @@ namespace PascalABCCompiler.NetHelper
|
|||
if (si.sym_info is common_namespace_function_node)
|
||||
{
|
||||
function_node fn = si.sym_info as function_node;
|
||||
if ((fn.return_value_type == to || fn.return_value_type.original_generic == to) &&
|
||||
if ((fn.return_value_type == to || fn.return_value_type.original_generic == to
|
||||
|| to.type_special_kind == type_special_kind.array_kind && fn.return_value_type != null && fn.return_value_type.type_special_kind == type_special_kind.array_kind
|
||||
&& fn.return_value_type.element_type.is_generic_parameter) &&
|
||||
fn.parameters.Count == 1 &&
|
||||
(fn.parameters[0].type == from || fn.parameters[0].type.original_generic == from)
|
||||
|| fn.parameters[0].type.type_special_kind == type_special_kind.array_kind && fn.parameters[0].type.element_type.is_generic_parameter)
|
||||
|
|
|
|||
|
|
@ -881,6 +881,8 @@ namespace PascalABCCompiler.TreeRealization
|
|||
return true;
|
||||
if (left is ref_type_node && right is ref_type_node)
|
||||
return is_type_or_original_generics_equal((left as ref_type_node).pointed_type, (right as ref_type_node).pointed_type);
|
||||
if (left.type_special_kind == SemanticTree.type_special_kind.array_kind && right.type_special_kind == SemanticTree.type_special_kind.array_kind)
|
||||
return is_type_or_original_generics_equal(left.element_type, right.element_type);
|
||||
return left == right;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue