disabled declarations of extension methods in interface part of unit

This commit is contained in:
Бондарев Иван 2015-12-03 19:59:37 +01:00
parent 553efb3e86
commit cf8282b3cc
3 changed files with 12 additions and 1 deletions

View file

@ -562,6 +562,7 @@ namespace PascalABCCompiler.TreeConverter
set_intls.Clear();
NetHelper.NetHelper.reset();
from_pabc_dll = false;
in_interface_part = false;
compiled_type_node[] ctns = new compiled_type_node[compiled_type_node.compiled_types.Values.Count];
compiled_type_node.compiled_types.Values.CopyTo(ctns, 0);
null_type_node.reset();
@ -3030,6 +3031,8 @@ namespace PascalABCCompiler.TreeConverter
weak_node_test_and_visit(_implementation_node.implementation_definitions);
}
bool in_interface_part = false;
public override void visit(SyntaxTree.interface_node _interface_node)
{
if (_interface_node.interface_definitions != null && _interface_node.interface_definitions.defs != null)
@ -9429,8 +9432,12 @@ namespace PascalABCCompiler.TreeConverter
//cnsn.scope=_compiled_unit.scope;
reset_for_interface();
in_interface_part = false;
if (_unit_module.implementation_part != null)
in_interface_part = true;
hard_node_test_and_visit(_unit_module.interface_part);
if (_unit_module.implementation_part != null)
in_interface_part = false;
//compiled_program=new program_node();
//compiled_program.units.Add(compiled_main_unit);
@ -11809,6 +11816,8 @@ namespace PascalABCCompiler.TreeConverter
}
case proc_attribute.attr_extension:
{
if (in_interface_part)
AddError(get_location(_procedure_attributes_list), "EXTENSION_METHODS_IN_INTERFACE_PART_NOT_ALLOWED");
if (!(context.top_function is common_namespace_function_node))
AddError(get_location(_procedure_attributes_list), "EXTENSION_ATTRIBUTE_ONLY_FOR_NAMESPACE_FUNCTIONS_ALLOWED");
if (context.top_function.parameters.Count == 0)

View file

@ -99,6 +99,7 @@ EXTENSION_METHODS_MUST_HAVE_LEAST_ONE_PARAMETER=Parameter with name 'self' expec
FIRST_PARAMETER_SHOULDBE_ONLY_VALUE_PARAMETER=var and const are not allowed for first parameter of extension method
FIRST_PARAMETER_MUST_HAVE_NAME_SELF=Parameter with 'name' self expected
EXTENSION_METHODS_FOR_CONSTRUCTED_TYPES_NOT_ALLOWED=Cannot extend this type
EXTENSION_METHODS_IN_INTERFACE_PART_NOT_ALLOWED=Cannot declare extension methods in interface part of unit
%PREFIX%=COMPILATIONERROR_
UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Unit expected, library found
ASSEMBLY_{0}_READING_ERROR=Error by reading assembly '{0}'

View file

@ -101,6 +101,7 @@ EXTENSION_METHODS_MUST_HAVE_LEAST_ONE_PARAMETER=Ожидался парамет
FIRST_PARAMETER_SHOULDBE_ONLY_VALUE_PARAMETER=Недопустимо использование var или const в первом параметре extension-метода
FIRST_PARAMETER_MUST_HAVE_NAME_SELF=Первый параметр должен иметь имя self
EXTENSION_METHODS_FOR_CONSTRUCTED_TYPES_NOT_ALLOWED=Нельзя расширять этот тип
EXTENSION_METHODS_IN_INTERFACE_PART_NOT_ALLOWED=Объявление extension-методов в интерфейсной части модуля недопустимо
%PREFIX%=COMPILATIONERROR_
UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Ожидался модуль, а встречена библиотека
ASSEMBLY_{0}_READING_ERROR=Ошибка при чтении сборки '{0}'