This commit is contained in:
Бондарев Иван 2018-05-06 12:48:01 +02:00
parent b6aa4d9c90
commit c2c5196298
2 changed files with 46 additions and 2 deletions

38
TestSuite/cast3.pas Normal file
View file

@ -0,0 +1,38 @@
type TClass<T> = class(System.Collections.Generic.IComparer<TClass<T>>)
i: integer;
public function Compare(a, b: TClass<T>): integer;
begin
Result := integer(a.i > b.i);
end;
end;
begin
var o:object := new System.Collections.Generic.List<byte>();
var e := System.Collections.Generic.List&<byte>(o);
assert(e.Count = 0);
e := o as System.Collections.Generic.List<byte>;
assert(e.Count = 0);
var a := 0;
if o is System.Collections.Generic.List&<byte> then
a := 1;
assert(a = 1);
o := 'abc';
var s := string(o);
var s1 := o as string;
assert(o as string = 'abc');
assert(string(o) = 'abc');
assert(s = 'abc');
assert(s1 = 'abc');
o := 2;
assert(integer(o) = 2);
o := new List<integer>;
assert((o as List<integer>).Count = 0);
assert(List&<integer>(o).Count = 0);
o := new TClass<integer>;
(o as TClass<integer>).i := 2;
assert((o as System.Collections.Generic.IComparer<TClass<integer>>) <> nil);
var cmp := System.Collections.Generic.IComparer&<TClass<integer>>(o);
assert(cmp.Compare(o as TClass<integer>,o as TClass<integer>) = 0);
cmp := o as System.Collections.Generic.IComparer<TClass<integer>>;
assert(cmp.Compare(TClass&<integer>(o),TClass&<integer>(o)) = 0);
end.

View file

@ -5401,12 +5401,18 @@ namespace PascalABCCompiler.TreeConverter
sil = nsn.find(id_right.name);
if (templ_args_count != 0)
{
SymbolInfo conv = ConvertTypeToInstance(sil?.FirstOrDefault(), iwt.template_params.params_list, get_location(id_right));
sil = nsn.find(id_right.name + compiler_string_consts.generic_params_infix + templ_args_count.ToString());
if (sil != null)
{
sil = new List<SymbolInfo> { new SymbolInfo(get_generic_instance(sil?.FirstOrDefault(), iwt.template_params.params_list)) };
iwt = null;
}
/*SymbolInfo conv = ConvertTypeToInstance(sil?.FirstOrDefault(), iwt.template_params.params_list, get_location(id_right));
if (conv != null)
{
sil = new List<SymbolInfo> { conv };
iwt = null;
}
}*/
}
}
}