diff --git a/CodeCompletion/DomSyntaxTreeVisitor.cs b/CodeCompletion/DomSyntaxTreeVisitor.cs index cb943d479..89b3df99d 100644 --- a/CodeCompletion/DomSyntaxTreeVisitor.cs +++ b/CodeCompletion/DomSyntaxTreeVisitor.cs @@ -3699,16 +3699,20 @@ namespace CodeCompletion ss.loc = get_location(_class_definition); cur_scope = ss; - if (_class_definition.template_args != null) + if (!parse_only_method_bodies) { - foreach (ident id in _class_definition.template_args.idents) - ss.AddGenericParameter(id.name); - } - else if (template_args != null) - { - foreach (ident id in template_args.idents) - ss.AddGenericParameter(id.name); + if (_class_definition.template_args != null) + { + foreach (ident id in _class_definition.template_args.idents) + ss.AddGenericParameter(id.name); + } + else if (template_args != null) + { + foreach (ident id in template_args.idents) + ss.AddGenericParameter(id.name); + } } + string tmp_name = cur_type_name; cur_type_name = null; if (_class_definition.body != null) @@ -5297,9 +5301,9 @@ namespace CodeCompletion if ((awaitedProcType as ProcType).target.parameters.Count > 0) param_type = (awaitedProcType as ProcType).target.parameters[i].sc as TypeScope; } - else if (awaitedProcType.IsDelegate && awaitedProcType.instances != null && awaitedProcType.instances.Count > i) + else if (awaitedProcType.IsDelegate && awaitedProcType.instances != null && awaitedProcType.instances.Count > 0) { - param_type = awaitedProcType.instances[i]; + param_type = awaitedProcType.instances[Math.Min(i, awaitedProcType.instances.Count - 1)]; } else if (awaitedProcType.IsDelegate) { diff --git a/CodeCompletion/SymTable.cs b/CodeCompletion/SymTable.cs index cb5d73d55..9397a266d 100644 --- a/CodeCompletion/SymTable.cs +++ b/CodeCompletion/SymTable.cs @@ -2227,8 +2227,25 @@ namespace CodeCompletion public ProcScope GetInstance(List gen_args) { - if (this.template_parameters == null || this.template_parameters.Count == 0) - return this; + List template_parameters = this.template_parameters; + if ((this.template_parameters == null || this.template_parameters.Count == 0)) + { + bool has_instance = false; + if (this.topScope is TypeScope) + { + TypeScope ts = this.topScope as TypeScope; + if (ts.instances != null && ts.instances.Count > 0 && gen_args.Count > 0) + { + has_instance = true; + gen_args = ts.instances; + template_parameters = new List(ts.TemplateArguments); + } + + } + if (!has_instance) + return this; + } + ProcScope instance = new ProcScope(this.name, this.topScope, this.is_constructor); instance.is_extension = this.is_extension; instance.original_function = this; @@ -2241,7 +2258,7 @@ namespace CodeCompletion i++; if (parameter.sc is UnknownScope || (parameter.sc is TypeScope) && (parameter.sc as TypeScope).IsGenericParameter) { - int ind = this.template_parameters.IndexOf((parameter.sc as TypeScope).Name); + int ind = template_parameters.IndexOf((parameter.sc as TypeScope).Name); ElementScope inst_param = null; if (gen_args.Count > ind && ind != -1) inst_param = new ElementScope(new SymInfo(parameter.si.name, parameter.si.kind, parameter.si.description), gen_args[ind], parameter.topScope); @@ -2267,7 +2284,7 @@ namespace CodeCompletion if (this.return_type != null) { bool exact = true; - if (this.template_parameters != null && this.template_parameters.Count > 0) + if (template_parameters != null && template_parameters.Count > 0) { foreach (ElementScope parameter in this.parameters) { @@ -3956,6 +3973,13 @@ namespace CodeCompletion } } + public override void Clear() + { + base.Clear(); + if (generic_params != null) + generic_params.Clear(); + } + public virtual List GetInstances() { return this.instances; diff --git a/TestSuite/intellisense_tests/generics10.pas b/TestSuite/intellisense_tests/generics10.pas index 31a46be52..34d1346df 100644 --- a/TestSuite/intellisense_tests/generics10.pas +++ b/TestSuite/intellisense_tests/generics10.pas @@ -14,4 +14,5 @@ begin a1.c{@var t1<>.c: byte;@} := 3; var a2 := t1&.Create; a2.b{@var t1<>.b: byte;@} := 4; + end. \ No newline at end of file diff --git a/TestSuite/intellisense_tests/lambdas8.pas b/TestSuite/intellisense_tests/lambdas8.pas new file mode 100644 index 000000000..2a820f09c --- /dev/null +++ b/TestSuite/intellisense_tests/lambdas8.pas @@ -0,0 +1,8 @@ +begin + System.Collections.Generic.Comparer&.Create( + (b1{@parameter b1: byte;@},b2)-> + begin + Result := b2{@parameter b2: byte;@}-b1; + end + ) +end. \ No newline at end of file