#2396
This commit is contained in:
Ivan Bondarev 2021-01-08 19:00:40 +01:00
parent af1b9b85f4
commit 12b365650f
4 changed files with 77 additions and 3 deletions

View file

@ -903,6 +903,25 @@ namespace PascalABCCompiler.PCU
foreach (statement_node st in stmt_list.statements)
AddIndirectUsedUnitsInStatement(st, ns_dict, interf);
}
/*else if (stmt is common_static_method_call)
{
common_static_method_call csmc = stmt as common_static_method_call;
AddIndirectUsedUnitsForType(csmc.common_type, ns_dict, interf);
}
else if (stmt is if_node)
{
if_node node = stmt as if_node;
AddIndirectUsedUnitsInStatement(node.condition, ns_dict, interf);
}
if (stmt is base_function_call)
{
base_function_call bfc = stmt as base_function_call;
foreach (var expr in bfc.parameters)
{
AddIndirectUsedUnitsInStatement(expr, ns_dict, interf);
}
}*/
}

View file

@ -0,0 +1,25 @@
var i: integer;
type
t0 = class end;
t1 = class
static function operator implicit<T>(o: T): t1;
where T: record;
begin
i := 1;
end;
static function operator implicit(o: t0): t1;
begin
i := 2;
end;
end;
procedure p1(q: t1) := exit;
begin
p1(new t0);
assert(i = 2);
end.

View file

@ -0,0 +1,19 @@
var i: integer;
type
t1 = class
static function operator implicit<T>(o: T): t1;
where T: record;
begin
i := 1;
end;
end;
t2<T> = class(t1) end;
procedure p1(q: t1) := exit;
begin
//Ошибка: Невозможно инстанцировать, так как тип t2<byte> не является размерным
p1(new t2<byte>);
assert(i = 0);
end.

View file

@ -2321,7 +2321,12 @@ namespace PascalABCCompiler.TreeRealization
{
if (this.instance_params != null && this.instance_params.Count > 0)
{
fn = fn.get_instance(this.instance_params, true, null);
if (fn.parameters[0].type.is_generic_parameter)
fn = fn.get_instance(new List<type_node>() { this }, false, null);
else
fn = fn.get_instance(this.instance_params, false, null);
if (fn == null)
continue;
}
else if (ctn.instance_params != null && ctn.instance_params.Count > 0)
{
@ -2332,6 +2337,8 @@ namespace PascalABCCompiler.TreeRealization
if (ctn.IsPointer)
continue;
fn = fn.get_instance(new List<type_node>(new type_node[] { ctn }), false, null);
if (fn == null)
continue;
}
}
return fn;
@ -2363,9 +2370,11 @@ namespace PascalABCCompiler.TreeRealization
else if (ctn.instance_params != null && ctn.instance_params.Count > 0)
{
if (fn.parameters[0].type.is_generic_parameter)
fn = fn.get_instance(new List<type_node>() { ctn }, true, null);
fn = fn.get_instance(new List<type_node>() { ctn }, false, null);
else
fn = fn.get_instance(ctn.instance_params, true, null);
fn = fn.get_instance(ctn.instance_params, false, null);
if (fn == null)
continue;
}
else if (fn.get_generic_params_list() != null && fn.get_generic_params_list().Count > 0)
{
@ -2374,6 +2383,8 @@ namespace PascalABCCompiler.TreeRealization
if (ctn.IsPointer)
continue;
fn = fn.get_instance(new List<type_node>(new type_node[] { ctn }), false, null);
if (fn == null)
continue;
}
}
return fn;