bug fix: case sensitive self parameter in new extension methods syntax

bug fix:
procedure Add(self: List<integer>; x,y: integer); extensionmethod;
...
lst.Add(1,2);
lst.Add(1);
This commit is contained in:
Бондарев Иван 2015-10-13 22:00:29 +02:00
parent 56a8a1d15d
commit 248da671c3
5 changed files with 36 additions and 5 deletions

View file

@ -27,6 +27,14 @@ begin
sb.Append(c);
Result := sb.ToString();
end;
procedure MyAdd<T>(self: List<T>; params arr: array of T); extensionmethod;
begin
self.AddRange(arr);
end;
procedure Add(self: List<integer>; params arr: array of integer); extensionmethod;
begin
self.AddRange(arr);
end;
begin
var arr := Arr(1,2,3);
assert(arr.myfirst=1);
@ -41,4 +49,10 @@ begin
var j:= 2;
j.myproc;
assert(PABCSystem.Arr('a','b','c').glue='abc');
var lst3 := new List<integer>;
lst3.MyAdd(2,3,4,5);
assert(lst3[3]=5);
var lst4 := new List<integer>;
lst4.Add(2,3,4,5);
assert(lst4[3]=5);
end.

View file

@ -3278,7 +3278,7 @@ _cmn.types.AddElement(tctn);*/
throw new CompilerInternalError("Undefined block type");
}
}
while (siint.sym_info != fn)
while (siint.sym_info != fn && siint.Next != null)
{
siint = siint.Next;
}

View file

@ -38,6 +38,12 @@ namespace PascalABCCompiler.TreeConverter
syntax_tree_visitor.AddError(err);
}
private T AddError<T>(Errors.Error err)
{
syntax_tree_visitor.AddError(err);
return default(T);
}
private void AddError(location loc, string ErrString, params string[] values)
{
syntax_tree_visitor.AddError(loc, ErrString, values);
@ -1675,7 +1681,7 @@ namespace PascalABCCompiler.TreeConverter
{
if (functions==null)
{
AddError(new NoFunctionWithThisName(loc));
return AddError<function_node>(new NoFunctionWithThisName(loc));
}
function_node_list set_of_possible_functions = new function_node_list();

View file

@ -5042,11 +5042,11 @@ namespace PascalABCCompiler.TreeConverter
si = si.Next;
}
}
if (has_obj_methods)
/*if (has_obj_methods)
{
exprs.remove_at(0);
skip_first_parameter = false;
}
}*/
si = new_si;
}
if (_method_call.parameters != null)
@ -11754,7 +11754,7 @@ namespace PascalABCCompiler.TreeConverter
AddError(context.top_function.loc, "EXTENSION_METHODS_MUST_HAVE_LEAST_ONE_PARAMETER");
if (context.top_function.parameters[0].parameter_type != SemanticTree.parameter_type.value)
AddError(context.top_function.loc, "FIRST_PARAMETER_SHOULDBE_ONLY_VALUE_PARAMETER");
if (context.top_function.parameters[0].name != compiler_string_consts.self_word)
if (context.top_function.parameters[0].name.ToLower() != compiler_string_consts.self_word)
AddError(context.top_function.loc,"FIRST_PARAMETER_MUST_HAVE_NAME_SELF");
common_namespace_function_node top_function = context.top_function as common_namespace_function_node;
top_function.ConnectedToType = context.top_function.parameters[0].type;

View file

@ -2947,6 +2947,7 @@ namespace PascalABCCompiler.TreeRealization
SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.sm_name, ctn, SemanticTree.basic_function_type.enumsm, SystemLibrary.SystemLibrary.bool_type);
SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.smeq_name, ctn, SemanticTree.basic_function_type.enumsmeq, SystemLibrary.SystemLibrary.bool_type);
}
//ctn.init_scope();
//TODO: Тут надо подумать. Может как-то сделать по другому?
if (!NetHelper.NetHelper.IsStandType(st))
{
@ -3137,6 +3138,16 @@ namespace PascalABCCompiler.TreeRealization
{
SymbolInfo si = scope.SymbolTable.Find(scope, name);
SymbolInfo si2 = find_in_additional_names(name);
SymbolInfo si3 = compiled_find(name);
if (si != null)
{
SymbolInfo tmp_si = si;
while (tmp_si.Next != null)
tmp_si = tmp_si.Next;
tmp_si.Next = si3;
}
else if (si3 != null)
si = si3;
if (si == null && si2 == null && string.Compare(name, "Create", true) != 0)
{
compiled_type_node bas_type = base_type as compiled_type_node;