bug fix #2086
This commit is contained in:
parent
6ba1ca8716
commit
259b3c34b5
42
TestSuite/generics38.pas
Normal file
42
TestSuite/generics38.pas
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
type
|
||||
Comp1 = class(System.Collections.Generic.EqualityComparer<byte>)
|
||||
|
||||
public function Equals(x, y: byte): boolean; override :=
|
||||
x = y;
|
||||
|
||||
public function GetHashCode(obj: byte): integer; override :=
|
||||
obj.GetHashCode;
|
||||
|
||||
end;
|
||||
|
||||
t0 = class end;
|
||||
|
||||
|
||||
Comp2 = class(System.Collections.Generic.EqualityComparer<t0>)
|
||||
|
||||
public function Equals(x, y: t0): boolean; override :=
|
||||
x = y;
|
||||
|
||||
public function GetHashCode(obj: t0): integer; override :=
|
||||
obj.GetHashCode;
|
||||
|
||||
end;
|
||||
|
||||
Comp<T> = class(System.Collections.Generic.EqualityComparer<T>)
|
||||
|
||||
public function Equals(x, y: T): boolean; override :=
|
||||
x = y;
|
||||
|
||||
public function GetHashCode(obj: T): integer; override :=
|
||||
obj.GetHashCode;
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
var o := new Comp2;
|
||||
var t0obj := new t0;
|
||||
assert(o.Equals(new t0, new t0) = false);
|
||||
assert(o.Equals(t0obj, t0obj));
|
||||
var o2 := new Comp<integer>;
|
||||
assert(o2.Equals(2, 2));
|
||||
end.
|
||||
|
|
@ -1388,7 +1388,7 @@ namespace PascalABCCompiler.NetHelper
|
|||
}
|
||||
common_type_node curr_type = SystemLibrary.SystemLibrary.syn_visitor.context.converted_type;
|
||||
compiled_type_node comp_node = compiled_type_node.get_type_node(mi.DeclaringType);
|
||||
return curr_type != null && type_table.is_derived(comp_node, curr_type);
|
||||
return curr_type != null && type_table.is_derived(comp_node, curr_type, true);
|
||||
}
|
||||
|
||||
public static List<SymbolInfo> GetConstructor(Type t)
|
||||
|
|
|
|||
|
|
@ -1333,6 +1333,7 @@ namespace PascalABCCompiler.TreeRealization
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -345,13 +345,15 @@ namespace PascalABCCompiler.TreeRealization
|
|||
}
|
||||
}
|
||||
|
||||
public static bool is_derived(type_node base_class, type_node derived_class)
|
||||
public static bool is_derived(type_node base_class, type_node derived_class, bool ignore_generic_instances=false)
|
||||
{
|
||||
if (derived_class == null) //void?
|
||||
return false;
|
||||
if (base_class == null)
|
||||
return false;
|
||||
type_node tn = derived_class.base_type;
|
||||
if (tn is compiled_generic_instance_type_node && ignore_generic_instances)
|
||||
tn = tn.original_generic;
|
||||
//TODO: Проверить на ссылочный и размерный тип.
|
||||
if (derived_class.semantic_node_type == semantic_node_type.null_type_node)
|
||||
if (is_with_nil_allowed(base_class) || base_class.IsPointer)
|
||||
|
|
|
|||
Loading…
Reference in a new issue