PageRenderTime 91ms CodeModel.GetById 19ms app.highlight 44ms RepoModel.GetById 1ms app.codeStats 3ms

/Src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetSemanticInfoTests.cs

https://github.com/EkardNT/Roslyn
C# | 14316 lines | 12454 code | 1797 blank | 65 comment | 2 complexity | b50c7b40e0c17e90b05a8fb0ebd9f65c MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1// Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
   2
   3using System;
   4using System.Collections.Immutable;
   5using System.Linq;
   6using Microsoft.CodeAnalysis.CSharp.Symbols;
   7using Microsoft.CodeAnalysis.CSharp.Syntax;
   8using Microsoft.CodeAnalysis.Text;
   9using Roslyn.Test.Utilities;
  10using Xunit;
  11
  12// Note: the easiest way to create new unit tests that use GetSemanticInfo
  13// is to use the SemanticInfo unit test generate in Editor Test App. 
  14
  15namespace Microsoft.CodeAnalysis.CSharp.UnitTests
  16{
  17    using Utils = CompilationUtils;
  18    using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
  19
  20    public class GetExtendedSemanticInfoTests : SemanticModelTestBase
  21    {
  22        [Fact]
  23        public void FailedOverloadResolution()
  24        {
  25            string sourceCode = @"
  26class Program
  27{
  28    static void Main(string[] args)
  29    {
  30        int i = 8;
  31        int j = i + q;
  32        /*<bind>*/X.f/*</bind>*/(""hello"");
  33    }
  34}
  35
  36class X
  37{
  38    public static void f() { }
  39    public static void f(int i) { }
  40}
  41";
  42            var semanticInfo = GetSemanticInfoForTest(sourceCode);
  43
  44            Assert.Null(semanticInfo.Type);
  45            Assert.Null(semanticInfo.ConvertedType);
  46            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
  47
  48            Assert.Null(semanticInfo.Symbol);
  49            Assert.Equal(CandidateReason.OverloadResolutionFailure, semanticInfo.CandidateReason);
  50            Assert.Equal(2, semanticInfo.CandidateSymbols.Length);
  51            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
  52            Assert.Equal("void X.f()", sortedCandidates[0].ToTestDisplayString());
  53            Assert.Equal(SymbolKind.Method, sortedCandidates[0].Kind);
  54            Assert.Equal("void X.f(System.Int32 i)", sortedCandidates[1].ToTestDisplayString());
  55            Assert.Equal(SymbolKind.Method, sortedCandidates[1].Kind);
  56
  57            Assert.Equal(2, semanticInfo.MethodGroup.Length);
  58            var sortedMethodGroup = semanticInfo.MethodGroup.OrderBy(s => s.ToTestDisplayString()).ToArray();
  59            Assert.Equal("void X.f()", sortedMethodGroup[0].ToTestDisplayString());
  60            Assert.Equal("void X.f(System.Int32 i)", sortedMethodGroup[1].ToTestDisplayString());
  61
  62            Assert.False(semanticInfo.IsCompileTimeConstant);
  63        }
  64
  65        [Fact]
  66        public void SimpleGenericType()
  67        {
  68            string sourceCode = @"
  69using System;
  70
  71class Program
  72{
  73    /*<bind>*/K<int>/*</bind>*/ f;
  74}
  75
  76class K<T>
  77{ }
  78";
  79            var semanticInfo = GetSemanticInfoForTest(sourceCode);
  80
  81            Assert.Equal("K<System.Int32>", semanticInfo.Type.ToTestDisplayString());
  82            Assert.Equal(TypeKind.Class, semanticInfo.Type.TypeKind);
  83            Assert.Equal("K<System.Int32>", semanticInfo.ConvertedType.ToTestDisplayString());
  84            Assert.Equal(TypeKind.Class, semanticInfo.ConvertedType.TypeKind);
  85            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
  86
  87            Assert.Equal("K<System.Int32>", semanticInfo.Symbol.ToTestDisplayString());
  88            Assert.Equal(SymbolKind.NamedType, semanticInfo.Symbol.Kind);
  89            Assert.Equal(0, semanticInfo.CandidateSymbols.Length);
  90
  91            Assert.Equal(0, semanticInfo.MethodGroup.Length);
  92
  93            Assert.False(semanticInfo.IsCompileTimeConstant);
  94        }
  95
  96        [Fact]
  97        public void WrongArity1()
  98        {
  99            string sourceCode = @"
 100using System;
 101
 102class Program
 103{
 104    /*<bind>*/K<int, string>/*</bind>*/ f;
 105}
 106
 107class K<T>
 108{ }
 109";
 110            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 111
 112            Assert.Equal("K<T>", semanticInfo.Type.ToTestDisplayString());
 113            Assert.Equal(TypeKind.Class, semanticInfo.Type.TypeKind);
 114            Assert.Equal("K<T>", semanticInfo.ConvertedType.ToTestDisplayString());
 115            Assert.Equal(TypeKind.Class, semanticInfo.ConvertedType.TypeKind);
 116            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 117
 118            Assert.Null(semanticInfo.Symbol);
 119            Assert.Equal(CandidateReason.WrongArity, semanticInfo.CandidateReason);
 120            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 121            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 122            Assert.Equal("K<T>", sortedCandidates[0].ToTestDisplayString());
 123            Assert.Equal(SymbolKind.NamedType, sortedCandidates[0].Kind);
 124
 125            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 126
 127            Assert.False(semanticInfo.IsCompileTimeConstant);
 128        }
 129
 130        [Fact]
 131        public void WrongArity2()
 132        {
 133            string sourceCode = @"
 134using System;
 135
 136class Program
 137{
 138    /*<bind>*/K/*</bind>*/ f;
 139}
 140
 141class K<T>
 142{ }
 143";
 144            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 145
 146            Assert.Equal("K<T>", semanticInfo.Type.ToTestDisplayString());
 147            Assert.Equal(TypeKind.Class, semanticInfo.Type.TypeKind);
 148            Assert.Equal("K<T>", semanticInfo.ConvertedType.ToTestDisplayString());
 149            Assert.Equal(TypeKind.Class, semanticInfo.ConvertedType.TypeKind);
 150            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 151
 152            Assert.Null(semanticInfo.Symbol);
 153            Assert.Equal(CandidateReason.WrongArity, semanticInfo.CandidateReason);
 154            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 155            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 156            Assert.Equal("K<T>", sortedCandidates[0].ToTestDisplayString());
 157            Assert.Equal(SymbolKind.NamedType, sortedCandidates[0].Kind);
 158
 159            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 160
 161            Assert.False(semanticInfo.IsCompileTimeConstant);
 162        }
 163
 164        [Fact]
 165        public void WrongArity3()
 166        {
 167            string sourceCode = @"
 168using System;
 169
 170class Program
 171{
 172    static void Main()
 173    {
 174        /*<bind>*/K<int, int>/*</bind>*/.f();
 175    }
 176
 177}
 178
 179class K<T>
 180{
 181    void f() { }
 182}
 183
 184";
 185            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 186
 187            Assert.Equal("K<T>", semanticInfo.Type.ToTestDisplayString());
 188            Assert.Equal(TypeKind.Class, semanticInfo.Type.TypeKind);
 189            Assert.Equal("K<T>", semanticInfo.ConvertedType.ToTestDisplayString());
 190            Assert.Equal(TypeKind.Class, semanticInfo.ConvertedType.TypeKind);
 191            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 192
 193            Assert.Null(semanticInfo.Symbol);
 194            Assert.Equal(CandidateReason.WrongArity, semanticInfo.CandidateReason);
 195            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 196            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 197            Assert.Equal("K<T>", sortedCandidates[0].ToTestDisplayString());
 198            Assert.Equal(SymbolKind.NamedType, sortedCandidates[0].Kind);
 199
 200            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 201
 202            Assert.False(semanticInfo.IsCompileTimeConstant);
 203        }
 204
 205        [Fact]
 206        public void WrongArity4()
 207        {
 208            string sourceCode = @"
 209
 210using System;
 211
 212class Program
 213{
 214    static K Main()
 215    {
 216        /*<bind>*/K/*</bind>*/.f();
 217    }
 218
 219}
 220
 221class K<T>
 222{
 223    void f() { }
 224}
 225";
 226            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 227
 228            Assert.Equal("K<T>", semanticInfo.Type.ToTestDisplayString());
 229            Assert.Equal(TypeKind.Class, semanticInfo.Type.TypeKind);
 230            Assert.Equal("K<T>", semanticInfo.ConvertedType.ToTestDisplayString());
 231            Assert.Equal(TypeKind.Class, semanticInfo.ConvertedType.TypeKind);
 232            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 233
 234            Assert.Null(semanticInfo.Symbol);
 235            Assert.Equal(CandidateReason.WrongArity, semanticInfo.CandidateReason);
 236            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 237            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 238            Assert.Equal("K<T>", sortedCandidates[0].ToTestDisplayString());
 239            Assert.Equal(SymbolKind.NamedType, sortedCandidates[0].Kind);
 240
 241            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 242
 243            Assert.False(semanticInfo.IsCompileTimeConstant);
 244        }
 245
 246        [Fact]
 247        public void NotInvocable()
 248        {
 249            string sourceCode = @"
 250using System;
 251
 252class Program
 253{
 254    static void Main()
 255    {
 256        K./*<bind>*/f/*</bind>*/();
 257    }
 258
 259}
 260
 261class K
 262{
 263    public int f;
 264}
 265";
 266            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 267
 268            Assert.Equal("System.Int32", semanticInfo.Type.ToTestDisplayString());
 269            Assert.Equal(TypeKind.Struct, semanticInfo.Type.TypeKind);
 270            Assert.Equal("System.Int32", semanticInfo.ConvertedType.ToTestDisplayString());
 271            Assert.Equal(TypeKind.Struct, semanticInfo.ConvertedType.TypeKind);
 272            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 273
 274            Assert.Null(semanticInfo.Symbol);
 275            Assert.Equal(CandidateReason.NotInvocable, semanticInfo.CandidateReason);
 276            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 277            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 278            Assert.Equal("System.Int32 K.f", sortedCandidates[0].ToTestDisplayString());
 279            Assert.Equal(SymbolKind.Field, sortedCandidates[0].Kind);
 280
 281            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 282
 283            Assert.False(semanticInfo.IsCompileTimeConstant);
 284        }
 285
 286        [Fact]
 287        public void InaccessibleField()
 288        {
 289            string sourceCode = @"
 290class Program
 291{
 292    static void Main()
 293    {
 294        K./*<bind>*/f/*</bind>*/ = 3;
 295    }
 296}
 297
 298class K
 299{
 300    private int f;
 301}
 302";
 303            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 304
 305            Assert.Equal("System.Int32", semanticInfo.Type.ToTestDisplayString());
 306            Assert.Equal(TypeKind.Struct, semanticInfo.Type.TypeKind);
 307            Assert.Equal("System.Int32", semanticInfo.ConvertedType.ToTestDisplayString());
 308            Assert.Equal(TypeKind.Struct, semanticInfo.ConvertedType.TypeKind);
 309            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 310
 311            Assert.Null(semanticInfo.Symbol);
 312            Assert.Equal(CandidateReason.Inaccessible, semanticInfo.CandidateReason);
 313            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 314            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 315            Assert.Equal("System.Int32 K.f", sortedCandidates[0].ToTestDisplayString());
 316            Assert.Equal(SymbolKind.Field, sortedCandidates[0].Kind);
 317
 318            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 319
 320            Assert.False(semanticInfo.IsCompileTimeConstant);
 321        }
 322
 323        [Fact]
 324        public void InaccessibleFieldAssignment()
 325        {
 326            string sourceCode =
 327@"class A
 328{
 329    string F;
 330}
 331class B
 332{
 333    static void M(A a)
 334    {
 335        /*<bind>*/a.F/*</bind>*/ = string.Empty;
 336    }
 337}";
 338            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 339            Assert.Equal(SpecialType.System_String, semanticInfo.Type.SpecialType);
 340            var symbol = semanticInfo.Symbol;
 341            Assert.Null(symbol);
 342            Assert.Equal(CandidateReason.Inaccessible, semanticInfo.CandidateReason);
 343            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 344            symbol = semanticInfo.CandidateSymbols[0];
 345            Assert.Equal("System.String A.F", symbol.ToTestDisplayString());
 346            Assert.Equal(SymbolKind.Field, symbol.Kind);
 347        }
 348
 349        [WorkItem(542481, "DevDiv")]
 350        [Fact]
 351        public void InaccessibleBaseClassConstructor01()
 352        {
 353            string sourceCode = @"
 354namespace Test
 355{
 356    public class Base
 357    {
 358        protected Base() { }
 359    }
 360
 361    public class Derived : Base
 362    {
 363        void M()
 364        {
 365            Base b = /*<bind>*/new Base()/*</bind>*/;
 366        }
 367    }
 368}";
 369            var semanticInfo = GetSemanticInfoForTest<ObjectCreationExpressionSyntax>(sourceCode);
 370
 371            Assert.Null(semanticInfo.Symbol);
 372            Assert.Equal(CandidateReason.Inaccessible, semanticInfo.CandidateReason);
 373            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 374            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 375            Assert.Equal("Test.Base..ctor()", sortedCandidates[0].ToTestDisplayString());
 376            Assert.Equal(SymbolKind.Method, sortedCandidates[0].Kind);
 377        }
 378
 379        [WorkItem(542481, "DevDiv")]
 380        [Fact]
 381        public void InaccessibleBaseClassConstructor02()
 382        {
 383            string sourceCode = @"
 384namespace Test
 385{
 386    public class Base
 387    {
 388        protected Base() { }
 389    }
 390
 391    public class Derived : Base
 392    {
 393        void M()
 394        {
 395            Base b = new /*<bind>*/Base/*</bind>*/();
 396        }
 397    }
 398}";
 399            var semanticInfo = GetSemanticInfoForTest<NameSyntax>(sourceCode);
 400
 401            Assert.Null(semanticInfo.Type);
 402            Assert.Null(semanticInfo.ConvertedType);
 403
 404            Assert.Equal("Test.Base", semanticInfo.Symbol.ToTestDisplayString());
 405            Assert.Equal(CandidateReason.None, semanticInfo.CandidateReason);
 406            Assert.Equal(0, semanticInfo.CandidateSymbols.Length);
 407            Assert.Equal(0, semanticInfo.MemberGroup.Length);
 408        }
 409
 410        [Fact]
 411        public void InaccessibleFieldMethodArg()
 412        {
 413            string sourceCode =
 414@"class A
 415{
 416    string F;
 417}
 418class B
 419{
 420    static void M(A a)
 421    {
 422        M(/*<bind>*/a.F/*</bind>*/);
 423    }
 424    static void M(string s) { }
 425}";
 426            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 427            Assert.Equal(SpecialType.System_String, semanticInfo.Type.SpecialType);
 428            var symbol = semanticInfo.Symbol;
 429            Assert.Null(symbol);
 430            Assert.Equal(CandidateReason.Inaccessible, semanticInfo.CandidateReason);
 431            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 432            symbol = semanticInfo.CandidateSymbols[0];
 433            Assert.Equal("System.String A.F", symbol.ToTestDisplayString());
 434            Assert.Equal(SymbolKind.Field, symbol.Kind);
 435        }
 436
 437        [Fact]
 438        public void TypeNotAVariable()
 439        {
 440            string sourceCode = @"
 441using System;
 442
 443class Program
 444{
 445    static void Main()
 446    {
 447        /*<bind>*/K/*</bind>*/ = 12;
 448    }
 449
 450}
 451
 452class K
 453{
 454}
 455";
 456            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 457
 458            Assert.Equal("K", semanticInfo.Type.ToTestDisplayString());
 459            Assert.Equal(TypeKind.Class, semanticInfo.Type.TypeKind);
 460            Assert.Equal("K", semanticInfo.ConvertedType.ToTestDisplayString());
 461            Assert.Equal(TypeKind.Class, semanticInfo.ConvertedType.TypeKind);
 462            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 463
 464            Assert.Null(semanticInfo.Symbol);
 465            Assert.Equal(CandidateReason.NotAVariable, semanticInfo.CandidateReason);
 466            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 467            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 468            Assert.Equal("K", sortedCandidates[0].ToTestDisplayString());
 469            Assert.Equal(SymbolKind.NamedType, sortedCandidates[0].Kind);
 470
 471            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 472
 473            Assert.False(semanticInfo.IsCompileTimeConstant);
 474        }
 475
 476        [Fact]
 477        public void InaccessibleType1()
 478        {
 479            string sourceCode = @"
 480using System;
 481
 482class Program
 483{
 484    static void Main()
 485    {
 486        /*<bind>*/K.J/*</bind>*/ = v;
 487    }
 488
 489}
 490
 491class K
 492{
 493    protected class J { }
 494}
 495";
 496            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 497
 498            Assert.Equal("?", semanticInfo.Type.ToTestDisplayString());
 499            Assert.Equal(TypeKind.Error, semanticInfo.Type.TypeKind);
 500            Assert.Equal("?", semanticInfo.ConvertedType.ToTestDisplayString());
 501            Assert.Equal(TypeKind.Error, semanticInfo.ConvertedType.TypeKind);
 502            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 503
 504            Assert.Null(semanticInfo.Symbol);
 505            Assert.Equal(CandidateReason.Inaccessible, semanticInfo.CandidateReason);
 506            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 507            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 508            Assert.Equal("K.J", sortedCandidates[0].ToTestDisplayString());
 509            Assert.Equal(SymbolKind.NamedType, sortedCandidates[0].Kind);
 510
 511            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 512
 513            Assert.False(semanticInfo.IsCompileTimeConstant);
 514        }
 515
 516        [Fact]
 517        public void AmbiguousTypesBetweenUsings1()
 518        {
 519            string sourceCode = @"
 520using System;
 521using N1;
 522using N2;
 523
 524class Program
 525{
 526    /*<bind>*/A/*</bind>*/ field;
 527}
 528
 529namespace N1
 530{
 531    class A { }
 532}
 533
 534namespace N2
 535{
 536    class A { }
 537}
 538";
 539            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 540
 541            Assert.Equal("N1.A", semanticInfo.Type.ToTestDisplayString());
 542            Assert.Equal(TypeKind.Error, semanticInfo.Type.TypeKind);
 543            Assert.Equal("N1.A", semanticInfo.ConvertedType.ToTestDisplayString());
 544            Assert.Equal(TypeKind.Error, semanticInfo.ConvertedType.TypeKind);
 545            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 546
 547            Assert.Null(semanticInfo.Symbol);
 548            Assert.Equal(CandidateReason.Ambiguous, semanticInfo.CandidateReason);
 549            Assert.Equal(2, semanticInfo.CandidateSymbols.Length);
 550            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 551            Assert.Equal("N1.A", sortedCandidates[0].ToTestDisplayString());
 552            Assert.Equal(SymbolKind.NamedType, sortedCandidates[0].Kind);
 553            Assert.Equal("N2.A", sortedCandidates[1].ToTestDisplayString());
 554            Assert.Equal(SymbolKind.NamedType, sortedCandidates[1].Kind);
 555
 556            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 557
 558            Assert.False(semanticInfo.IsCompileTimeConstant);
 559        }
 560
 561        [Fact]
 562        public void AmbiguousTypesBetweenUsings2()
 563        {
 564            string sourceCode = @"
 565using System;
 566using N1;
 567using N2;
 568
 569class Program
 570{
 571    void f()
 572    {
 573        /*<bind>*/A/*</bind>*/.g();
 574    }
 575}
 576
 577namespace N1
 578{
 579    class A { }
 580}
 581
 582namespace N2
 583{
 584    class A { }
 585}
 586";
 587            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 588
 589            Assert.Equal("N1.A", semanticInfo.Type.ToTestDisplayString());
 590            Assert.Equal(TypeKind.Error, semanticInfo.Type.TypeKind);
 591            Assert.Equal("N1.A", semanticInfo.ConvertedType.ToTestDisplayString());
 592            Assert.Equal(TypeKind.Error, semanticInfo.ConvertedType.TypeKind);
 593            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 594
 595            Assert.Null(semanticInfo.Symbol);
 596            Assert.Equal(CandidateReason.Ambiguous, semanticInfo.CandidateReason);
 597            Assert.Equal(2, semanticInfo.CandidateSymbols.Length);
 598            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 599            Assert.Equal("N1.A", sortedCandidates[0].ToTestDisplayString());
 600            Assert.Equal(SymbolKind.NamedType, sortedCandidates[0].Kind);
 601            Assert.Equal("N2.A", sortedCandidates[1].ToTestDisplayString());
 602            Assert.Equal(SymbolKind.NamedType, sortedCandidates[1].Kind);
 603
 604            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 605
 606            Assert.False(semanticInfo.IsCompileTimeConstant);
 607        }
 608
 609        [Fact]
 610        public void AmbiguousTypesBetweenUsings3()
 611        {
 612            string sourceCode = @"
 613using System;
 614using N1;
 615using N2;
 616
 617class Program
 618{
 619    void f()
 620    {
 621        /*<bind>*/A<int>/*</bind>*/.g();
 622    }
 623}
 624
 625namespace N1
 626{
 627    class A<T> { }
 628}
 629
 630namespace N2
 631{
 632    class A<U> { }
 633}
 634";
 635            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 636
 637            Assert.Equal("N1.A<System.Int32>", semanticInfo.Type.ToTestDisplayString());
 638            Assert.Equal(TypeKind.Error, semanticInfo.Type.TypeKind);
 639            Assert.Equal("N1.A<System.Int32>", semanticInfo.ConvertedType.ToTestDisplayString());
 640            Assert.Equal(TypeKind.Error, semanticInfo.ConvertedType.TypeKind);
 641            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 642
 643            Assert.Null(semanticInfo.Symbol);
 644            Assert.Equal(CandidateReason.Ambiguous, semanticInfo.CandidateReason);
 645            Assert.Equal(2, semanticInfo.CandidateSymbols.Length);
 646            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 647            Assert.Equal("N1.A<T>", sortedCandidates[0].ToTestDisplayString());
 648            Assert.Equal(SymbolKind.NamedType, sortedCandidates[0].Kind);
 649            Assert.Equal("N2.A<U>", sortedCandidates[1].ToTestDisplayString());
 650            Assert.Equal(SymbolKind.NamedType, sortedCandidates[1].Kind);
 651
 652            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 653
 654            Assert.False(semanticInfo.IsCompileTimeConstant);
 655        }
 656
 657        [Fact]
 658        public void AmbiguityBetweenInterfaceMembers()
 659        {
 660            string sourceCode = @"
 661using System;
 662using System.Collections.Generic;
 663using System.Linq;
 664using System.Text;
 665
 666interface I1
 667{
 668    public int P { get; }
 669}
 670
 671interface I2
 672{
 673    public string P { get; }
 674}
 675
 676interface I3 : I1, I2
 677{ }
 678
 679public class Class1
 680{
 681    void f()
 682    {
 683        I3 x = null;
 684        int o = x./*<bind>*/P/*</bind>*/;
 685    }
 686}
 687";
 688            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 689
 690            Assert.Equal("I1.P", semanticInfo.Type.ToTestDisplayString());
 691            Assert.Equal(TypeKind.Error, semanticInfo.Type.TypeKind);
 692            Assert.Equal("System.Int32", semanticInfo.ConvertedType.ToTestDisplayString());
 693            Assert.Equal(TypeKind.Struct, semanticInfo.ConvertedType.TypeKind);
 694            Assert.Equal(ConversionKind.NoConversion, semanticInfo.ImplicitConversion.Kind);
 695
 696            Assert.Null(semanticInfo.Symbol);
 697            Assert.Equal(CandidateReason.Ambiguous, semanticInfo.CandidateReason);
 698            Assert.Equal(2, semanticInfo.CandidateSymbols.Length);
 699            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 700            Assert.Equal("System.Int32 I1.P { get; }", sortedCandidates[0].ToTestDisplayString());
 701            Assert.Equal(SymbolKind.Property, sortedCandidates[0].Kind);
 702            Assert.Equal("System.String I2.P { get; }", sortedCandidates[1].ToTestDisplayString());
 703            Assert.Equal(SymbolKind.Property, sortedCandidates[1].Kind);
 704
 705            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 706
 707            Assert.False(semanticInfo.IsCompileTimeConstant);
 708        }
 709
 710        [Fact]
 711        public void Alias1()
 712        {
 713            string sourceCode = @"
 714using O = System.Object;
 715
 716partial class A : /*<bind>*/O/*</bind>*/ {}
 717
 718";
 719            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 720
 721            Assert.Equal("System.Object", semanticInfo.Type.ToTestDisplayString());
 722            Assert.Equal(TypeKind.Class, semanticInfo.Type.TypeKind);
 723            Assert.Equal("System.Object", semanticInfo.ConvertedType.ToTestDisplayString());
 724            Assert.Equal(TypeKind.Class, semanticInfo.ConvertedType.TypeKind);
 725            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 726
 727            Assert.NotNull(semanticInfo.Symbol);
 728            Assert.Equal(0, semanticInfo.CandidateSymbols.Length);
 729
 730            var aliasInfo = GetAliasInfoForTest(sourceCode);
 731            Assert.NotNull(aliasInfo);
 732            Assert.Equal("O=System.Object", aliasInfo.ToTestDisplayString());
 733            Assert.Equal(SymbolKind.Alias, aliasInfo.Kind);
 734
 735            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 736
 737            Assert.False(semanticInfo.IsCompileTimeConstant);
 738        }
 739
 740        [Fact]
 741        public void Alias2()
 742        {
 743            string sourceCode = @"
 744using O = System.Object;
 745
 746partial class A {
 747    void f()
 748    {
 749        /*<bind>*/O/*</bind>*/.ReferenceEquals(null, null);
 750    }
 751}
 752
 753";
 754            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 755            var aliasInfo = GetAliasInfoForTest(sourceCode);
 756
 757            Assert.Equal("System.Object", semanticInfo.Type.ToTestDisplayString());
 758            Assert.Equal(TypeKind.Class, semanticInfo.Type.TypeKind);
 759            Assert.Equal("System.Object", semanticInfo.ConvertedType.ToTestDisplayString());
 760            Assert.Equal(TypeKind.Class, semanticInfo.ConvertedType.TypeKind);
 761            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 762
 763            Assert.NotNull(semanticInfo.Symbol);
 764            Assert.Equal(0, semanticInfo.CandidateSymbols.Length);
 765
 766            Assert.Equal("O=System.Object", aliasInfo.ToTestDisplayString());
 767            Assert.Equal(SymbolKind.Alias, aliasInfo.Kind);
 768
 769            Assert.Equal(0, semanticInfo.MethodGroup.Length);
 770
 771            Assert.False(semanticInfo.IsCompileTimeConstant);
 772        }
 773
 774        [WorkItem(539002, "DevDiv")]
 775        [Fact]
 776        public void IncompleteGenericMethodCall()
 777        {
 778            string sourceCode = @"
 779class Array
 780{
 781  public static void Find<T>(T t) { }
 782}
 783class C
 784{
 785  static void Main()
 786  {
 787    /*<bind>*/Array.Find<int>/*</bind>*/(
 788  }
 789}
 790";
 791            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 792
 793            Assert.Null(semanticInfo.Type);
 794            Assert.Null(semanticInfo.ConvertedType);
 795            Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
 796
 797            Assert.Null(semanticInfo.Symbol);
 798            Assert.Equal(CandidateReason.OverloadResolutionFailure, semanticInfo.CandidateReason);
 799            Assert.Equal(1, semanticInfo.CandidateSymbols.Length);
 800            var sortedCandidates = semanticInfo.CandidateSymbols.OrderBy(s => s.ToTestDisplayString()).ToArray();
 801            Assert.Equal("void Array.Find<System.Int32>(System.Int32 t)", sortedCandidates[0].ToTestDisplayString());
 802            Assert.Equal(SymbolKind.Method, sortedCandidates[0].Kind);
 803
 804            Assert.Equal(1, semanticInfo.MethodGroup.Length);
 805            var sortedMethodGroup = semanticInfo.MethodGroup.OrderBy(s => s.ToTestDisplayString()).ToArray();
 806            Assert.Equal("void Array.Find<System.Int32>(System.Int32 t)", sortedMethodGroup[0].ToTestDisplayString());
 807
 808            Assert.False(semanticInfo.IsCompileTimeConstant);
 809        }
 810
 811        [Fact]
 812        public void IncompleteExtensionMethodCall()
 813        {
 814            string sourceCode =
 815@"interface I<T> { }
 816class A { }
 817class B : A { }
 818class C
 819{
 820    static void M(A a)
 821    {
 822        /*<bind>*/a.M/*</bind>*/(
 823    }
 824}
 825static class S
 826{
 827    internal static void M(this object o, int x) { }
 828    internal static void M(this A a, int x, int y) { }
 829    internal static void M(this B b) { }
 830    internal static void M(this string s) { }
 831    internal static void M<T>(this T t, object o) { }
 832    internal static void M<T>(this T[] t) { }
 833    internal static void M<T, U>(this T x, I<T> y, U z) { }
 834}";
 835            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 836            Assert.Null(semanticInfo.Symbol);
 837            Utils.CheckSymbols(semanticInfo.MethodGroup,
 838                "void object.M(int x)",
 839                "void A.M(int x, int y)",
 840                "void A.M<A>(object o)",
 841                "void A.M<A, U>(I<A> y, U z)");
 842            Utils.CheckSymbols(semanticInfo.CandidateSymbols,
 843                "void object.M(int x)",
 844                "void A.M(int x, int y)",
 845                "void A.M<A>(object o)",
 846                "void A.M<A, U>(I<A> y, U z)");
 847            Utils.CheckReducedExtensionMethod((MethodSymbol)semanticInfo.MethodGroup[3],
 848                "void A.M<A, U>(I<A> y, U z)",
 849                "void S.M<T, U>(T x, I<T> y, U z)",
 850                "void T.M<T, U>(I<T> y, U z)",
 851                "void S.M<T, U>(T x, I<T> y, U z)");
 852        }
 853
 854        [Fact]
 855        public void IncompleteExtensionMethodCallBadThisType()
 856        {
 857            string sourceCode =
 858@"interface I<T> { }
 859class B
 860{
 861    static void M(I<A> a)
 862    {
 863        /*<bind>*/a.M/*</bind>*/(
 864    }
 865}
 866static class S
 867{
 868    internal static void M(this object o) { }
 869    internal static void M<T>(this T t, object o) { }
 870    internal static void M<T>(this T[] t) { }
 871    internal static void M<T, U>(this I<T> x, I<T> y, U z) { }
 872}";
 873            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 874            Utils.CheckSymbols(semanticInfo.MethodGroup,
 875                "void object.M()",
 876                "void I<A>.M<I<A>>(object o)",
 877                "void I<A>.M<A, U>(I<A> y, U z)");
 878        }
 879
 880        [WorkItem(541141, "DevDiv")]
 881        [Fact]
 882        public void IncompleteGenericExtensionMethodCall()
 883        {
 884            string sourceCode =
 885@"using System.Linq;
 886class C
 887{
 888    static void M(double[] a)
 889    {
 890        /*<bind>*/a.Where/*</bind>*/(
 891    }
 892}";
 893            var compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
 894            var semanticInfo = GetSemanticInfoForTest<ExpressionSyntax>(compilation);
 895            Utils.CheckSymbols(semanticInfo.MethodGroup,
 896                "IEnumerable<double> IEnumerable<double>.Where<double>(Func<double, bool> predicate)",
 897                "IEnumerable<double> IEnumerable<double>.Where<double>(Func<double, int, bool> predicate)");
 898        }
 899
 900        [WorkItem(541349, "DevDiv")]
 901        [Fact]
 902        public void GenericExtensionMethodCallExplicitTypeArgs()
 903        {
 904            string sourceCode =
 905@"interface I<T> { }
 906class C
 907{
 908    static void M(object o)
 909    {
 910        /*<bind>*/o.E<int>/*</bind>*/();
 911    }
 912}
 913static class S
 914{
 915    internal static void E(this object x, object y) { }
 916    internal static void E<T>(this object o) { }
 917    internal static void E<T>(this object o, T t) { }
 918    internal static void E<T>(this I<T> t) { }
 919    internal static void E<T, U>(this I<T> t) { }
 920}";
 921            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 922            Utils.CheckSymbol(semanticInfo.Symbol,
 923                "void object.E<int>()");
 924            Utils.CheckSymbols(semanticInfo.MethodGroup,
 925                "void object.E<int>()",
 926                "void object.E<int>(int t)");
 927            Utils.CheckSymbols(semanticInfo.CandidateSymbols);
 928        }
 929
 930        [Fact]
 931        public void GenericExtensionMethodCallExplicitTypeArgsOfT()
 932        {
 933            string sourceCode =
 934@"interface I<T> { }
 935class C
 936{
 937    static void M<T, U>(T t, U u)
 938    {
 939        /*<bind>*/t.E<T, U>/*</bind>*/(u);
 940    }
 941}
 942static class S
 943{
 944    internal static void E(this object x, object y) { }
 945    internal static void E<T>(this object o) { }
 946    internal static void E<T, U>(this T t, U u) { }
 947    internal static void E<T, U>(this I<T> t, U u) { }
 948}";
 949            var semanticInfo = GetSemanticInfoForTest(sourceCode);
 950            Utils.CheckSymbols(semanticInfo.MethodGroup,
 951                "void T.E<T, U>(U u)");
 952        }
 953
 954        [WorkItem(541297, "DevDiv")]
 955        [Fact]
 956        public void GenericExtensionMethodCall()
 957        {
 958            // Single applicable overload with valid argument.
 959            var semanticInfo = GetSemanticInfoForTest(
 960@"class C
 961{
 962    static void M(string s)
 963    {
 964        /*<bind>*/s.E(s)/*</bind>*/;
 965    }
 966}
 967static class S
 968{
 969    internal static void E<T>(this T x, object y) { }
 970    internal static void E<T, U>(this T x, U y) { }
 971}");
 972            Utils.CheckSymbol(semanticInfo.Symbol,
 973                "void string.E<string, string>(string y)");
 974            Utils.CheckSymbols(semanticInfo.MethodGroup);
 975            Utils.CheckSymbols(semanticInfo.CandidateSymbols);
 976
 977            // Multiple applicable overloads with valid arguments.
 978            semanticInfo = GetSemanticInfoForTest(
 979@"class C
 980{
 981    static void M(string s, object o)
 982    {
 983        /*<bind>*/s.E(s, o)/*</bind>*/;
 984    }
 985}
 986static class S
 987{
 988    internal static void E<T>(this object x, T y, object z) { }
 989    internal static void E<T, U>(this T x, object y, U z) { }
 990}");
 991            Assert.Null(semanticInfo.Symbol);
 992            Utils.CheckSymbols(semanticInfo.MethodGroup);
 993            Utils.CheckSymbols(semanticInfo.CandidateSymbols,
 994                "void object.E<string>(string y, object z)",
 995                "void string.E<string, object>(object y, object z)");
 996
 997            // Multiple applicable overloads with error argument.
 998            semanticInfo = GetSemanticInfoForTest(
 999@"class C
1000{
1001    static void M(string s)
1002    {
1003        /*<bind>*/s.E(t, s)/*</bind>*/;
1004    }
1005}
1006static class S
1007{
1008    internal static void E<T>(this T x, T y, object z) { }
1009    internal static void E<T, U>(this T x, string y, U z) { }
1010}");
1011            Assert.Null(semanticInfo.Symbol);
1012            Utils.CheckSymbols(semanticInfo.MethodGroup);
1013            Utils.CheckSymbols(semanticInfo.CandidateSymbols,
1014                "void string.E<string>(string y, object z)",
1015                "void string.E<string, string>(string y, string z)");
1016
1017            // Multiple overloads but all inaccessible.
1018            semanticInfo = GetSemanticInfoForTest(
1019@"class C
1020{
1021    static void M(string s)
1022    {
1023        /*<bind>*/s.E()/*</bind>*/;
1024    }
1025}
1026static class S
1027{
1028    static void E(this string x) { }
1029    static void E<T>(this T x) { }
1030}");
1031            Assert.Null(semanticInfo.Symbol);
1032            Utils.CheckSymbols(semanticInfo.MethodGroup);
1033            Utils.CheckSymbols(semanticInfo.CandidateSymbols,
1034                "void string.E()",
1035                "void string.E<string>()"
1036                );
1037        }
1038
1039        [Fact]
1040        public void GenericExtensionDelegateMethod()
1041        {
1042            // Single applicable overload.
1043            var semanticInfo = GetSemanticInfoForTest(
1044@"class C
1045{
1046    static void M(string s)
1047    {
1048        System.Action<string> a = /*<bind>*/s.E/*</bind>*/;
1049    }
1050}
1051static class S
1052{
1053    internal static void E<T>(this T x, T y) { }
1054    internal static void E<T>(this object x, T y) { }
1055}");
1056            Utils.CheckSymbol(semanticInfo.Symbol,
1057                "void string.E<string>(string y)");
1058            Utils.CheckSymbols(semanticInfo.MethodGroup,
1059                "void string.E<string>(string y)",
1060                "void object.E<T>(T y)");
1061            Utils.CheckSymbols(semanticInfo.CandidateSymbols);
1062
1063            // Multiple applicable overloads.
1064            semanticInfo = GetSemanticInfoForTest(
1065@"class C
1066{
1067    static void M(string s)
1068    {
1069        System.Action<string> a = /*<bind>*/s.E/*</bind>*/;
1070    }
1071}
1072static class S
1073{
1074    internal static void E<T>(this T x, T y) { }
1075    internal static void E<T, U>(this T x, U y) { }
1076}");
1077            Assert.Null(semanticInfo.Symbol);
1078            Utils.CheckSymbols(semanticInfo.MethodGroup,
1079                "void string.E<string>(string y)",
1080                "void string.E<string, U>(U y)");
1081            Utils.CheckSymbols(semanticInfo.CandidateSymbols,
1082                "void string.E<string>(string y)",
1083                "void string.E<string, U>(U y)");
1084        }
1085
1086        /// <summary>
1087        /// Overloads from different scopes should
1088        /// be included in method group.
1089        /// </summary>
1090        [WorkItem(541890, "DevDiv")]
1091        [Fact]
1092        public void IncompleteExtensionOverloadedDifferentScopes()
1093        {
1094            // Instance methods and extension method (implicit instance).
1095            var sourceCode =
1096@"class C
1097{
1098    void M()
1099    {
1100        /*<bind>*/F/*</bind>*/(
1101    }
1102    void F(int x) { }
1103    void F(object x, object y) { }
1104}
1105static class E
1106{
1107    internal static void F(this object x, object y) { }
1108}";
1109            var compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1110            var type = compilation.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
1111            var tree = compilation.SyntaxTrees[0];
1112            var model = compilation.GetSemanticModel(tree);
1113            var expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1114            var symbols = model.GetMemberGroup(expr);
1115            Utils.CheckSymbols(symbols,
1116                "void C.F(int x)",
1117                "void C.F(object x, object y)");
1118            symbols = model.LookupSymbols(expr.SpanStart, container: null, name: "F", includeReducedExtensionMethods: true);
1119            Utils.CheckSymbols(symbols,
1120                "void C.F(int x)",
1121                "void C.F(object x, object y)");
1122            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1123            Utils.CheckSymbols(symbols,
1124                "void C.F(int x)",
1125                "void C.F(object x, object y)",
1126                "void object.F(object y)");
1127
1128            // Instance methods and extension method (explicit instance).
1129            sourceCode =
1130@"class C
1131{
1132    void M()
1133    {
1134        /*<bind>*/this.F/*</bind>*/(
1135    }
1136    void F(int x) { }
1137    void F(object x, object y) { }
1138}
1139static class E
1140{
1141    internal static void F(this object x, object y) { }
1142}";
1143            compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1144            type = compilation.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
1145            tree = compilation.SyntaxTrees[0];
1146            model = compilation.GetSemanticModel(tree);
1147            expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1148            symbols = model.GetMemberGroup(expr);
1149            Utils.CheckSymbols(symbols,
1150                "void C.F(int x)",
1151                "void C.F(object x, object y)",
1152                "void object.F(object y)");
1153            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1154            Utils.CheckSymbols(symbols,
1155                "void C.F(int x)",
1156                "void C.F(object x, object y)",
1157                "void object.F(object y)");
1158
1159            // Applicable instance method and inapplicable extension method.
1160            sourceCode =
1161@"class C
1162{
1163    void M()
1164    {
1165        /*<bind>*/this.F<string>/*</bind>*/(
1166    }
1167    void F<T>(T t) { }
1168}
1169static class E
1170{
1171    internal static void F(this object x) { }
1172}";
1173            compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1174            type = compilation.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
1175            tree = compilation.SyntaxTrees[0];
1176            model = compilation.GetSemanticModel(tree);
1177            expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1178            symbols = model.GetMemberGroup(expr);
1179            Utils.CheckSymbols(symbols,
1180                "void C.F<string>(string t)");
1181            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1182            Utils.CheckSymbols(symbols,
1183                "void C.F<T>(T t)",
1184                "void object.F()");
1185
1186            // Inaccessible instance method and accessible extension method.
1187            sourceCode =
1188@"class A
1189{
1190    void F() { }
1191}
1192class B : A
1193{
1194    static void M(A a)
1195    {
1196        /*<bind>*/a.F/*</bind>*/(
1197    }
1198}
1199static class E
1200{
1201    internal static void F(this object x) { }
1202}";
1203            compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1204            type = compilation.GlobalNamespace.GetMember<NamedTypeSymbol>("A");
1205            tree = compilation.SyntaxTrees[0];
1206            model = compilation.GetSemanticModel(tree);
1207            expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1208            symbols = model.GetMemberGroup(expr);
1209            Utils.CheckSymbols(symbols,
1210                "void object.F()");
1211            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1212            Utils.CheckSymbols(symbols,
1213                "void object.F()");
1214
1215            // Inapplicable instance method and applicable extension method.
1216            sourceCode =
1217@"class C
1218{
1219    void M()
1220    {
1221        /*<bind>*/this.F<string>/*</bind>*/(
1222    }
1223    void F(object o) { }
1224}
1225static class E
1226{
1227    internal static void F<T>(this object x) { }
1228}";
1229            compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1230            type = compilation.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
1231            tree = compilation.SyntaxTrees[0];
1232            model = compilation.GetSemanticModel(tree);
1233            expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1234            symbols = model.GetMemberGroup(expr);
1235            Utils.CheckSymbols(symbols,
1236                "void object.F<string>()");
1237            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1238            Utils.CheckSymbols(symbols,
1239                "void C.F(object o)",
1240                "void object.F<T>()");
1241
1242            // Viable instance and extension methods, binding to extension method.
1243            sourceCode =
1244@"class C
1245{
1246    void M()
1247    {
1248        /*<bind>*/this.F/*</bind>*/();
1249    }
1250    void F(object o) { }
1251}
1252static class E
1253{
1254    internal static void F(this object x) { }
1255}";
1256            compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1257            type = compilation.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
1258            tree = compilation.SyntaxTrees[0];
1259            model = compilation.GetSemanticModel(tree);
1260            expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1261            symbols = model.GetMemberGroup(expr);
1262            Utils.CheckSymbols(symbols,
1263                "void C.F(object o)",
1264                "void object.F()");
1265            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1266            Utils.CheckSymbols(symbols,
1267                "void C.F(object o)",
1268                "void object.F()");
1269
1270            // Applicable and inaccessible extension methods.
1271            sourceCode =
1272@"class C
1273{
1274    void M(string s)
1275    {
1276        /*<bind>*/s.F<string>/*</bind>*/(
1277    }
1278}
1279static class E
1280{
1281    internal static void F(this object x, object y) { }
1282    internal static void F<T>(this T t) { }
1283}";
1284            compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1285            type = compilation.GetSpecialType(SpecialType.System_String);
1286            tree = compilation.SyntaxTrees[0];
1287            model = compilation.GetSemanticModel(tree);
1288            expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1289            symbols = model.GetMemberGroup(expr);
1290            Utils.CheckSymbols(symbols,
1291                "void string.F<string>()");
1292            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1293            Utils.CheckSymbols(symbols,
1294                "void object.F(object y)",
1295                "void string.F<string>()");
1296
1297            // Inapplicable and inaccessible extension methods.
1298            sourceCode =
1299@"class C
1300{
1301    void M(string s)
1302    {
1303        /*<bind>*/s.F<string>/*</bind>*/(
1304    }
1305}
1306static class E
1307{
1308    internal static void F(this object x, object y) { }
1309    private static void F<T>(this T t) { }
1310}";
1311            compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1312            type = compilation.GetSpecialType(SpecialType.System_String);
1313            tree = compilation.SyntaxTrees[0];
1314            model = compilation.GetSemanticModel(tree);
1315            expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1316            symbols = model.GetMemberGroup(expr);
1317            Utils.CheckSymbols(symbols,
1318                "void string.F<string>()");
1319            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1320            Utils.CheckSymbols(symbols,
1321                "void object.F(object y)");
1322
1323            // Multiple scopes.
1324            sourceCode =
1325@"namespace N1
1326{
1327    static class E
1328    {
1329        internal static void F(this object o) { }
1330    }
1331}
1332namespace N2
1333{
1334    using N1;
1335    class C
1336    {
1337        static void M(C c)
1338        {
1339            /*<bind>*/c.F/*</bind>*/(
1340        }
1341        void F(int x) { }
1342    }
1343    static class E
1344    {
1345        internal static void F(this object x, object y) { }
1346    }
1347}
1348static class E
1349{
1350    internal static void F(this object x, object y, object z) { }
1351}";
1352            compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1353            type = compilation.GlobalNamespace.GetMember<NamespaceSymbol>("N2").GetMember<NamedTypeSymbol>("C");
1354            tree = compilation.SyntaxTrees[0];
1355            model = compilation.GetSemanticModel(tree);
1356            expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1357            symbols = model.GetMemberGroup(expr);
1358            Utils.CheckSymbols(symbols,
1359                "void C.F(int x)",
1360                "void object.F(object y)",
1361                "void object.F()",
1362                "void object.F(object y, object z)");
1363            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1364            Utils.CheckSymbols(symbols,
1365                "void C.F(int x)",
1366                "void object.F(object y)",
1367                "void object.F()",
1368                "void object.F(object y, object z)");
1369
1370            // Multiple scopes, no instance methods.
1371            sourceCode =
1372@"namespace N
1373{
1374    class C
1375    {
1376        static void M(C c)
1377        {
1378            /*<bind>*/c.F/*</bind>*/(
1379        }
1380    }
1381    static class E
1382    {
1383        internal static void F(this object x, object y) { }
1384    }
1385}
1386static class E
1387{
1388    internal static void F(this object x, object y, object z) { }
1389}";
1390            compilation = CreateCompilationWithMscorlib(references: new MetadataReference[] { SystemCoreRef }, text: sourceCode);
1391            type = compilation.GlobalNamespace.GetMember<NamespaceSymbol>("N").GetMember<NamedTypeSymbol>("C");
1392            tree = compilation.SyntaxTrees[0];
1393            model = compilation.GetSemanticModel(tree);
1394            expr = GetSyntaxNodeOfTypeForBinding<ExpressionSyntax>(GetSyntaxNodeList(tree));
1395            symbols = model.GetMemberGroup(expr);
1396            Utils.CheckSymbols(symbols,
1397                "void object.F(object y)",
1398                "void object.F(object y, object z)");
1399            symbols = model.LookupSymbols(expr.SpanStart, container: type, name: "F", includeReducedExtensionMethods: true);
1400            Utils.CheckSymbols(symbols,
1401                "void object.F(object y)",
1402                "void object.F(object y, object z)");
1403        }
1404
1405        [Fact]
1406        public void PropertyGroup()
1407        {
1408            var source1 =
1409@"Imports System
1410Imports System.Runtime.InteropServices
1411<Assembly: PrimaryInteropAssembly(0, 0)> 
1412<Assembly: Guid(""165F752D-E9C4-4F7E-B0D0-CDFD7A36E210"")> 
1413<ComImport()>
1414<Guid(""165F752D-E9C4-4F7E-B0D0-CDFD7A36E211"")>
1415Public Class A
1416    Property P(Optional x As Integer = 0) As Object
1417        Get
1418            Return Nothing
1419        End Get
1420        Set
1421        End Set
1422    End Property
1423    Property P(x As Integer, y As Integer) As Integer
1424        Get
1425            Return Nothing
1426        End Get
1427        Set
1428        End Set
1429    End Property
1430    Property P(x As Integer, y As String) As String
1431        Get
1432            Return Nothing
1433        End Get
1434        Set
1435        End Set
1436    End Property
1437End Class";
1438            var reference1 = BasicCompilationUtils.CompileToMetadata(source1, verify: false);
1439
1440            // Assignment (property group).
1441            var source2 =
1442@"class B
1443{
1444    static void M(A a)
1445    {
1446        /*<bind>*/a.P/*</bind>*/[1, null] = string.Empty;
1447    }
1448}";
1449            var compilation = CreateCompilationWithMscorlib(source2, new[] { reference1 });
1450            var semanticInfo = GetSemanticInfoForTest<ExpressionSyntax>(compilation);
1451            Utils.CheckSymbol(semanticInfo.Symbol, "string A.P[int x, string y]");
1452            Utils.CheckSymbols(semanticInfo.MemberGroup,
1453                "object A.P[int x = 0]",
1454                "int A.P[int x, int y]",
1455                "string A.P[int x, string y]");
1456            Utils.CheckSymbols(semanticInfo.CandidateSymbols);
1457
1458            // Assignment (property access).
1459            source2 =
1460@"class B
1461{
1462    static void M(A a)
1463    {
1464        /*<bind>*/a.P[1, null]/*</bind>*/ = string.Empty;
1465    }
1466}";
1467            compilation = CreateCompilationWithMscorlib(source2, new[] { reference1 });
1468            semanticInfo = GetSemanticInfoForTest<ExpressionSyntax>(compilation);
1469            Utils.CheckSymbol(semanticInfo.Symbol, "string A.P[int x, string y]");
1470            Utils.CheckSym

Large files files are truncated, but you can click here to view the full file