TypeInferrerTests.cs 57.8 KB
Newer Older
S
Sam Harwell 已提交
1
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
2 3

using System.Threading;
C
Cyrus Najmabadi 已提交
4
using System.Threading.Tasks;
5 6 7 8 9 10
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.UnitTests.TypeInferrer;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
11
using Microsoft.CodeAnalysis.Test.Utilities;
12 13 14 15 16 17 18 19
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.TypeInferrer
{
    public partial class TypeInferrerTests : TypeInferrerTestBase<CSharpTestWorkspaceFixture>
    {
20 21 22 23
        public TypeInferrerTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture)
        {
        }

24
        protected override async Task TestWorkerAsync(Document document, TextSpan textSpan, string expectedType, bool useNodeStartPosition)
25
        {
26
            var root = await document.GetSyntaxRootAsync();
27 28 29 30
            var node = FindExpressionSyntaxFromSpan(root, textSpan);
            var typeInference = document.GetLanguageService<ITypeInferenceService>();

            var inferredType = useNodeStartPosition
C
Cyrus Najmabadi 已提交
31 32
                ? typeInference.InferType(await document.GetSemanticModelForSpanAsync(new TextSpan(node?.SpanStart ?? textSpan.Start, 0), CancellationToken.None), node?.SpanStart ?? textSpan.Start, objectAsDefault: true, cancellationToken: CancellationToken.None)
                : typeInference.InferType(await document.GetSemanticModelForSpanAsync(node?.Span ?? textSpan, CancellationToken.None), node, objectAsDefault: true, cancellationToken: CancellationToken.None);
C
Cyrus Najmabadi 已提交
33
            var typeSyntax = inferredType.GenerateTypeSyntax().NormalizeWhitespace();
34 35 36
            Assert.Equal(expectedType, typeSyntax.ToString());
        }

C
Cyrus Najmabadi 已提交
37
        private async Task TestInClassAsync(string text, string expectedType)
38 39 40 41 42
        {
            text = @"class C
{
    $
}".Replace("$", text);
C
Cyrus Najmabadi 已提交
43
            await TestAsync(text, expectedType);
44 45
        }

C
Cyrus Najmabadi 已提交
46
        private async Task TestInMethodAsync(string text, string expectedType, bool testNode = true, bool testPosition = true)
47 48 49 50 51 52 53 54
        {
            text = @"class C
{
    void M()
    {
        $
    }
}".Replace("$", text);
C
Cyrus Najmabadi 已提交
55
            await TestAsync(text, expectedType, testNode: testNode, testPosition: testPosition);
56 57 58 59 60 61 62 63
        }

        private ExpressionSyntax FindExpressionSyntaxFromSpan(SyntaxNode root, TextSpan textSpan)
        {
            var token = root.FindToken(textSpan.Start);
            var currentNode = token.Parent;
            while (currentNode != null)
            {
C
CyrusNajmabadi 已提交
64
                if (currentNode is ExpressionSyntax result && result.Span == textSpan)
65 66 67 68 69 70 71 72 73 74
                {
                    return result;
                }

                currentNode = currentNode.Parent;
            }

            return null;
        }

75
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
76
        public async Task TestConditional1()
77 78 79
        {
            // We do not support position inference here as we're before the ? and we only look
            // backwards to infer a type here.
80
            await TestInMethodAsync(
81
@"var q = [|Goo()|] ? 1 : 2;", "global::System.Boolean",
82 83 84
                testPosition: false);
        }

85
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
86
        public async Task TestConditional2()
87
        {
88
            await TestInMethodAsync(
89
@"var q = a ? [|Goo()|] : 2;", "global::System.Int32");
90 91
        }

92
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
93
        public async Task TestConditional3()
94
        {
95
            await TestInMethodAsync(
96
@"var q = a ? """" : [|Goo()|];", "global::System.String");
97 98
        }

99
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
100
        public async Task TestVariableDeclarator1()
101
        {
102
            await TestInMethodAsync(
103
@"int q = [|Goo()|];", "global::System.Int32");
104 105
        }

106
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
107
        public async Task TestVariableDeclarator2()
108
        {
109
            await TestInMethodAsync(
110
@"var q = [|Goo()|];", "global::System.Object");
111 112
        }

113
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
114
        public async Task TestCoalesce1()
115
        {
116
            await TestInMethodAsync(
117
@"var q = [|Goo()|] ?? 1;", "global::System.Int32?", testPosition: false);
118 119
        }

120
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
121
        public async Task TestCoalesce2()
122
        {
123 124
            await TestInMethodAsync(
@"bool? b;
125
var q = b ?? [|Goo()|];", "global::System.Boolean");
126 127
        }

128
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
129
        public async Task TestCoalesce3()
130
        {
131 132
            await TestInMethodAsync(
@"string s;
133
var q = s ?? [|Goo()|];", "global::System.String");
134 135
        }

136
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
137
        public async Task TestCoalesce4()
138
        {
139
            await TestInMethodAsync(
140
@"var q = [|Goo()|] ?? string.Empty;", "global::System.String", testPosition: false);
141 142
        }

143
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
144
        public async Task TestBinaryExpression1()
145
        {
146 147
            await TestInMethodAsync(
@"string s;
148
var q = s + [|Goo()|];", "global::System.String");
149 150
        }

151
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
152
        public async Task TestBinaryExpression2()
153
        {
154 155
            await TestInMethodAsync(
@"var s;
156
var q = s || [|Goo()|];", "global::System.Boolean");
157 158
        }

159
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
160
        public async Task TestBinaryOperator1()
161
        {
162
            await TestInMethodAsync(
163
@"var q = x << [|Goo()|];", "global::System.Int32");
164 165
        }

166
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
167
        public async Task TestBinaryOperator2()
168
        {
169
            await TestInMethodAsync(
170
@"var q = x >> [|Goo()|];", "global::System.Int32");
171 172
        }

173
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
174
        public async Task TestAssignmentOperator3()
175
        {
176
            await TestInMethodAsync(
177
@"var q <<= [|Goo()|];", "global::System.Int32");
178 179
        }

180
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
181
        public async Task TestAssignmentOperator4()
182
        {
183
            await TestInMethodAsync(
184
@"var q >>= [|Goo()|];", "global::System.Int32");
185 186
        }

187
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
188
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
189
        public async Task TestOverloadedConditionalLogicalOperatorsInferBool()
190
        {
C
CyrusNajmabadi 已提交
191 192 193
            await TestAsync(
@"using System;

194 195
class C
{
C
CyrusNajmabadi 已提交
196 197 198 199 200 201 202 203 204 205 206 207 208 209
    public static C operator &(C c, C d)
    {
        return null;
    }

    public static bool operator true(C c)
    {
        return true;
    }

    public static bool operator false(C c)
    {
        return false;
    }
210 211 212

    static void Main(string[] args)
    {
213
        var c = new C() && [|Goo()|];
214
    }
C
CyrusNajmabadi 已提交
215
}", "global::System.Boolean");
216 217
        }

218
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
219
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
220
        public async Task TestConditionalLogicalOrOperatorAlwaysInfersBool()
221 222 223 224 225 226 227 228 229
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = a || [|7|];
    }
}";
C
CyrusNajmabadi 已提交
230
            await TestAsync(text, "global::System.Boolean");
231 232
        }

233
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
234
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
235
        public async Task TestConditionalLogicalAndOperatorAlwaysInfersBool()
236 237 238 239 240 241 242 243 244
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = a && [|7|];
    }
}";
C
CyrusNajmabadi 已提交
245
            await TestAsync(text, "global::System.Boolean");
246 247
        }

248
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
249
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
250
        public async Task TestLogicalOrOperatorInference1()
251 252 253 254 255 256 257 258 259
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = [|a|] | true;
    }
}";
C
CyrusNajmabadi 已提交
260
            await TestAsync(text, "global::System.Boolean", testPosition: false);
261 262
        }

263
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
264
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
265
        public async Task TestLogicalOrOperatorInference2()
266 267 268 269 270 271 272 273 274
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = [|a|] | b | c || d;
    }
}";
C
CyrusNajmabadi 已提交
275
            await TestAsync(text, "global::System.Boolean", testPosition: false);
276 277
        }

278
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
279
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
280
        public async Task TestLogicalOrOperatorInference3()
281 282 283 284 285 286 287 288 289
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = a | b | [|c|] || d;
    }
}";
C
CyrusNajmabadi 已提交
290
            await TestAsync(text, "global::System.Boolean");
291 292
        }

293
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
294
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
295
        public async Task TestLogicalOrOperatorInference4()
296 297 298 299 300 301
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
302
        var x = Goo([|a|] | b);
303
    }
304
    static object Goo(Program p)
305 306 307 308
    {
        return p;
    }
}";
C
Cyrus Najmabadi 已提交
309
            await TestAsync(text, "Program", testPosition: false);
310 311
        }

312
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
313
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
314
        public async Task TestLogicalOrOperatorInference5()
315 316 317 318 319 320
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
321
        var x = Goo([|a|] | b);
322
    }
323
    static object Goo(bool p)
324 325 326 327
    {
        return p;
    }
}";
C
CyrusNajmabadi 已提交
328
            await TestAsync(text, "global::System.Boolean");
329 330
        }

331
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
332
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
333
        public async Task TestLogicalOrOperatorInference6()
334 335 336 337 338 339 340 341 342
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if (([|x|] | y) != 0) {}
    }
}";
C
CyrusNajmabadi 已提交
343
            await TestAsync(text, "global::System.Int32", testPosition: false);
344 345
        }

346
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
347
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
348
        public async Task TestLogicalOrOperatorInference7()
349 350 351 352 353 354 355 356 357
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if ([|x|] | y) {}
    }
}";
C
CyrusNajmabadi 已提交
358
            await TestAsync(text, "global::System.Boolean");
359 360
        }

361
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
362
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
363
        public async Task TestLogicalAndOperatorInference1()
364 365 366 367 368 369 370 371 372
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = [|a|] & true;
    }
}";
C
CyrusNajmabadi 已提交
373
            await TestAsync(text, "global::System.Boolean", testPosition: false);
374 375
        }

376
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
377
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
378
        public async Task TestLogicalAndOperatorInference2()
379 380 381 382 383 384 385 386 387
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = [|a|] & b & c && d;
    }
}";
C
CyrusNajmabadi 已提交
388
            await TestAsync(text, "global::System.Boolean", testPosition: false);
389 390
        }

391
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
392
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
393
        public async Task TestLogicalAndOperatorInference3()
394 395 396 397 398 399 400 401 402
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = a & b & [|c|] && d;
    }
}";
C
CyrusNajmabadi 已提交
403
            await TestAsync(text, "global::System.Boolean");
404 405
        }

406
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
407
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
408
        public async Task TestLogicalAndOperatorInference4()
409 410 411 412 413 414
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
415
        var x = Goo([|a|] & b);
416
    }
417
    static object Goo(Program p)
418 419 420 421
    {
        return p;
    }
}";
C
Cyrus Najmabadi 已提交
422
            await TestAsync(text, "Program", testPosition: false);
423 424
        }

425
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
426
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
427
        public async Task TestLogicalAndOperatorInference5()
428 429 430 431 432 433
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
434
        var x = Goo([|a|] & b);
435
    }
436
    static object Goo(bool p)
437 438 439 440
    {
        return p;
    }
}";
C
CyrusNajmabadi 已提交
441
            await TestAsync(text, "global::System.Boolean");
442 443
        }

444
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
445
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
446
        public async Task TestLogicalAndOperatorInference6()
447 448 449 450 451 452 453 454 455
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if (([|x|] & y) != 0) {}
    }
}";
C
CyrusNajmabadi 已提交
456
            await TestAsync(text, "global::System.Int32", testPosition: false);
457 458
        }

459
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
460
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
461
        public async Task TestLogicalAndOperatorInference7()
462 463 464 465 466 467 468 469 470
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if ([|x|] & y) {}
    }
}";
C
CyrusNajmabadi 已提交
471
            await TestAsync(text, "global::System.Boolean");
472 473
        }

474
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
475
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
476
        public async Task TestLogicalXorOperatorInference1()
477 478 479 480 481 482 483 484 485
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = [|a|] ^ true;
    }
}";
C
CyrusNajmabadi 已提交
486
            await TestAsync(text, "global::System.Boolean", testPosition: false);
487 488
        }

489
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
490
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
491
        public async Task TestLogicalXorOperatorInference2()
492 493 494 495 496 497 498 499 500
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = [|a|] ^ b ^ c && d;
    }
}";
C
CyrusNajmabadi 已提交
501
            await TestAsync(text, "global::System.Boolean", testPosition: false);
502 503
        }

504
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
505
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
506
        public async Task TestLogicalXorOperatorInference3()
507 508 509 510 511 512 513 514 515
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = a ^ b ^ [|c|] && d;
    }
}";
C
CyrusNajmabadi 已提交
516
            await TestAsync(text, "global::System.Boolean");
517 518
        }

519
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
520
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
521
        public async Task TestLogicalXorOperatorInference4()
522 523 524 525 526 527
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
528
        var x = Goo([|a|] ^ b);
529
    }
530
    static object Goo(Program p)
531 532 533 534
    {
        return p;
    }
}";
C
Cyrus Najmabadi 已提交
535
            await TestAsync(text, "Program", testPosition: false);
536 537
        }

538
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
539
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
540
        public async Task TestLogicalXorOperatorInference5()
541 542 543 544 545 546
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
547
        var x = Goo([|a|] ^ b);
548
    }
549
    static object Goo(bool p)
550 551 552 553
    {
        return p;
    }
}";
C
CyrusNajmabadi 已提交
554
            await TestAsync(text, "global::System.Boolean");
555 556
        }

557
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
558
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
559
        public async Task TestLogicalXorOperatorInference6()
560 561 562 563 564 565 566 567 568
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if (([|x|] ^ y) != 0) {}
    }
}";
C
CyrusNajmabadi 已提交
569
            await TestAsync(text, "global::System.Int32", testPosition: false);
570 571
        }

572
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
573
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
574
        public async Task TestLogicalXorOperatorInference7()
575 576 577 578 579 580 581 582 583
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if ([|x|] ^ y) {}
    }
}";
C
CyrusNajmabadi 已提交
584
            await TestAsync(text, "global::System.Boolean");
585 586
        }

587
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
588
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
589
        public async Task TestLogicalOrEqualsOperatorInference1()
590 591 592 593 594 595 596 597 598
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if ([|x|] |= y) {}
    }
}";
C
CyrusNajmabadi 已提交
599
            await TestAsync(text, "global::System.Boolean");
600 601
        }

602
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
603
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
604
        public async Task TestLogicalOrEqualsOperatorInference2()
605 606 607 608 609 610 611 612 613
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        int z = [|x|] |= y;
    }
}";
C
CyrusNajmabadi 已提交
614
            await TestAsync(text, "global::System.Int32");
615 616
        }

617
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
618
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
619
        public async Task TestLogicalAndEqualsOperatorInference1()
620 621 622 623 624 625 626 627 628
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if ([|x|] &= y) {}
    }
}";
C
CyrusNajmabadi 已提交
629
            await TestAsync(text, "global::System.Boolean");
630 631
        }

632
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
633
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
634
        public async Task TestLogicalAndEqualsOperatorInference2()
635 636 637 638 639 640 641 642 643
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        int z = [|x|] &= y;
    }
}";
C
CyrusNajmabadi 已提交
644
            await TestAsync(text, "global::System.Int32");
645 646
        }

647
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
648
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
649
        public async Task TestLogicalXorEqualsOperatorInference1()
650 651 652 653 654 655 656 657 658
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if ([|x|] ^= y) {}
    }
}";
C
CyrusNajmabadi 已提交
659
            await TestAsync(text, "global::System.Boolean");
660 661
        }

662
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
663
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
664
        public async Task TestLogicalXorEqualsOperatorInference2()
665 666 667 668 669 670 671 672 673
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        int z = [|x|] ^= y;
    }
}";
C
CyrusNajmabadi 已提交
674
            await TestAsync(text, "global::System.Int32");
675 676
        }

677
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
678
        public async Task TestReturn1()
679
        {
680 681 682
            await TestInClassAsync(
@"int M()
{
683
    return [|Goo()|];
684
}", "global::System.Int32");
685 686
        }

687
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
688
        public async Task TestReturn2()
689
        {
690
            await TestInMethodAsync(
691
@"return [|Goo()|];", "void");
692 693
        }

694
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
695
        public async Task TestReturn3()
696
        {
697 698 699 700 701
            await TestInClassAsync(
@"int Property
{
    get
    {
702
        return [|Goo()|];
703 704
    }
}", "global::System.Int32");
705 706
        }

707
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
708
        [WorkItem(827897, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/827897")]
C
Cyrus Najmabadi 已提交
709
        public async Task TestYieldReturn()
710 711 712 713 714 715 716 717 718 719 720
        {
            var markup =
@"using System.Collections.Generic;

class Program
{
    IEnumerable<int> M()
    {
        yield return [|abc|]
    }
}";
C
CyrusNajmabadi 已提交
721
            await TestAsync(markup, "global::System.Int32");
722 723
        }

724
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
725
        public async Task TestReturnInSimpleLambda()
726
        {
727 728 729
            await TestInMethodAsync(
@"System.Func<string, int> f = s =>
{
730
    return [|Goo()|];
731
};", "global::System.Int32");
732 733
        }

734
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
        public async Task TestReturnInParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Func<int> f = () =>
{
    return [|Goo()|];
};", "global::System.Int32");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAnonymousMethod()
        {
            await TestInMethodAsync(
@"System.Func<int> f = delegate ()
{
    return [|Goo()|];
};", "global::System.Int32");
        }

754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
        [WorkItem(4486, "https://github.com/dotnet/roslyn/issues/4486")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncSimpleLambda()
        {
            await TestInMethodAsync(
@"System.Func<string, System.Threading.Tasks.Task<int>> f = async s =>
{
    return [|Goo()|];
};", "global::System.Int32");
        }

        [WorkItem(4486, "https://github.com/dotnet/roslyn/issues/4486")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Func<System.Threading.Tasks.Task<int>> f = async () =>
{
    return [|Goo()|];
};", "global::System.Int32");
        }

        [WorkItem(4486, "https://github.com/dotnet/roslyn/issues/4486")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncAnonymousMethod()
        {
            await TestInMethodAsync(
@"System.Func<System.Threading.Tasks.Task<int>> f = async delegate ()
{
    return [|Goo()|];
};", "global::System.Int32");
        }

787 788
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestSimpleLambda()
789
        {
790
            await TestInMethodAsync(
791
@"System.Func<string, int> f = s => [|Goo()|];", "global::System.Int32");
792 793
        }

794 795 796 797 798 799 800
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Func<int> f = () => [|Goo()|];", "global::System.Int32");
        }

801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
        [WorkItem(30232, "https://github.com/dotnet/roslyn/issues/30232")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestAsyncSimpleLambda()
        {
            await TestInMethodAsync(
@"System.Func<string, System.Threading.Tasks.Task<int>> f = async s => [|Goo()|];", "global::System.Int32");
        }

        [WorkItem(30232, "https://github.com/dotnet/roslyn/issues/30232")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestAsyncParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Func<System.Threading.Tasks.Task<int>> f = async () => [|Goo()|];", "global::System.Int32");
        }

817 818 819 820 821 822 823 824 825 826 827 828 829 830
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionTreeSimpleLambda()
        {
            await TestInMethodAsync(
@"System.Linq.Expressions.Expression<System.Func<string, int>> f = s => [|Goo()|];", "global::System.Int32");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionTreeParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Linq.Expressions.Expression<System.Func<int>> f = () => [|Goo()|];", "global::System.Int32");
        }

831
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
832
        public async Task TestThrow()
833
        {
834
            await TestInMethodAsync(
835
@"throw [|Goo()|];", "global::System.Exception");
836 837
        }

838
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
839
        public async Task TestCatch()
840
        {
841
            await TestInMethodAsync("try { } catch ([|Goo|] ex) { }", "global::System.Exception");
842 843
        }

844
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
845
        public async Task TestIf()
846
        {
847
            await TestInMethodAsync(@"if ([|Goo()|]) { }", "global::System.Boolean");
848 849
        }

850
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
851
        public async Task TestWhile()
852
        {
853
            await TestInMethodAsync(@"while ([|Goo()|]) { }", "global::System.Boolean");
854 855
        }

856
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
857
        public async Task TestDo()
858
        {
859
            await TestInMethodAsync(@"do { } while ([|Goo()|])", "global::System.Boolean");
860 861
        }

862
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
863
        public async Task TestFor1()
864
        {
865
            await TestInMethodAsync(
866
@"for (int i = 0; [|Goo()|];
867 868

i++) { }", "global::System.Boolean");
869 870
        }

871
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
872
        public async Task TestFor2()
873
        {
874
            await TestInMethodAsync(@"for (string i = [|Goo()|]; ; ) { }", "global::System.String");
875 876
        }

877
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
878
        public async Task TestFor3()
879
        {
880
            await TestInMethodAsync(@"for (var i = [|Goo()|]; ; ) { }", "global::System.Int32");
881 882
        }

883
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
884
        public async Task TestUsing1()
885
        {
886
            await TestInMethodAsync(@"using ([|Goo()|]) { }", "global::System.IDisposable");
887 888
        }

889
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
890
        public async Task TestUsing2()
891
        {
892
            await TestInMethodAsync(@"using (int i = [|Goo()|]) { }", "global::System.Int32");
893 894
        }

895
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
896
        public async Task TestUsing3()
897
        {
898
            await TestInMethodAsync(@"using (var v = [|Goo()|]) { }", "global::System.IDisposable");
899 900
        }

901
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
902
        public async Task TestForEach()
903
        {
904
            await TestInMethodAsync(@"foreach (int v in [|Goo()|]) { }", "global::System.Collections.Generic.IEnumerable<global::System.Int32>");
905 906
        }

907
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
908
        public async Task TestPrefixExpression1()
909
        {
910
            await TestInMethodAsync(
911
@"var q = +[|Goo()|];", "global::System.Int32");
912 913
        }

914
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
915
        public async Task TestPrefixExpression2()
916
        {
917
            await TestInMethodAsync(
918
@"var q = -[|Goo()|];", "global::System.Int32");
919 920
        }

921
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
922
        public async Task TestPrefixExpression3()
923
        {
924
            await TestInMethodAsync(
925
@"var q = ~[|Goo()|];", "global::System.Int32");
926 927
        }

928
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
929
        public async Task TestPrefixExpression4()
930
        {
931
            await TestInMethodAsync(
932
@"var q = ![|Goo()|];", "global::System.Boolean");
933 934
        }

B
Brandon 已提交
935 936 937
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestPrefixExpression5()
        {
938
            await TestInMethodAsync(
939
@"var q = System.DayOfWeek.Monday & ~[|Goo()|];", "global::System.DayOfWeek");
B
Brandon 已提交
940 941
        }

942
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
943
        public async Task TestArrayRankSpecifier()
944
        {
945
            await TestInMethodAsync(
946
@"var q = new string[[|Goo()|]];", "global::System.Int32");
947 948
        }

949
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
950
        public async Task TestSwitch1()
951
        {
952
            await TestInMethodAsync(@"switch ([|Goo()|]) { }", "global::System.Int32");
953 954
        }

955
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
956
        public async Task TestSwitch2()
957
        {
958
            await TestInMethodAsync(@"switch ([|Goo()|]) { default: }", "global::System.Int32");
959 960
        }

961
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
962
        public async Task TestSwitch3()
963
        {
964
            await TestInMethodAsync(@"switch ([|Goo()|]) { case ""a"": }", "global::System.String");
965 966
        }

967
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
968
        public async Task TestMethodCall1()
969
        {
970
            await TestInMethodAsync(
971
@"Bar([|Goo()|]);", "global::System.Object");
972 973
        }

974
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
975
        public async Task TestMethodCall2()
976
        {
977 978 979
            await TestInClassAsync(
@"void M()
{
980
    Bar([|Goo()|]);
981 982 983
}

void Bar(int i);", "global::System.Int32");
984 985
        }

986
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
987
        public async Task TestMethodCall3()
988
        {
989 990 991
            await TestInClassAsync(
@"void M()
{
992
    Bar([|Goo()|]);
993 994 995
}

void Bar();", "global::System.Object");
996 997
        }

998
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
999
        public async Task TestMethodCall4()
1000
        {
1001 1002 1003
            await TestInClassAsync(
@"void M()
{
1004
    Bar([|Goo()|]);
1005 1006 1007
}

void Bar(int i, string s);", "global::System.Int32");
1008 1009
        }

1010
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1011
        public async Task TestMethodCall5()
1012
        {
1013 1014 1015
            await TestInClassAsync(
@"void M()
{
1016
    Bar(s: [|Goo()|]);
1017 1018 1019
}

void Bar(int i, string s);", "global::System.String");
1020 1021
        }

1022
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1023
        public async Task TestConstructorCall1()
1024
        {
1025
            await TestInMethodAsync(
1026
@"new C([|Goo()|]);", "global::System.Object");
1027 1028
        }

1029
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1030
        public async Task TestConstructorCall2()
1031
        {
1032 1033 1034
            await TestInClassAsync(
@"void M()
{
1035
    new C([|Goo()|]);
1036 1037 1038
} C(int i)
{
}", "global::System.Int32");
1039 1040
        }

1041
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1042
        public async Task TestConstructorCall3()
1043
        {
1044 1045 1046
            await TestInClassAsync(
@"void M()
{
1047
    new C([|Goo()|]);
1048 1049 1050
} C()
{
}", "global::System.Object");
1051 1052
        }

1053
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1054
        public async Task TestConstructorCall4()
1055
        {
1056 1057 1058
            await TestInClassAsync(
@"void M()
{
1059
    new C([|Goo()|]);
1060 1061 1062
} C(int i, string s)
{
}", "global::System.Int32");
1063 1064
        }

1065
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1066
        public async Task TestConstructorCall5()
1067
        {
1068 1069 1070
            await TestInClassAsync(
@"void M()
{
1071
    new C(s: [|Goo()|]);
1072 1073 1074
} C(int i, string s)
{
}", "global::System.String");
1075 1076
        }

J
Jared Parsons 已提交
1077
        [WorkItem(858112, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")]
1078
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1079
        public async Task TestThisConstructorInitializer1()
1080
        {
C
CyrusNajmabadi 已提交
1081 1082 1083 1084 1085 1086 1087
            await TestAsync(
@"class MyClass
{
    public MyClass(int x) : this([|test|])
    {
    }
}", "global::System.Int32");
1088 1089
        }

J
Jared Parsons 已提交
1090
        [WorkItem(858112, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")]
1091
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1092
        public async Task TestThisConstructorInitializer2()
1093
        {
C
CyrusNajmabadi 已提交
1094 1095 1096 1097 1098 1099 1100
            await TestAsync(
@"class MyClass
{
    public MyClass(int x, string y) : this(5, [|test|])
    {
    }
}", "global::System.String");
1101 1102
        }

J
Jared Parsons 已提交
1103
        [WorkItem(858112, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")]
1104
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1105
        public async Task TestBaseConstructorInitializer()
1106
        {
C
CyrusNajmabadi 已提交
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
            await TestAsync(
@"class B
{
    public B(int x)
    {
    }
}

class D : B
{
    public D() : base([|test|])
    {
    }
}", "global::System.Int32");
1121 1122
        }

1123
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1124
        public async Task TestIndexAccess1()
1125
        {
1126 1127 1128
            await TestInMethodAsync(
@"string[] i;

1129
i[[|Goo()|]];", "global::System.Int32");
1130 1131
        }

1132
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1133
        public async Task TestIndexerCall1()
1134
        {
1135
            await TestInMethodAsync(@"this[[|Goo()|]];", "global::System.Int32");
1136 1137
        }

1138
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1139
        public async Task TestIndexerCall2()
1140 1141
        {
            // Update this when binding of indexers is working.
1142 1143 1144
            await TestInClassAsync(
@"void M()
{
1145
    this[[|Goo()|]];
1146 1147 1148
}

int this[int i] { get; }", "global::System.Int32");
1149 1150
        }

1151
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1152
        public async Task TestIndexerCall3()
1153 1154
        {
            // Update this when binding of indexers is working.
1155 1156 1157
            await TestInClassAsync(
@"void M()
{
1158
    this[[|Goo()|]];
1159 1160 1161
}

int this[int i, string s] { get; }", "global::System.Int32");
1162 1163
        }

1164
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1165
        public async Task TestIndexerCall5()
1166
        {
1167 1168 1169
            await TestInClassAsync(
@"void M()
{
1170
    this[s: [|Goo()|]];
1171 1172 1173
}

int this[int i, string s] { get; }", "global::System.String");
1174 1175
        }

1176
        [Fact]
C
Cyrus Najmabadi 已提交
1177
        public async Task TestArrayInitializerInImplicitArrayCreationSimple()
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
       var a = new[] { 1, [|2|] };
  }
}";

C
CyrusNajmabadi 已提交
1190
            await TestAsync(text, "global::System.Int32");
1191 1192
        }

1193
        [Fact]
C
Cyrus Najmabadi 已提交
1194
        public async Task TestArrayInitializerInImplicitArrayCreation1()
1195 1196 1197 1198 1199 1200 1201 1202
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
1203
       var a = new[] { Bar(), [|Goo()|] };
1204 1205 1206
  }

  int Bar() { return 1; }
1207
  int Goo() { return 2; }
1208 1209
}";

C
CyrusNajmabadi 已提交
1210
            await TestAsync(text, "global::System.Int32");
1211 1212
        }

1213
        [Fact]
C
Cyrus Najmabadi 已提交
1214
        public async Task TestArrayInitializerInImplicitArrayCreation2()
1215 1216 1217 1218 1219 1220 1221 1222
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
1223
       var a = new[] { Bar(), [|Goo()|] };
1224 1225 1226 1227 1228
  }

  int Bar() { return 1; }
}";

C
CyrusNajmabadi 已提交
1229
            await TestAsync(text, "global::System.Int32");
1230 1231
        }

1232
        [Fact]
C
Cyrus Najmabadi 已提交
1233
        public async Task TestArrayInitializerInImplicitArrayCreation3()
1234 1235 1236 1237 1238 1239 1240 1241
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
1242
       var a = new[] { Bar(), [|Goo()|] };
1243 1244 1245
  }
}";

C
CyrusNajmabadi 已提交
1246
            await TestAsync(text, "global::System.Object");
1247 1248
        }

1249
        [Fact]
C
Cyrus Najmabadi 已提交
1250
        public async Task TestArrayInitializerInEqualsValueClauseSimple()
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
       int[] a = { 1, [|2|] };
  }
}";

C
CyrusNajmabadi 已提交
1263
            await TestAsync(text, "global::System.Int32");
1264 1265
        }

1266
        [Fact]
C
Cyrus Najmabadi 已提交
1267
        public async Task TestArrayInitializerInEqualsValueClause()
1268 1269 1270 1271 1272 1273 1274 1275
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
1276
       int[] a = { Bar(), [|Goo()|] };
1277 1278 1279 1280 1281
  }

  int Bar() { return 1; }
}";

C
CyrusNajmabadi 已提交
1282
            await TestAsync(text, "global::System.Int32");
1283 1284
        }

1285
        [Fact]
J
Jared Parsons 已提交
1286
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
1287
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1288
        public async Task TestCollectionInitializer1()
1289 1290 1291 1292 1293 1294 1295 1296
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
1297
    new List<int>() { [|Goo()|] };
1298 1299 1300
  }
}";

C
CyrusNajmabadi 已提交
1301
            await TestAsync(text, "global::System.Int32");
1302 1303
        }

1304
        [Fact]
J
Jared Parsons 已提交
1305
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
1306
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1307
        public async Task TestCollectionInitializer2()
1308 1309 1310 1311 1312 1313 1314 1315 1316
        {
            var text =
@"
using System.Collections.Generic;

class C
{
  void M()
  {
1317
    new Dictionary<int,string>() { { [|Goo()|], """" } };
1318 1319 1320
  }
}";

C
CyrusNajmabadi 已提交
1321
            await TestAsync(text, "global::System.Int32");
1322 1323
        }

1324
        [Fact]
J
Jared Parsons 已提交
1325
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
1326
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1327
        public async Task TestCollectionInitializer3()
1328 1329 1330 1331 1332 1333 1334 1335 1336
        {
            var text =
@"
using System.Collections.Generic;

class C
{
  void M()
  {
1337
    new Dictionary<int,string>() { { 0, [|Goo()|] } };
1338 1339 1340
  }
}";

C
CyrusNajmabadi 已提交
1341
            await TestAsync(text, "global::System.String");
1342 1343
        }

1344
        [Fact]
J
Jared Parsons 已提交
1345
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
1346
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1347
        public async Task TestCustomCollectionInitializerAddMethod1()
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
        {
            var text =
@"class C : System.Collections.IEnumerable
{
    void M()
    {
        var x = new C() { [|a|] };
    }

    void Add(int i) { }
    void Add(string s, bool b) { }

    public System.Collections.IEnumerator GetEnumerator()
    {
        throw new System.NotImplementedException();
    }
}";

C
CyrusNajmabadi 已提交
1366
            await TestAsync(text, "global::System.Int32", testPosition: false);
1367 1368
        }

1369
        [Fact]
J
Jared Parsons 已提交
1370
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
1371
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1372
        public async Task TestCustomCollectionInitializerAddMethod2()
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
        {
            var text =
@"class C : System.Collections.IEnumerable
{
    void M()
    {
        var x = new C() { { ""test"", [|b|] } };
    }

    void Add(int i) { }
    void Add(string s, bool b) { }

    public System.Collections.IEnumerator GetEnumerator()
    {
        throw new System.NotImplementedException();
    }
}";

C
CyrusNajmabadi 已提交
1391
            await TestAsync(text, "global::System.Boolean");
1392 1393
        }

1394
        [Fact]
J
Jared Parsons 已提交
1395
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
1396
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1397
        public async Task TestCustomCollectionInitializerAddMethod3()
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
        {
            var text =
@"class C : System.Collections.IEnumerable
{
    void M()
    {
        var x = new C() { { [|s|], true } };
    }

    void Add(int i) { }
    void Add(string s, bool b) { }

    public System.Collections.IEnumerator GetEnumerator()
    {
        throw new System.NotImplementedException();
    }
}";

C
CyrusNajmabadi 已提交
1416
            await TestAsync(text, "global::System.String");
1417 1418
        }

1419
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1420
        public async Task TestArrayInference1()
1421 1422 1423 1424 1425
        {
            var text =
@"
class A
{
1426
    void Goo()
1427 1428 1429 1430 1431
    {
        A[] x = new [|C|][] { };
    }
}";

C
Cyrus Najmabadi 已提交
1432
            await TestAsync(text, "global::A", testPosition: false);
1433 1434
        }

1435
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1436
        public async Task TestArrayInference1_Position()
1437 1438 1439 1440 1441
        {
            var text =
@"
class A
{
1442
    void Goo()
1443 1444 1445 1446 1447
    {
        A[] x = new [|C|][] { };
    }
}";

C
Cyrus Najmabadi 已提交
1448
            await TestAsync(text, "global::A[]", testNode: false);
1449 1450
        }

1451
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1452
        public async Task TestArrayInference2()
1453 1454 1455 1456 1457
        {
            var text =
@"
class A
{
1458
    void Goo()
1459 1460 1461 1462 1463
    {
        A[][] x = new [|C|][][] { };
    }
}";

C
Cyrus Najmabadi 已提交
1464
            await TestAsync(text, "global::A", testPosition: false);
1465 1466
        }

1467
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1468
        public async Task TestArrayInference2_Position()
1469 1470 1471 1472 1473
        {
            var text =
@"
class A
{
1474
    void Goo()
1475 1476 1477 1478 1479
    {
        A[][] x = new [|C|][][] { };
    }
}";

C
Cyrus Najmabadi 已提交
1480
            await TestAsync(text, "global::A[][]", testNode: false);
1481 1482
        }

1483
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1484
        public async Task TestArrayInference3()
1485 1486 1487 1488 1489
        {
            var text =
@"
class A
{
1490
    void Goo()
1491 1492 1493 1494 1495
    {
        A[][] x = new [|C|][] { };
    }
}";

C
Cyrus Najmabadi 已提交
1496
            await TestAsync(text, "global::A[]", testPosition: false);
1497 1498
        }

1499
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1500
        public async Task TestArrayInference3_Position()
1501 1502 1503 1504 1505
        {
            var text =
@"
class A
{
1506
    void Goo()
1507 1508 1509 1510 1511
    {
        A[][] x = new [|C|][] { };
    }
}";

C
Cyrus Najmabadi 已提交
1512
            await TestAsync(text, "global::A[][]", testNode: false);
1513 1514
        }

1515
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1516
        public async Task TestArrayInference4()
1517 1518 1519 1520 1521 1522
        {
            var text =
@"
using System;
class A
{
1523
    void Goo()
1524 1525 1526 1527 1528
    {
        Func<int, int>[] x = new Func<int, int>[] { [|Bar()|] };
    }
}";

C
Cyrus Najmabadi 已提交
1529
            await TestAsync(text, "global::System.Func<global::System.Int32, global::System.Int32>");
1530 1531
        }

J
Jared Parsons 已提交
1532
        [WorkItem(538993, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538993")]
1533
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1534
        public async Task TestInsideLambda2()
1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
        {
            var text =
@"using System;
class C
{
  void M()
  {
    Func<int,int> f = i => [|here|]
  }
}";

C
CyrusNajmabadi 已提交
1546
            await TestAsync(text, "global::System.Int32");
1547 1548
        }

J
Jared Parsons 已提交
1549
        [WorkItem(539813, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539813")]
1550
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1551
        public async Task TestPointer1()
1552 1553 1554 1555 1556 1557
        {
            var text =
@"class C
{
  void M(int* i)
  {
1558
    var q = i[[|Goo()|]];
1559 1560 1561
  }
}";

C
CyrusNajmabadi 已提交
1562
            await TestAsync(text, "global::System.Int32");
1563 1564
        }

J
Jared Parsons 已提交
1565
        [WorkItem(539813, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539813")]
1566
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1567
        public async Task TestDynamic1()
1568 1569 1570 1571 1572 1573
        {
            var text =
@"class C
{
  void M(dynamic i)
  {
1574
    var q = i[[|Goo()|]];
1575 1576 1577
  }
}";

C
CyrusNajmabadi 已提交
1578
            await TestAsync(text, "global::System.Int32");
1579 1580
        }

1581
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1582
        public async Task TestChecked1()
1583 1584 1585 1586 1587 1588
        {
            var text =
@"class C
{
  void M()
  {
1589
    string q = checked([|Goo()|]);
1590 1591 1592
  }
}";

C
CyrusNajmabadi 已提交
1593
            await TestAsync(text, "global::System.String");
1594 1595
        }

1596
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1597
        [WorkItem(553584, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/553584")]
C
Cyrus Najmabadi 已提交
1598
        public async Task TestAwaitTaskOfT()
1599 1600 1601 1602 1603 1604 1605
        {
            var text =
@"using System.Threading.Tasks;
class C
{
  void M()
  {
1606
    int x = await [|Goo()|];
1607 1608 1609
  }
}";

C
CyrusNajmabadi 已提交
1610
            await TestAsync(text, "global::System.Threading.Tasks.Task<global::System.Int32>");
1611 1612
        }

1613
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1614
        [WorkItem(553584, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/553584")]
C
Cyrus Najmabadi 已提交
1615
        public async Task TestAwaitTaskOfTaskOfT()
1616 1617 1618 1619 1620 1621 1622
        {
            var text =
@"using System.Threading.Tasks;
class C
{
  void M()
  {
1623
    Task<int> x = await [|Goo()|];
1624 1625 1626
  }
}";

C
CyrusNajmabadi 已提交
1627
            await TestAsync(text, "global::System.Threading.Tasks.Task<global::System.Threading.Tasks.Task<global::System.Int32>>");
1628 1629
        }

1630
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1631
        [WorkItem(553584, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/553584")]
C
Cyrus Najmabadi 已提交
1632
        public async Task TestAwaitTask()
1633 1634 1635 1636 1637 1638 1639
        {
            var text =
@"using System.Threading.Tasks;
class C
{
  void M()
  {
1640
    await [|Goo()|];
1641 1642 1643
  }
}";

C
Cyrus Najmabadi 已提交
1644
            await TestAsync(text, "global::System.Threading.Tasks.Task");
1645 1646
        }

1647
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1648
        [WorkItem(617622, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617622")]
C
Cyrus Najmabadi 已提交
1649
        public async Task TestLockStatement()
1650 1651 1652 1653 1654 1655
        {
            var text =
@"class C
{
  void M()
  {
1656
    lock([|Goo()|])
1657 1658 1659 1660 1661
    {
    }
  }
}";

C
CyrusNajmabadi 已提交
1662
            await TestAsync(text, "global::System.Object");
1663 1664
        }

1665
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1666
        [WorkItem(617622, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617622")]
C
Cyrus Najmabadi 已提交
1667
        public async Task TestAwaitExpressionInLockStatement()
1668 1669 1670 1671 1672 1673
        {
            var text =
@"class C
{
  async void M()
  {
1674
    lock(await [|Goo()|])
1675 1676 1677 1678 1679
    {
    }
  }
}";

C
CyrusNajmabadi 已提交
1680
            await TestAsync(text, "global::System.Threading.Tasks.Task<global::System.Object>");
1681 1682
        }

1683
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1684
        [WorkItem(827897, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/827897")]
C
Cyrus Najmabadi 已提交
1685
        public async Task TestReturnFromAsyncTaskOfT()
1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
        {
            var markup =
@"using System.Threading.Tasks;
class Program
{
    async Task<int> M()
    {
        await Task.Delay(1);
        return [|ab|]
    }
}";
C
CyrusNajmabadi 已提交
1697
            await TestAsync(markup, "global::System.Int32");
1698 1699
        }

1700
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1701
        [WorkItem(853840, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/853840")]
C
Cyrus Najmabadi 已提交
1702
        public async Task TestAttributeArguments1()
1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715
        {
            var markup =
@"[A([|dd|], ee, Y = ff)]
class AAttribute : System.Attribute
{
    public int X;
    public string Y;

    public AAttribute(System.DayOfWeek a, double b)
    {

    }
}";
C
Cyrus Najmabadi 已提交
1716
            await TestAsync(markup, "global::System.DayOfWeek");
1717 1718
        }

1719
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1720
        [WorkItem(853840, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/853840")]
C
Cyrus Najmabadi 已提交
1721
        public async Task TestAttributeArguments2()
1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
        {
            var markup =
@"[A(dd, [|ee|], Y = ff)]
class AAttribute : System.Attribute
{
    public int X;
    public string Y;

    public AAttribute(System.DayOfWeek a, double b)
    {

    }
}";
C
CyrusNajmabadi 已提交
1735
            await TestAsync(markup, "global::System.Double");
1736 1737
        }

1738
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1739
        [WorkItem(853840, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/853840")]
C
Cyrus Najmabadi 已提交
1740
        public async Task TestAttributeArguments3()
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753
        {
            var markup =
@"[A(dd, ee, Y = [|ff|])]
class AAttribute : System.Attribute
{
    public int X;
    public string Y;

    public AAttribute(System.DayOfWeek a, double b)
    {

    }
}";
C
CyrusNajmabadi 已提交
1754
            await TestAsync(markup, "global::System.String");
1755 1756
        }

1757
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1758
        [WorkItem(757111, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/757111")]
C
Cyrus Najmabadi 已提交
1759
        public async Task TestReturnStatementWithinDelegateWithinAMethodCall()
1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777
        {
            var text =
@"using System;

class Program
{
    delegate string A(int i);

    static void Main(string[] args)
    {
        B(delegate(int i) { return [|M()|]; });
    }

    private static void B(A a)
    {
    }
}";

C
CyrusNajmabadi 已提交
1778
            await TestAsync(text, "global::System.String");
1779 1780
        }

1781
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1782
        [WorkItem(994388, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994388")]
C
Cyrus Najmabadi 已提交
1783
        public async Task TestCatchFilterClause()
1784 1785 1786 1787 1788 1789 1790
        {
            var text =
@"
try
{ }
catch (Exception) if ([|M()|])
}";
C
CyrusNajmabadi 已提交
1791
            await TestInMethodAsync(text, "global::System.Boolean");
1792 1793
        }

1794
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1795
        [WorkItem(994388, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994388")]
C
Cyrus Najmabadi 已提交
1796
        public async Task TestCatchFilterClause1()
1797 1798 1799 1800 1801 1802 1803
        {
            var text =
@"
try
{ }
catch (Exception) if ([|M|])
}";
C
CyrusNajmabadi 已提交
1804
            await TestInMethodAsync(text, "global::System.Boolean");
1805 1806
        }

1807
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
1808
        [WorkItem(994388, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994388")]
C
Cyrus Najmabadi 已提交
1809
        public async Task TestCatchFilterClause2()
1810 1811 1812 1813 1814 1815 1816
        {
            var text =
@"
try
{ }
catch (Exception) if ([|M|].N)
}";
C
CyrusNajmabadi 已提交
1817
            await TestInMethodAsync(text, "global::System.Object", testPosition: false);
1818
        }
J
Jonathon Marolf 已提交
1819

1820
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jonathon Marolf 已提交
1821
        [WorkItem(643, "https://github.com/dotnet/roslyn/issues/643")]
C
Cyrus Najmabadi 已提交
1822
        public async Task TestAwaitExpressionWithChainingMethod()
J
Jonathon Marolf 已提交
1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
        {
            var text =
@"using System;
using System.Threading.Tasks;

class C
{
    static async void T()
    {
        bool x = await [|M()|].ConfigureAwait(false);
    }
}";
C
CyrusNajmabadi 已提交
1835
            await TestAsync(text, "global::System.Threading.Tasks.Task<global::System.Boolean>", testPosition: false);
J
Jonathon Marolf 已提交
1836 1837
        }

1838
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jonathon Marolf 已提交
1839
        [WorkItem(643, "https://github.com/dotnet/roslyn/issues/643")]
C
Cyrus Najmabadi 已提交
1840
        public async Task TestAwaitExpressionWithChainingMethod2()
J
Jonathon Marolf 已提交
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
        {
            var text =
@"using System;
using System.Threading.Tasks;

class C
{
    static async void T()
    {
        bool x = await [|M|].ContinueWith(a => { return true; }).ContinueWith(a => { return false; });
    }
}";
C
CyrusNajmabadi 已提交
1853
            await TestAsync(text, "global::System.Threading.Tasks.Task<global::System.Object>", testPosition: false);
J
Jonathon Marolf 已提交
1854
        }
1855

1856
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1857
        [WorkItem(4233, "https://github.com/dotnet/roslyn/issues/4233")]
C
Cyrus Najmabadi 已提交
1858
        public async Task TestAwaitExpressionWithGenericMethod1()
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871
        {
            var text =
@"using System.Threading.Tasks;

public class C
{
    private async void M()
    {
        bool merged = await X([|Test()|]);
    }

    private async Task<T> X<T>(T t) { return t; }
}";
C
CyrusNajmabadi 已提交
1872
            await TestAsync(text, "global::System.Boolean", testPosition: false);
1873 1874
        }

1875
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1876
        [WorkItem(4233, "https://github.com/dotnet/roslyn/issues/4233")]
C
Cyrus Najmabadi 已提交
1877
        public async Task TestAwaitExpressionWithGenericMethod2()
1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890
        {
            var text =
@"using System.Threading.Tasks;

public class C
{
    private async void M()
    {
        bool merged = await Task.Run(() => [|Test()|]);;
    }

    private async Task<T> X<T>(T t) { return t; }
}";
C
CyrusNajmabadi 已提交
1891
            await TestAsync(text, "global::System.Boolean");
1892
        }
1893

1894
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1895
        [WorkItem(4483, "https://github.com/dotnet/roslyn/issues/4483")]
C
Cyrus Najmabadi 已提交
1896
        public async Task TestNullCoalescingOperator1()
1897 1898 1899 1900 1901 1902 1903 1904 1905
        {
            var text =
    @"class C
{
    void M()
    {
        object z = [|a|]?? null;
    }
}";
C
CyrusNajmabadi 已提交
1906
            await TestAsync(text, "global::System.Object");
1907 1908
        }

1909
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1910
        [WorkItem(4483, "https://github.com/dotnet/roslyn/issues/4483")]
C
Cyrus Najmabadi 已提交
1911
        public async Task TestNullCoalescingOperator2()
1912 1913 1914 1915 1916 1917 1918 1919 1920
        {
            var text =
    @"class C
{
    void M()
    {
        object z = [|a|] ?? b ?? c;
    }
}";
C
CyrusNajmabadi 已提交
1921
            await TestAsync(text, "global::System.Object");
1922 1923
        }

1924
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1925
        [WorkItem(4483, "https://github.com/dotnet/roslyn/issues/4483")]
C
Cyrus Najmabadi 已提交
1926
        public async Task TestNullCoalescingOperator3()
1927 1928 1929 1930 1931 1932 1933 1934 1935
        {
            var text =
    @"class C
{
    void M()
    {
        object z = a ?? [|b|] ?? c;
    }
}";
C
CyrusNajmabadi 已提交
1936
            await TestAsync(text, "global::System.Object");
1937
        }
J
Jonathon Marolf 已提交
1938

1939
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jonathon Marolf 已提交
1940
        [WorkItem(5126, "https://github.com/dotnet/roslyn/issues/5126")]
C
Cyrus Najmabadi 已提交
1941
        public async Task TestSelectLambda()
J
Jonathon Marolf 已提交
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
        {
            var text =
    @"using System.Collections.Generic;
using System.Linq;

class C
{
    void M(IEnumerable<string> args)
    {
        args = args.Select(a =>[||])
    }
}";
C
CyrusNajmabadi 已提交
1954
            await TestAsync(text, "global::System.Object", testPosition: false);
J
Jonathon Marolf 已提交
1955 1956
        }

1957
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jonathon Marolf 已提交
1958
        [WorkItem(5126, "https://github.com/dotnet/roslyn/issues/5126")]
C
Cyrus Najmabadi 已提交
1959
        public async Task TestSelectLambda2()
J
Jonathon Marolf 已提交
1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
        {
            var text =
    @"using System.Collections.Generic;
using System.Linq;

class C
{
    void M(IEnumerable<string> args)
    {
        args = args.Select(a =>[|b|])
    }
}";
C
CyrusNajmabadi 已提交
1972
            await TestAsync(text, "global::System.String", testPosition: false);
1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        [WorkItem(1903, "https://github.com/dotnet/roslyn/issues/1903")]
        public async Task TestSelectLambda3()
        {
            var text =
@"using System.Collections.Generic;
using System.Linq;

class A { }
class B { }
class C
{
    IEnumerable<B> GetB(IEnumerable<A> a)
    {
1989
        return a.Select(i => [|Goo(i)|]);
1990 1991 1992
    }
}";
            await TestAsync(text, "global::B");
J
Jonathon Marolf 已提交
1993
        }
1994

R
Ravi Chande 已提交
1995 1996
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        [WorkItem(6765, "https://github.com/dotnet/roslyn/issues/6765")]
A
Andy Gocke 已提交
1997
        public async Task TestDefaultStatement1()
R
Ravi Chande 已提交
1998 1999 2000 2001 2002 2003 2004 2005 2006
        {
            var text =
    @"class C
{
    static void Main(string[] args)
    {
        System.ConsoleModifiers c = default([||])
    }
}";
2007
            await TestAsync(text, "global::System.ConsoleModifiers", testNode: false);
R
Ravi Chande 已提交
2008 2009 2010 2011
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        [WorkItem(6765, "https://github.com/dotnet/roslyn/issues/6765")]
A
Andy Gocke 已提交
2012
        public async Task TestDefaultStatement2()
R
Ravi Chande 已提交
2013 2014 2015 2016
        {
            var text =
    @"class C
{
2017
    static void Goo(System.ConsoleModifiers arg)
R
Ravi Chande 已提交
2018
    {
2019
        Goo(default([||])
R
Ravi Chande 已提交
2020 2021
    }
}";
A
Andy Gocke 已提交
2022
            await TestAsync(text, "global::System.ConsoleModifiers", testNode: false);
R
Ravi Chande 已提交
2023
        }
2024 2025 2026 2027 2028 2029 2030 2031 2032

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestWhereCall()
        {
            var text =
    @"
using System.Collections.Generic;
class C
{
2033
    void Goo()
2034 2035 2036 2037
    {
        [|ints|].Where(i => i > 10);
    }
}";
C
CyrusNajmabadi 已提交
2038
            await TestAsync(text, "global::System.Collections.Generic.IEnumerable<global::System.Int32>", testPosition: false);
2039 2040 2041 2042 2043 2044 2045 2046 2047 2048
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestWhereCall2()
        {
            var text =
    @"
using System.Collections.Generic;
class C
{
2049
    void Goo()
2050 2051 2052 2053
    {
        [|ints|].Where(i => null);
    }
}";
C
CyrusNajmabadi 已提交
2054
            await TestAsync(text, "global::System.Collections.Generic.IEnumerable<global::System.Object>", testPosition: false);
2055
        }
R
Ravi Chande 已提交
2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074

        [WorkItem(12755, "https://github.com/dotnet/roslyn/issues/12755")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestObjectCreationBeforeArrayIndexing()
        {
            var text =
@"using System;
class C
{
  void M()
  {
        int[] array;
        C p = new [||]
        array[4] = 4;
  }
}";

            await TestAsync(text, "global::C", testNode: false);
        }
2075 2076

        [WorkItem(15468, "https://github.com/dotnet/roslyn/issues/15468")]
C
Cyrus Najmabadi 已提交
2077
        [WorkItem(25305, "https://github.com/dotnet/roslyn/issues/25305")]
2078 2079 2080 2081
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestDeconstruction()
        {
            await TestInMethodAsync(
C
Cyrus Najmabadi 已提交
2082 2083 2084 2085 2086 2087 2088 2089 2090 2091
@"[|(int i, _)|] =", "(global::System.Int32 i, global::System.Object _)", testPosition: false);
        }

        [WorkItem(15468, "https://github.com/dotnet/roslyn/issues/15468")]
        [WorkItem(25305, "https://github.com/dotnet/roslyn/issues/25305")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestDeconstruction2()
        {
            await TestInMethodAsync(
@"(int i, _) =  [||]", "(global::System.Int32 i, global::System.Object _)", testNode: false);
2092
        }
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109

        [WorkItem(13402, "https://github.com/dotnet/roslyn/issues/13402")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestObjectCreationBeforeBlock()
        {
            var text =
@"class Program
{
    static void Main(string[] args)
    {
        Program p = new [||] 
        { }
    }
}";

            await TestAsync(text, "global::Program", testNode: false);
        }
2110
    }
S
Sam Harwell 已提交
2111
}