提交 b6ed1896 编写于 作者: J Jonathon Marolf 提交者: GitHub

Merge pull request #12489 from vslsnap/merge-microupdate-into-dev15-preview-420160713-175309

Merge microupdate into dev15-preview-4
......@@ -305,11 +305,11 @@ public class C
Assert.True(symbols.Count > 0);
TestRoundTrip(symbols, compilation);
}
[Fact]
public void TestExtensionMethodReferences()
{
var source = @"
using System;
using System.Collections.Generic;
public static class E
......@@ -319,6 +319,7 @@ public static class E
public static void Z<T>(this T t, string y) { }
public static void Z<T>(this T t, T t2) { }
public static void Y<T, S>(this T t, S other) { }
public static TResult Select<TSource, TResult>(this IEnumerable<TSource> collection, Func<TSource, TResult> selector) { return null;}
}
public class C
......@@ -329,13 +330,14 @@ public class C
this.Z(""test"");
this.Z(this);
this.Y(1.0);
new[] { 1, 2, 3 }.Select(
}
}
";
var compilation = GetCompilation(source);
var tree = compilation.SyntaxTrees.First();
var model = compilation.GetSemanticModel(tree);
var symbols = tree.GetRoot().DescendantNodes().OfType<InvocationExpressionSyntax>().Select(s => model.GetSymbolInfo(s).Symbol).ToList();
var symbols = tree.GetRoot().DescendantNodes().OfType<InvocationExpressionSyntax>().Select(s => model.GetSymbolInfo(s).GetAnySymbol()).ToList();
Assert.True(symbols.Count > 0);
Assert.True(symbols.All(s => s.IsReducedExtension()));
TestRoundTrip(symbols, compilation);
......@@ -425,6 +427,104 @@ public class C<S, T>
TestRoundTrip(constructed, compilation);
}
[Fact, WorkItem(235912, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=235912&_a=edit")]
public void TestNestedGenericType()
{
var source = @"
public class A<TOuter>
{
public class B<TInner>
{
}
}";
var compilation = GetCompilation(source);
var tree = compilation.SyntaxTrees.First();
var model = compilation.GetSemanticModel(tree);
var outer = GetDeclaredSymbols(compilation).OfType<INamedTypeSymbol>().First(s => s.Name == "A");
var constructed = outer.Construct(compilation.GetSpecialType(SpecialType.System_String));
var inner = constructed.GetTypeMembers().Single();
TestRoundTrip(inner, compilation);
}
[Fact, WorkItem(235912, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=235912&_a=edit")]
public void TestNestedGenericType1()
{
var source = @"
using System.Collections.Generic;
public class A<T1>
{
public class B<T2>
{
void M<T3>(T1 t1, T2, T3 t3, List<int> l1, List<T3> l2) { }
}
}";
var compilation = GetCompilation(source);
var tree = compilation.SyntaxTrees.First();
var model = compilation.GetSemanticModel(tree);
var a = GetDeclaredSymbols(compilation).OfType<INamedTypeSymbol>().Single(s => s.Name == "A");
var a_b = a.GetTypeMembers().Single();
var a_b_m = a_b.GetMembers().Single(s => s.Name == "M");
TestRoundTrip(a, compilation);
TestRoundTrip(a_b, compilation);
TestRoundTrip(a_b_m, compilation);
var a_string = a.Construct(compilation.GetSpecialType(SpecialType.System_String));
var a_string_b = a_string.GetTypeMembers().Single();
var a_string_b_m = a_string_b.GetMembers().Single(s => s.Name == "M");
TestRoundTrip(a_string, compilation);
TestRoundTrip(a_string_b, compilation);
TestRoundTrip(a_string_b_m, compilation);
var a_string_b_int = a_string_b.Construct(compilation.GetSpecialType(SpecialType.System_Int32));
var a_string_b_int_m = a_string_b_int.GetMembers().Single(s => s.Name == "M");
TestRoundTrip(a_string_b_int, compilation);
TestRoundTrip(a_string_b_int_m, compilation);
var a_string_b_int_m_datetime = ((IMethodSymbol)a_string_b_int_m).Construct(compilation.GetSpecialType(SpecialType.System_DateTime));
TestRoundTrip(a_string_b_int_m_datetime, compilation);
var a_b_int = a_b.Construct(compilation.GetSpecialType(SpecialType.System_Int32));
var a_b_int_m = a_b_int.GetMembers().Single(s => s.Name == "M");
var a_b_int_m_datetime = ((IMethodSymbol)a_b_int_m).Construct(compilation.GetSpecialType(SpecialType.System_DateTime));
TestRoundTrip(a_b_int, compilation);
TestRoundTrip(a_b_int_m, compilation);
TestRoundTrip(a_b_int_m_datetime, compilation);
var a_b_m_datetime = ((IMethodSymbol)a_b_m).Construct(compilation.GetSpecialType(SpecialType.System_DateTime));
TestRoundTrip(a_b_m_datetime, compilation);
}
[Fact, WorkItem(235912, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=235912&_a=edit")]
public void TestGenericTypeTypeParameter()
{
var source = @"class C<T> { }";
var compilation = GetCompilation(source);
var tree = compilation.SyntaxTrees.First();
var model = compilation.GetSemanticModel(tree);
var typeParameter = GetDeclaredSymbols(compilation).OfType<INamedTypeSymbol>().Single().TypeParameters.Single();
TestRoundTrip(typeParameter, compilation);
}
[Fact, WorkItem(235912, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=235912&_a=edit")]
public void TestGenericMethodTypeParameter()
{
var source = @"class C { void M<T>() { } }";
var compilation = GetCompilation(source);
var tree = compilation.SyntaxTrees.First();
var model = compilation.GetSemanticModel(tree);
var typeParameter = GetDeclaredSymbols(compilation).OfType<INamedTypeSymbol>().Single().GetMembers("M").OfType<IMethodSymbol>().Single().TypeParameters.Single();
TestRoundTrip(typeParameter, compilation);
}
[Fact, WorkItem(11193, "https://github.com/dotnet/roslyn/issues/11193")]
public async Task TestGetInteriorSymbolsDoesNotCrashOnSpeculativeSemanticModel()
{
......@@ -475,7 +575,7 @@ private void TestRoundTrip(IEnumerable<ISymbol> symbols, Compilation compilation
{
foreach (var symbol in symbols)
{
TestRoundTrip(symbol, compilation, fnId);
TestRoundTrip(symbol, compilation, fnId: fnId);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册