Skip to content

Commit 2e9800d

Browse files
committed
1 parent 67e433a commit 2e9800d

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

TestSuite/errors/err0221.pas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type TNode<T> = class;
2+
TNode<T1> = class
3+
a: T1;
4+
end;
5+
begin
6+
7+
end.

TestSuite/generic_predef1.pas

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
type TNode<T> = class;
2+
TList<T> = class
3+
node: TNode<T>;
4+
end;
5+
6+
TNode<T> = class
7+
a: T;
8+
lst: TList<T>;
9+
end;
10+
11+
begin
12+
var n := new TNode<integer>;
13+
n.a := 1;
14+
var lst := new TList<integer>;
15+
lst.node := n;
16+
n.lst := lst;
17+
assert(n.a = 1);
18+
assert(lst.node.a = 1);
19+
end.

TreeConverter/TreeConversion/syntax_tree_visitor.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10482,11 +10482,19 @@ _type_declaration.type_def is SyntaxTree.ref_type || _type_declaration.type_def
1048210482
//Ошибка, т.к. нет списка шаблонных параметров.
1048310483
AddError(get_location(_type_declaration.type_name), "TEMPLATE_PARAMS_EXPECTED");
1048410484
}
10485+
bool predefined_generic = false;
1048510486
if (is_generic)
1048610487
{
10487-
context.check_name_free(_type_declaration.type_name.name, get_location(_type_declaration.type_name));
10488+
SymbolInfo si = context.find_only_in_namespace(_type_declaration.type_name.name + compiler_string_consts.generic_params_infix +
10489+
cl_def.template_args.idents.Count.ToString());
10490+
if (!(si != null && si.sym_info is common_type_node && context.types_predefined.IndexOf(si.sym_info as common_type_node) != -1))
10491+
{
10492+
context.check_name_free(_type_declaration.type_name.name, get_location(_type_declaration.type_name));
10493+
}
10494+
else
10495+
predefined_generic = true;
1048810496
_type_declaration.type_name.name += compiler_string_consts.generic_params_infix +
10489-
cl_def.template_args.idents.Count.ToString();
10497+
cl_def.template_args.idents.Count.ToString();
1049010498
}
1049110499
if (cl_def.keyword == SyntaxTree.class_keyword.Record)
1049210500
{
@@ -10516,9 +10524,27 @@ _type_declaration.type_def is SyntaxTree.ref_type || _type_declaration.type_def
1051610524
assign_doc_info(ctn,_type_declaration);
1051710525
if (is_generic)
1051810526
{
10519-
context.create_generic_indicator(ctn);
10520-
visit_generic_params(ctn, cl_def.template_args.idents);
10527+
if (predefined_generic)
10528+
{
10529+
if (ctn.generic_params.Count != cl_def.template_args.idents.Count)
10530+
AddError(get_location(cl_def.template_args), "GENERIC_PARAMETERS_MISMATCH");
10531+
foreach (ident id in cl_def.template_args.idents)
10532+
{
10533+
SymbolInfo si = ctn.find_in_type(id.name);
10534+
if (si == null)
10535+
AddError(get_location(cl_def.template_args), "GENERIC_PARAMETERS_MISMATCH");
10536+
if (!(si.sym_info is common_type_node && (si.sym_info as common_type_node).is_generic_parameter))
10537+
AddError(get_location(cl_def.template_args), "GENERIC_PARAMETERS_MISMATCH");
10538+
}
10539+
}
10540+
else
10541+
{
10542+
context.create_generic_indicator(ctn);
10543+
visit_generic_params(ctn, cl_def.template_args.idents);
10544+
}
1052110545
}
10546+
if (predefined_generic && cl_def.where_section != null && cl_def.where_section.defs.Count > 0)
10547+
AddError(get_location(cl_def.where_section), "WHERE_SECTION_NOT_ALLOWED");
1052210548
visit_where_list(cl_def.where_section);
1052310549
CheckWaitedRefTypes(ctn);
1052410550
is_direct_type_decl = true;

bin/Lng/Eng/SemanticErrors_ib.dat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ IMPLICIT_EXPLICIT_OPERATOR_EXTENSION_ONLY_FOR_COMPILED_CLASSES_ALLOWED=Operators
121121
EXTENSIONMETHOD_KEYWORD_NOT_ALLOWED=extensionmethod is not allowed in this context
122122
CANNOT_EXTEND_STANDARD_OPERATORS_FOR_DELEGATE=Can not extend operators +,+=,-,-= for delegates
123123
FORWARD_EXTENSION_METHODS_NOT_ALLOWED=forward attribute can not be applied to extension methods
124+
WHERE_SECTION_NOT_ALLOWED=Can not apply 'where' to predefined class
125+
GENERIC_PARAMETERS_MISMATCH=Generic-parameters mismatch
124126
%PREFIX%=COMPILATIONERROR_
125127
UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Unit expected, library found
126128
ASSEMBLY_{0}_READING_ERROR=Error by reading assembly '{0}'

bin/Lng/Rus/SemanticErrors_ib.dat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ IMPLICIT_EXPLICIT_OPERATOR_EXTENSION_ONLY_FOR_COMPILED_CLASSES_ALLOWED=extension
116116
EXTENSIONMETHOD_KEYWORD_NOT_ALLOWED=Атрибут extensionmethod недопустим в данном контексте
117117
CANNOT_EXTEND_STANDARD_OPERATORS_FOR_DELEGATE=Нельзя раширять операции +,+=,-,-= для делегатов
118118
FORWARD_EXTENSION_METHODS_NOT_ALLOWED=Атрибут forward недопустим для методов расширения
119+
WHERE_SECTION_NOT_ALLOWED=Секция where недопустима в данном контексте
120+
GENERIC_PARAMETERS_MISMATCH=Generic-параметры не совпадают с generic-параметрами в предописании типа
119121
%PREFIX%=COMPILATIONERROR_
120122
UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Ожидался модуль, а встречена библиотека
121123
ASSEMBLY_{0}_READING_ERROR=Ошибка при чтении сборки '{0}'

0 commit comments

Comments
 (0)