Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ibond84 committed Aug 2, 2016
1 parent 67e433a commit 2e9800d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
7 changes: 7 additions & 0 deletions TestSuite/errors/err0221.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type TNode<T> = class;
TNode<T1> = class
a: T1;
end;
begin

end.
19 changes: 19 additions & 0 deletions TestSuite/generic_predef1.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type TNode<T> = class;
TList<T> = class
node: TNode<T>;
end;

TNode<T> = class
a: T;
lst: TList<T>;
end;

begin
var n := new TNode<integer>;
n.a := 1;
var lst := new TList<integer>;
lst.node := n;
n.lst := lst;
assert(n.a = 1);
assert(lst.node.a = 1);
end.
34 changes: 30 additions & 4 deletions TreeConverter/TreeConversion/syntax_tree_visitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10482,11 +10482,19 @@ _type_declaration.type_def is SyntaxTree.ref_type || _type_declaration.type_def
//Ошибка, т.к. нет списка шаблонных параметров.
AddError(get_location(_type_declaration.type_name), "TEMPLATE_PARAMS_EXPECTED");
}
bool predefined_generic = false;
if (is_generic)
{
context.check_name_free(_type_declaration.type_name.name, get_location(_type_declaration.type_name));
SymbolInfo si = context.find_only_in_namespace(_type_declaration.type_name.name + compiler_string_consts.generic_params_infix +
cl_def.template_args.idents.Count.ToString());
if (!(si != null && si.sym_info is common_type_node && context.types_predefined.IndexOf(si.sym_info as common_type_node) != -1))
{
context.check_name_free(_type_declaration.type_name.name, get_location(_type_declaration.type_name));
}
else
predefined_generic = true;
_type_declaration.type_name.name += compiler_string_consts.generic_params_infix +
cl_def.template_args.idents.Count.ToString();
cl_def.template_args.idents.Count.ToString();
}
if (cl_def.keyword == SyntaxTree.class_keyword.Record)
{
Expand Down Expand Up @@ -10516,9 +10524,27 @@ _type_declaration.type_def is SyntaxTree.ref_type || _type_declaration.type_def
assign_doc_info(ctn,_type_declaration);
if (is_generic)
{
context.create_generic_indicator(ctn);
visit_generic_params(ctn, cl_def.template_args.idents);
if (predefined_generic)
{
if (ctn.generic_params.Count != cl_def.template_args.idents.Count)
AddError(get_location(cl_def.template_args), "GENERIC_PARAMETERS_MISMATCH");
foreach (ident id in cl_def.template_args.idents)
{
SymbolInfo si = ctn.find_in_type(id.name);
if (si == null)
AddError(get_location(cl_def.template_args), "GENERIC_PARAMETERS_MISMATCH");
if (!(si.sym_info is common_type_node && (si.sym_info as common_type_node).is_generic_parameter))
AddError(get_location(cl_def.template_args), "GENERIC_PARAMETERS_MISMATCH");
}
}
else
{
context.create_generic_indicator(ctn);
visit_generic_params(ctn, cl_def.template_args.idents);
}
}
if (predefined_generic && cl_def.where_section != null && cl_def.where_section.defs.Count > 0)
AddError(get_location(cl_def.where_section), "WHERE_SECTION_NOT_ALLOWED");
visit_where_list(cl_def.where_section);
CheckWaitedRefTypes(ctn);
is_direct_type_decl = true;
Expand Down
2 changes: 2 additions & 0 deletions bin/Lng/Eng/SemanticErrors_ib.dat
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ IMPLICIT_EXPLICIT_OPERATOR_EXTENSION_ONLY_FOR_COMPILED_CLASSES_ALLOWED=Operators
EXTENSIONMETHOD_KEYWORD_NOT_ALLOWED=extensionmethod is not allowed in this context
CANNOT_EXTEND_STANDARD_OPERATORS_FOR_DELEGATE=Can not extend operators +,+=,-,-= for delegates
FORWARD_EXTENSION_METHODS_NOT_ALLOWED=forward attribute can not be applied to extension methods
WHERE_SECTION_NOT_ALLOWED=Can not apply 'where' to predefined class
GENERIC_PARAMETERS_MISMATCH=Generic-parameters mismatch
%PREFIX%=COMPILATIONERROR_
UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Unit expected, library found
ASSEMBLY_{0}_READING_ERROR=Error by reading assembly '{0}'
Expand Down
2 changes: 2 additions & 0 deletions bin/Lng/Rus/SemanticErrors_ib.dat
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ IMPLICIT_EXPLICIT_OPERATOR_EXTENSION_ONLY_FOR_COMPILED_CLASSES_ALLOWED=extension
EXTENSIONMETHOD_KEYWORD_NOT_ALLOWED=Атрибут extensionmethod недопустим в данном контексте
CANNOT_EXTEND_STANDARD_OPERATORS_FOR_DELEGATE=Нельзя раширять операции +,+=,-,-= для делегатов
FORWARD_EXTENSION_METHODS_NOT_ALLOWED=Атрибут forward недопустим для методов расширения
WHERE_SECTION_NOT_ALLOWED=Секция where недопустима в данном контексте
GENERIC_PARAMETERS_MISMATCH=Generic-параметры не совпадают с generic-параметрами в предописании типа
%PREFIX%=COMPILATIONERROR_
UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Ожидался модуль, а встречена библиотека
ASSEMBLY_{0}_READING_ERROR=Ошибка при чтении сборки '{0}'
Expand Down

0 comments on commit 2e9800d

Please sign in to comment.