Browse Source

Fix bug in output type inference for explicitly typed lambdas.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
79b8b00d29
  1. 2
      ICSharpCode.NRefactory.CSharp/Resolver/TypeInference.cs
  2. 19
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/LambdaTests.cs

2
ICSharpCode.NRefactory.CSharp/Resolver/TypeInference.cs

@ -372,7 +372,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -372,7 +372,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
{
// C# 4.0 spec: §7.5.2.4 Output types
LambdaResolveResult lrr = e as LambdaResolveResult;
if (lrr != null && lrr.IsImplicitlyTyped || e is MethodGroupResolveResult) {
if (lrr != null || e is MethodGroupResolveResult) {
IMethod m = GetDelegateOrExpressionTreeSignature(t);
if (m != null) {
return new[] { m.ReturnType };

19
ICSharpCode.NRefactory.Tests/CSharp/Resolver/LambdaTests.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using NUnit.Framework;
@ -420,6 +421,24 @@ class TestClass { @@ -420,6 +421,24 @@ class TestClass {
Assert.IsTrue(c.IsValid);
}
[Test]
public void RaisePropertyChanged_WithExpressionLambda()
{
string program = @"using System;
using System.Linq.Expressions;
class Test {
void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression) {}
void RaisePropertyChanged(string propertyName) {}
string MyProperty { get {} }
void Test() {
$RaisePropertyChanged(() => MyProperty)$;
}
}";
var rr = Resolve<CSharpInvocationResolveResult>(program);
Assert.IsFalse(rr.IsError);
Assert.AreEqual("propertyExpression", rr.Member.Parameters.Single().Name);
}
/* TODO write test for this
class A
{

Loading…
Cancel
Save