TypeInferrerTests.cs 83.3 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 114 115 116 117 118 119 120
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestVariableDeclaratorNullableReferenceType()
        {
            await TestInMethodAsync(
@"#nullable enable
string? q = [|Goo()|];", "global::System.String?");
        }

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

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

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

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

151 152 153 154 155 156 157 158 159 160 161
        // This is skipped for now. This is a case where we know we can unilaterally mark the reference type as nullable, as long as the user has #nullable enable on.
        // But right now there's no compiler API to know if it is, so we have to skip this. Once there is an API, we'll have it always return a nullable reference type
        // and we'll remove the ? if it's in a non-nullable context no differently than we always generate types fully qualified and then clean up based on context.
        [Fact(Skip = "https://github.com/dotnet/roslyn/issues/36101"), Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestCoalesceInNullableEnabled()
        {
            await TestInMethodAsync(
@"#nullable enable
var q = [|Goo()|] ?? string.Empty;", "global::System.String?", testPosition: false);
        }

162
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
163
        public async Task TestBinaryExpression1()
164
        {
165 166
            await TestInMethodAsync(
@"string s;
167
var q = s + [|Goo()|];", "global::System.String");
168 169
        }

170
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
171
        public async Task TestBinaryExpression2()
172
        {
173 174
            await TestInMethodAsync(
@"var s;
175
var q = s || [|Goo()|];", "global::System.Boolean");
176 177
        }

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

185
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
186
        public async Task TestBinaryOperator2()
187
        {
188
            await TestInMethodAsync(
189
@"var q = x >> [|Goo()|];", "global::System.Int32");
190 191
        }

192
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
193
        public async Task TestAssignmentOperator3()
194
        {
195
            await TestInMethodAsync(
196
@"var q <<= [|Goo()|];", "global::System.Int32");
197 198
        }

199
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
200
        public async Task TestAssignmentOperator4()
201
        {
202
            await TestInMethodAsync(
203
@"var q >>= [|Goo()|];", "global::System.Int32");
204 205
        }

206
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
207
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
208
        public async Task TestOverloadedConditionalLogicalOperatorsInferBool()
209
        {
C
CyrusNajmabadi 已提交
210 211 212
            await TestAsync(
@"using System;

213 214
class C
{
C
CyrusNajmabadi 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228
    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;
    }
229 230 231

    static void Main(string[] args)
    {
232
        var c = new C() && [|Goo()|];
233
    }
C
CyrusNajmabadi 已提交
234
}", "global::System.Boolean");
235 236
        }

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

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

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

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

297
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
298
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
299
        public async Task TestLogicalOrOperatorInference3()
300 301 302 303 304 305 306 307 308
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = a | b | [|c|] || d;
    }
}";
C
CyrusNajmabadi 已提交
309
            await TestAsync(text, "global::System.Boolean");
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 TestLogicalOrOperatorInference4()
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(Program p)
324 325 326 327
    {
        return p;
    }
}";
C
Cyrus Najmabadi 已提交
328
            await TestAsync(text, "Program", testPosition: false);
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 TestLogicalOrOperatorInference5()
334 335 336 337 338 339
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
340
        var x = Goo([|a|] | b);
341
    }
342
    static object Goo(bool p)
343 344 345 346
    {
        return p;
    }
}";
C
CyrusNajmabadi 已提交
347
            await TestAsync(text, "global::System.Boolean");
348 349
        }

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

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

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

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

410
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
411
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
412
        public async Task TestLogicalAndOperatorInference3()
413 414 415 416 417 418 419 420 421
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = a & b & [|c|] && d;
    }
}";
C
CyrusNajmabadi 已提交
422
            await TestAsync(text, "global::System.Boolean");
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 TestLogicalAndOperatorInference4()
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(Program p)
437 438 439 440
    {
        return p;
    }
}";
C
Cyrus Najmabadi 已提交
441
            await TestAsync(text, "Program", testPosition: false);
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 TestLogicalAndOperatorInference5()
447 448 449 450 451 452
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
453
        var x = Goo([|a|] & b);
454
    }
455
    static object Goo(bool p)
456 457 458 459
    {
        return p;
    }
}";
C
CyrusNajmabadi 已提交
460
            await TestAsync(text, "global::System.Boolean");
461 462
        }

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

478
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
479
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
480
        public async Task TestLogicalAndOperatorInference7()
481 482 483 484 485 486 487 488 489
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        if ([|x|] & y) {}
    }
}";
C
CyrusNajmabadi 已提交
490
            await TestAsync(text, "global::System.Boolean");
491 492
        }

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

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

523
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
524
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
525
        public async Task TestLogicalXorOperatorInference3()
526 527 528 529 530 531 532 533 534
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        var x = a ^ b ^ [|c|] && d;
    }
}";
C
CyrusNajmabadi 已提交
535
            await TestAsync(text, "global::System.Boolean");
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 TestLogicalXorOperatorInference4()
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(Program p)
550 551 552 553
    {
        return p;
    }
}";
C
Cyrus Najmabadi 已提交
554
            await TestAsync(text, "Program", testPosition: false);
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 TestLogicalXorOperatorInference5()
560 561 562 563 564 565
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
566
        var x = Goo([|a|] ^ b);
567
    }
568
    static object Goo(bool p)
569 570 571 572
    {
        return p;
    }
}";
C
CyrusNajmabadi 已提交
573
            await TestAsync(text, "global::System.Boolean");
574 575
        }

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

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

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

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

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

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

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

681
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
682
        [WorkItem(617633, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")]
C
Cyrus Najmabadi 已提交
683
        public async Task TestLogicalXorEqualsOperatorInference2()
684 685 686 687 688 689 690 691 692
        {
            var text = @"using System;
class C
{
    static void Main(string[] args)
    {
        int z = [|x|] ^= y;
    }
}";
C
CyrusNajmabadi 已提交
693
            await TestAsync(text, "global::System.Int32");
694 695
        }

Š
Šimon Koníček 已提交
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInConstructor()
        {
            await TestInClassAsync(
@"C()
{
    return [|Goo()|];
}", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInDestructor()
        {
            await TestInClassAsync(
@"~C()
{
    return [|Goo()|];
}", "void");
        }

716
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
717
        public async Task TestReturnInMethod()
718
        {
719 720 721
            await TestInClassAsync(
@"int M()
{
722
    return [|Goo()|];
723
}", "global::System.Int32");
724 725
        }

726 727 728 729 730 731 732 733 734 735 736
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInMethodNullableReference()
        {
            await TestInClassAsync(
@"#nullable enable
string? M()
{
    return [|Goo()|];
}", "global::System.String?");
        }

737
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
738 739 740 741 742 743 744 745 746 747 748
        public async Task TestReturnInVoidMethod()
        {
            await TestInClassAsync(
@"void M()
{
    return [|Goo()|];
}", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncTaskOfTMethod()
749 750 751 752 753 754 755 756
        {
            await TestInClassAsync(
@"async System.Threading.Tasks.Task<int> M()
{
    return [|Goo()|];
}", "global::System.Int32");
        }

757 758 759 760 761 762 763 764 765 766
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncTaskOfTMethodNestedNullability()
        {
            await TestInClassAsync(
@"async System.Threading.Tasks.Task<string?> M()
{
    return [|Goo()|];
}", "global::System.String?");
        }

767
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
768
        public async Task TestReturnInAsyncTaskMethod()
769
        {
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
            await TestInClassAsync(
@"async System.Threading.Tasks.Task M()
{
    return [|Goo()|];
}", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncVoidMethod()
        {
            await TestInClassAsync(
@"async void M()
{
    return [|Goo()|];
}", "void");
785 786
        }

787
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
Š
Šimon Koníček 已提交
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
        public async Task TestReturnInOperator()
        {
            await TestInClassAsync(
@"public static C operator ++(C c)
{
    return [|Goo()|];
}", "global::C");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInConversionOperator()
        {
            await TestInClassAsync(
@"public static implicit operator int(C c)
{
    return [|Goo()|];
}", "global::System.Int32");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInPropertyGetter()
809
        {
810
            await TestInClassAsync(
Š
Šimon Koníček 已提交
811
@"int P
812 813 814
{
    get
    {
815
        return [|Goo()|];
816 817
    }
}", "global::System.Int32");
818 819
        }

820 821 822 823 824 825 826 827 828 829 830 831 832 833
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInPropertyGetterNullableReference()
        {
            await TestInClassAsync(
@"#nullable enable
string? P
{
    get
    {
        return [|Goo()|];
    }
}", "global::System.String?");
        }

Š
Šimon Koníček 已提交
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInPropertySetter()
        {
            await TestInClassAsync(
@"int P
{
    set
    {
        return [|Goo()|];
    }
}", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInIndexerGetter()
        {
            await TestInClassAsync(
@"int this[int i]
{
    get
    {
        return [|Goo()|];
    }
}", "global::System.Int32");
        }

860 861 862 863 864 865 866 867 868 869 870 871 872 873
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInIndexerGetterNullableReference()
        {
            await TestInClassAsync(
@"#nullable enable
string? this[int i]
{
    get
    {
        return [|Goo()|];
    }
}", "global::System.String?");
        }

Š
Šimon Koníček 已提交
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInIndexerSetter()
        {
            await TestInClassAsync(
@"int this[int i]
{
    set
    {
        return [|Goo()|];
    }
}", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInEventAdder()
        {
            await TestInClassAsync(
@"event System.EventHandler E
{
    add
    {
        return [|Goo()|];
    }
    remove { }
}", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInEventRemover()
        {
            await TestInClassAsync(
@"event System.EventHandler E
{
    add { }
    remove
    {
        return [|Goo()|];
    }
}", "void");
        }

915 916 917 918 919 920 921 922 923 924 925 926 927
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInLocalFunction()
        {
            await TestInClassAsync(
@"void M()
{
    int F()
    {
        return [|Goo()|];
    }
}", "global::System.Int32");
        }

928 929 930 931 932 933 934 935 936 937 938 939 940 941
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInLocalFunctionNullableReference()
        {
            await TestInClassAsync(
@"#nullable enable
void M()
{
    string? F()
    {
        return [|Goo()|];
    }
}", "global::System.String?");
        }

942
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
943
        public async Task TestReturnInAsyncTaskOfTLocalFunction()
944 945 946 947 948 949 950 951 952 953 954
        {
            await TestInClassAsync(
@"void M()
{
    async System.Threading.Tasks.Task<int> F()
    {
        return [|Goo()|];
    }
}", "global::System.Int32");
        }

955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncTaskLocalFunction()
        {
            await TestInClassAsync(
@"void M()
{
    async System.Threading.Tasks.Task F()
    {
        return [|Goo()|];
    }
}", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncVoidLocalFunction()
        {
            await TestInClassAsync(
@"void M()
{
    async void F()
    {
        return [|Goo()|];
    }
}", "void");
        }

981 982 983 984 985 986 987
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedConstructor()
        {
            await TestInClassAsync(
@"C() => [|Goo()|];", "void");
        }

Š
Šimon Koníček 已提交
988 989 990 991 992 993 994
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedDestructor()
        {
            await TestInClassAsync(
@"~C() => [|Goo()|];", "void");
        }

995 996 997 998 999 1000 1001
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedMethod()
        {
            await TestInClassAsync(
@"int M() => [|Goo()|];", "global::System.Int32");
        }

1002 1003 1004 1005 1006 1007 1008
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedVoidMethod()
        {
            await TestInClassAsync(
@"void M() => [|Goo()|];", "void");
        }

1009 1010
        [WorkItem(27647, "https://github.com/dotnet/roslyn/issues/27647")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1011
        public async Task TestExpressionBodiedAsyncTaskOfTMethod()
1012 1013 1014 1015 1016
        {
            await TestInClassAsync(
@"async System.Threading.Tasks.Task<int> M() => [|Goo()|];", "global::System.Int32");
        }

1017 1018 1019 1020 1021 1022 1023 1024 1025
        [WorkItem(27647, "https://github.com/dotnet/roslyn/issues/27647")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedAsyncTaskOfTMethodNullableReference()
        {
            await TestInClassAsync(
@"#nullable enable
async System.Threading.Tasks.Task<string?> M() => [|Goo()|];", "global::System.String?");
        }

1026
        [WorkItem(27647, "https://github.com/dotnet/roslyn/issues/27647")]
1027
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1028
        public async Task TestExpressionBodiedAsyncTaskMethod()
1029 1030
        {
            await TestInClassAsync(
1031 1032 1033 1034 1035 1036 1037 1038
@"async System.Threading.Tasks.Task M() => [|Goo()|];", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedAsyncVoidMethod()
        {
            await TestInClassAsync(
@"async void M() => [|Goo()|];", "void");
1039 1040
        }

Š
Šimon Koníček 已提交
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedOperator()
        {
            await TestInClassAsync(
@"public static C operator ++(C c) => [|Goo()|];", "global::C");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedConversionOperator()
        {
            await TestInClassAsync(
@"public static implicit operator int(C c) => [|Goo()|];", "global::System.Int32");
        }

1055 1056 1057 1058 1059 1060 1061
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedProperty()
        {
            await TestInClassAsync(
@"int P => [|Goo()|];", "global::System.Int32");
        }

Š
Šimon Koníček 已提交
1062 1063 1064 1065 1066 1067 1068
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedIndexer()
        {
            await TestInClassAsync(
@"int this[int i] => [|Goo()|];", "global::System.Int32");
        }

1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedPropertyGetter()
        {
            await TestInClassAsync(
@"int P { get => [|Goo()|]; }", "global::System.Int32");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedPropertySetter()
        {
            await TestInClassAsync(
@"int P { set => [|Goo()|]; }", "void");
        }

Š
Šimon Koníček 已提交
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedIndexerGetter()
        {
            await TestInClassAsync(
@"int this[int i] { get => [|Goo()|]; }", "global::System.Int32");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedIndexerSetter()
        {
            await TestInClassAsync(
@"int this[int i] { set => [|Goo()|]; }", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedEventAdder()
        {
            await TestInClassAsync(
@"event System.EventHandler E { add => [|Goo()|]; remove { } }", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedEventRemover()
        {
            await TestInClassAsync(
@"event System.EventHandler E { add { } remove => [|Goo()|]; }", "void");
        }

1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedLocalFunction()
        {
            await TestInClassAsync(
@"void M()
{
    int F() => [|Goo()|];
}", "global::System.Int32");
        }

        [WorkItem(27647, "https://github.com/dotnet/roslyn/issues/27647")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1123
        public async Task TestExpressionBodiedAsyncTaskOfTLocalFunction()
1124 1125 1126 1127 1128 1129 1130 1131
        {
            await TestInClassAsync(
@"void M()
{
    async System.Threading.Tasks.Task<int> F() => [|Goo()|];
}", "global::System.Int32");
        }

1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
        [WorkItem(27647, "https://github.com/dotnet/roslyn/issues/27647")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedAsyncTaskLocalFunction()
        {
            await TestInClassAsync(
@"void M()
{
    async System.Threading.Tasks.Task F() => [|Goo()|];
}", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestExpressionBodiedAsyncVoidLocalFunction()
        {
            await TestInClassAsync(
@"void M()
{
    async void F() => [|Goo()|];
}", "void");
        }

J
Jared Parsons 已提交
1153
        [WorkItem(827897, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/827897")]
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
        [Theory, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        [InlineData("IEnumerable")]
        [InlineData("IEnumerator")]
        [InlineData("InvalidGenericType")]
        public async Task TestYieldReturnInMethod(string returnTypeName)
        {
            var markup =
$@"using System.Collections.Generic;

class C
{{
    {returnTypeName}<int> M()
    {{
        yield return [|abc|]
    }}
}}";
            await TestAsync(markup, "global::System.Int32");
        }

1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
        [Theory, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        [InlineData("IEnumerable")]
        [InlineData("IEnumerator")]
        [InlineData("InvalidGenericType")]
        public async Task TestYieldReturnInMethodNullableReference(string returnTypeName)
        {
            var markup =
$@"#nullable enable
using System.Collections.Generic;

class C
{{
    {returnTypeName}<string?> M()
    {{
        yield return [|abc|]
    }}
}}";
            await TestAsync(markup, "global::System.String?");
        }

1193 1194 1195 1196 1197 1198 1199 1200 1201
        [Theory, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        [InlineData("IAsyncEnumerable")]
        [InlineData("IAsyncEnumerator")]
        [InlineData("InvalidGenericType")]
        public async Task TestYieldReturnInAsyncMethod(string returnTypeName)
        {
            var markup =
$@"namespace System.Collections.Generic
{{
Š
Šimon Koníček 已提交
1202
    interface {returnTypeName}<T> {{ }}
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
    class C
    {{
        async {returnTypeName}<int> M()
        {{
            yield return [|abc|]
        }}
    }}
}}";
            await TestAsync(markup, "global::System.Int32");
        }

        [Theory, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        [InlineData("int[]")]
        [InlineData("InvalidNonGenericType")]
        [InlineData("InvalidGenericType<int, int>")]
        public async Task TestYieldReturnInvalidTypeInMethod(string returnType)
        {
            var markup =
$@"class C
{{
    {returnType} M()
    {{
        yield return [|abc|]
    }}
}}";
            await TestAsync(markup, "global::System.Object");
        }

        [WorkItem(30235, "https://github.com/dotnet/roslyn/issues/30235")]
1232
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1233
        public async Task TestYieldReturnInLocalFunction()
1234 1235 1236 1237
        {
            var markup =
@"using System.Collections.Generic;

1238
class C
1239
{
1240
    void M()
1241
    {
1242 1243 1244 1245
        IEnumerable<int> F()
        {
            yield return [|abc|]
        }
1246 1247
    }
}";
C
CyrusNajmabadi 已提交
1248
            await TestAsync(markup, "global::System.Int32");
1249 1250
        }

1251
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1252
        public async Task TestYieldReturnInPropertyGetter()
1253 1254 1255 1256
        {
            var markup =
@"using System.Collections.Generic;

1257
class C
1258
{
1259
    IEnumerable<int> P
1260
    {
1261
        get
1262 1263 1264 1265 1266 1267 1268 1269
        {
            yield return [|abc|]
        }
    }
}";
            await TestAsync(markup, "global::System.Int32");
        }

1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestYieldReturnInPropertySetter()
        {
            var markup =
@"using System.Collections.Generic;

class C
{
    IEnumerable<int> P
    {
        set
        {
            yield return [|abc|]
        }
    }
}";
            await TestAsync(markup, "global::System.Object");
        }

1289 1290 1291 1292 1293 1294 1295
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestYieldReturnAsGlobalStatement()
        {
            await TestAsync(
@"yield return [|abc|]", "global::System.Object", sourceCodeKind: SourceCodeKind.Script);
        }

1296
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1297
        public async Task TestReturnInSimpleLambda()
1298
        {
1299 1300 1301
            await TestInMethodAsync(
@"System.Func<string, int> f = s =>
{
1302
    return [|Goo()|];
1303
};", "global::System.Int32");
1304 1305
        }

1306
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1307 1308 1309 1310 1311 1312 1313 1314 1315
        public async Task TestReturnInParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Func<int> f = () =>
{
    return [|Goo()|];
};", "global::System.Int32");
        }

1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInLambdaWithNullableReturn()
        {
            await TestInMethodAsync(
@"#nullable enable
System.Func<string, string?> f = s =>
{
    return [|Goo()|];
};", "global::System.String?");
        }

1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAnonymousMethod()
        {
            await TestInMethodAsync(
@"System.Func<int> f = delegate ()
{
    return [|Goo()|];
};", "global::System.Int32");
        }

1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAnonymousMethodWithNullableReturn()
        {
            await TestInMethodAsync(
@"#nullable enable
System.Func<string?> f = delegate ()
{
    return [|Goo()|];
};", "global::System.String?");
        }

1348 1349
        [WorkItem(4486, "https://github.com/dotnet/roslyn/issues/4486")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1350
        public async Task TestReturnInAsyncTaskOfTSimpleLambda()
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
        {
            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)]
1361
        public async Task TestReturnInAsyncTaskOfTParenthesizedLambda()
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
        {
            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)]
1372
        public async Task TestReturnInAsyncTaskOfTAnonymousMethod()
1373 1374 1375 1376 1377 1378 1379 1380
        {
            await TestInMethodAsync(
@"System.Func<System.Threading.Tasks.Task<int>> f = async delegate ()
{
    return [|Goo()|];
};", "global::System.Int32");
        }

1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncTaskOfTAnonymousMethodWithNullableReference()
        {
            await TestInMethodAsync(
@"#nullable enable
System.Func<System.Threading.Tasks.Task<string?>> f = async delegate ()
{
    return [|Goo()|];
};", "global::System.String?");
        }

1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncTaskSimpleLambda()
        {
            await TestInMethodAsync(
@"System.Func<string, System.Threading.Tasks.Task> f = async s =>
{
    return [|Goo()|];
};", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncTaskParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Func<System.Threading.Tasks.Task> f = async () =>
{
    return [|Goo()|];
};", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncTaskAnonymousMethod()
        {
            await TestInMethodAsync(
@"System.Func<System.Threading.Tasks.Task> f = async delegate ()
{
    return [|Goo()|];
};", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncVoidSimpleLambda()
        {
            await TestInMethodAsync(
@"System.Action<string> f = async s =>
{
    return [|Goo()|];
};", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncVoidParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Action f = async () =>
{
    return [|Goo()|];
};", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnInAsyncVoidAnonymousMethod()
        {
            await TestInMethodAsync(
@"System.Action f = async delegate ()
{
    return [|Goo()|];
};", "void");
        }

1452 1453 1454 1455 1456 1457 1458
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestReturnAsGlobalStatement()
        {
            await TestAsync(
@"return [|Goo()|];", "global::System.Object", sourceCodeKind: SourceCodeKind.Script);
        }

1459 1460
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestSimpleLambda()
1461
        {
1462
            await TestInMethodAsync(
1463
@"System.Func<string, int> f = s => [|Goo()|];", "global::System.Int32");
1464 1465
        }

1466 1467 1468 1469 1470 1471 1472
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Func<int> f = () => [|Goo()|];", "global::System.Int32");
        }

1473 1474
        [WorkItem(30232, "https://github.com/dotnet/roslyn/issues/30232")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1475
        public async Task TestAsyncTaskOfTSimpleLambda()
1476 1477 1478 1479 1480
        {
            await TestInMethodAsync(
@"System.Func<string, System.Threading.Tasks.Task<int>> f = async s => [|Goo()|];", "global::System.Int32");
        }

1481 1482 1483 1484 1485 1486 1487 1488
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestAsyncTaskOfTSimpleLambdaWithNullableReturn()
        {
            await TestInMethodAsync(
@"#nullable enable
System.Func<string, System.Threading.Tasks.Task<string?>> f = async s => [|Goo()|];", "global::System.String?");
        }

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

1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
        [WorkItem(30232, "https://github.com/dotnet/roslyn/issues/30232")]
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestAsyncTaskSimpleLambda()
        {
            await TestInMethodAsync(
@"System.Func<string, System.Threading.Tasks.Task> f = async s => [|Goo()|];", "void");
        }

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

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestAsyncVoidSimpleLambda()
        {
            await TestInMethodAsync(
@"System.Action<string> f = async s => [|Goo()|];", "void");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestAsyncVoidParenthesizedLambda()
        {
            await TestInMethodAsync(
@"System.Action f = async () => [|Goo()|];", "void");
        }

1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540
        [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");
        }

1541
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1542
        public async Task TestThrow()
1543
        {
1544
            await TestInMethodAsync(
1545
@"throw [|Goo()|];", "global::System.Exception");
1546 1547
        }

1548
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1549
        public async Task TestCatch()
1550
        {
1551
            await TestInMethodAsync("try { } catch ([|Goo|] ex) { }", "global::System.Exception");
1552 1553
        }

1554
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1555
        public async Task TestIf()
1556
        {
1557
            await TestInMethodAsync(@"if ([|Goo()|]) { }", "global::System.Boolean");
1558 1559
        }

1560
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1561
        public async Task TestWhile()
1562
        {
1563
            await TestInMethodAsync(@"while ([|Goo()|]) { }", "global::System.Boolean");
1564 1565
        }

1566
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1567
        public async Task TestDo()
1568
        {
1569
            await TestInMethodAsync(@"do { } while ([|Goo()|])", "global::System.Boolean");
1570 1571
        }

1572
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1573
        public async Task TestFor1()
1574
        {
1575
            await TestInMethodAsync(
1576
@"for (int i = 0; [|Goo()|];
1577 1578

i++) { }", "global::System.Boolean");
1579 1580
        }

1581
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1582
        public async Task TestFor2()
1583
        {
1584
            await TestInMethodAsync(@"for (string i = [|Goo()|]; ; ) { }", "global::System.String");
1585 1586
        }

1587
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1588
        public async Task TestFor3()
1589
        {
1590
            await TestInMethodAsync(@"for (var i = [|Goo()|]; ; ) { }", "global::System.Int32");
1591 1592
        }

1593 1594 1595 1596 1597 1598 1599 1600 1601
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestForNullableReference()
        {
            await TestInMethodAsync(
@"#nullable enable
for (string? s = [|Goo()|]; ; ) { }", "global::System.String?");
        }


1602
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1603
        public async Task TestUsing1()
1604
        {
1605
            await TestInMethodAsync(@"using ([|Goo()|]) { }", "global::System.IDisposable");
1606 1607
        }

1608
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1609
        public async Task TestUsing2()
1610
        {
1611
            await TestInMethodAsync(@"using (int i = [|Goo()|]) { }", "global::System.Int32");
1612 1613
        }

1614
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1615
        public async Task TestUsing3()
1616
        {
1617
            await TestInMethodAsync(@"using (var v = [|Goo()|]) { }", "global::System.IDisposable");
1618 1619
        }

1620
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1621
        public async Task TestForEach()
1622
        {
1623
            await TestInMethodAsync(@"foreach (int v in [|Goo()|]) { }", "global::System.Collections.Generic.IEnumerable<global::System.Int32>");
1624 1625
        }

1626
        [Fact(Skip = "https://github.com/dotnet/roslyn/issues/37309"), Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
1627 1628 1629 1630 1631 1632 1633
        public async Task TestForEachNullableElements()
        {
            await TestInMethodAsync(
@"#nullable enable
foreach (string? v in [|Goo()|]) { }", "global::System.Collections.Generic.IEnumerable<global::System.String?>");
        }

1634
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1635
        public async Task TestPrefixExpression1()
1636
        {
1637
            await TestInMethodAsync(
1638
@"var q = +[|Goo()|];", "global::System.Int32");
1639 1640
        }

1641
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1642
        public async Task TestPrefixExpression2()
1643
        {
1644
            await TestInMethodAsync(
1645
@"var q = -[|Goo()|];", "global::System.Int32");
1646 1647
        }

1648
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1649
        public async Task TestPrefixExpression3()
1650
        {
1651
            await TestInMethodAsync(
1652
@"var q = ~[|Goo()|];", "global::System.Int32");
1653 1654
        }

1655
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1656
        public async Task TestPrefixExpression4()
1657
        {
1658
            await TestInMethodAsync(
1659
@"var q = ![|Goo()|];", "global::System.Boolean");
1660 1661
        }

B
Brandon 已提交
1662 1663 1664
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestPrefixExpression5()
        {
1665
            await TestInMethodAsync(
1666
@"var q = System.DayOfWeek.Monday & ~[|Goo()|];", "global::System.DayOfWeek");
B
Brandon 已提交
1667 1668
        }

1669
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1670
        public async Task TestArrayRankSpecifier()
1671
        {
1672
            await TestInMethodAsync(
1673
@"var q = new string[[|Goo()|]];", "global::System.Int32");
1674 1675
        }

1676
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1677
        public async Task TestSwitch1()
1678
        {
1679
            await TestInMethodAsync(@"switch ([|Goo()|]) { }", "global::System.Int32");
1680 1681
        }

1682
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1683
        public async Task TestSwitch2()
1684
        {
1685
            await TestInMethodAsync(@"switch ([|Goo()|]) { default: }", "global::System.Int32");
1686 1687
        }

1688
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1689
        public async Task TestSwitch3()
1690
        {
1691
            await TestInMethodAsync(@"switch ([|Goo()|]) { case ""a"": }", "global::System.String");
1692 1693
        }

1694
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1695
        public async Task TestMethodCall1()
1696
        {
1697
            await TestInMethodAsync(
1698
@"Bar([|Goo()|]);", "global::System.Object");
1699 1700
        }

1701
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1702
        public async Task TestMethodCall2()
1703
        {
1704 1705 1706
            await TestInClassAsync(
@"void M()
{
1707
    Bar([|Goo()|]);
1708 1709 1710
}

void Bar(int i);", "global::System.Int32");
1711 1712
        }

1713
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1714
        public async Task TestMethodCall3()
1715
        {
1716 1717 1718
            await TestInClassAsync(
@"void M()
{
1719
    Bar([|Goo()|]);
1720 1721 1722
}

void Bar();", "global::System.Object");
1723 1724
        }

1725
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1726
        public async Task TestMethodCall4()
1727
        {
1728 1729 1730
            await TestInClassAsync(
@"void M()
{
1731
    Bar([|Goo()|]);
1732 1733 1734
}

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

1737
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1738
        public async Task TestMethodCall5()
1739
        {
1740 1741 1742
            await TestInClassAsync(
@"void M()
{
1743
    Bar(s: [|Goo()|]);
1744 1745 1746
}

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

1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestMethodCallNullableReference()
        {
            await TestInClassAsync(
@"void M()
{
    Bar([|Goo()|]);
}

void Bar(string? s);", "global::System.String?");
        }

1761
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1762
        public async Task TestConstructorCall1()
1763
        {
1764
            await TestInMethodAsync(
1765
@"new C([|Goo()|]);", "global::System.Object");
1766 1767
        }

1768
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1769
        public async Task TestConstructorCall2()
1770
        {
1771 1772 1773
            await TestInClassAsync(
@"void M()
{
1774
    new C([|Goo()|]);
1775 1776 1777
}

C(int i)
1778 1779
{
}", "global::System.Int32");
1780 1781
        }

1782
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1783
        public async Task TestConstructorCall3()
1784
        {
1785 1786 1787
            await TestInClassAsync(
@"void M()
{
1788
    new C([|Goo()|]);
1789 1790 1791
}

C()
1792 1793
{
}", "global::System.Object");
1794 1795
        }

1796
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1797
        public async Task TestConstructorCall4()
1798
        {
1799 1800 1801
            await TestInClassAsync(
@"void M()
{
1802
    new C([|Goo()|]);
1803 1804 1805
}

C(int i, string s)
1806 1807
{
}", "global::System.Int32");
1808 1809
        }

1810
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1811
        public async Task TestConstructorCall5()
1812
        {
1813 1814 1815
            await TestInClassAsync(
@"void M()
{
1816
    new C(s: [|Goo()|]);
1817 1818 1819
}

C(int i, string s)
1820 1821
{
}", "global::System.String");
1822 1823
        }

1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestConstructorCallNullableParameter()
        {
            await TestInClassAsync(
@"#nullable enable

void M()
{
    new C([|Goo()|]);
}

C(string? s)
{
}", "global::System.String?");
        }

J
Jared Parsons 已提交
1840
        [WorkItem(858112, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")]
1841
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1842
        public async Task TestThisConstructorInitializer1()
1843
        {
C
CyrusNajmabadi 已提交
1844 1845 1846 1847 1848 1849 1850
            await TestAsync(
@"class MyClass
{
    public MyClass(int x) : this([|test|])
    {
    }
}", "global::System.Int32");
1851 1852
        }

J
Jared Parsons 已提交
1853
        [WorkItem(858112, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")]
1854
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1855
        public async Task TestThisConstructorInitializer2()
1856
        {
C
CyrusNajmabadi 已提交
1857 1858 1859 1860 1861 1862 1863
            await TestAsync(
@"class MyClass
{
    public MyClass(int x, string y) : this(5, [|test|])
    {
    }
}", "global::System.String");
1864 1865
        }

1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestThisConstructorInitializerNullableParameter()
        {
            await TestAsync(
@"#nullable enable

class MyClass
{
    public MyClass(string? y) : this([|test|])
    {
    }
}", "global::System.String?");
        }

J
Jared Parsons 已提交
1880
        [WorkItem(858112, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")]
1881
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1882
        public async Task TestBaseConstructorInitializer()
1883
        {
C
CyrusNajmabadi 已提交
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897
            await TestAsync(
@"class B
{
    public B(int x)
    {
    }
}

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

1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestBaseConstructorInitializerNullableParameter()
        {
            await TestAsync(
@"#nullable enable

class B
{
    public B(string? x)
    {
    }
}

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

1921
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1922
        public async Task TestIndexAccess1()
1923
        {
1924 1925 1926
            await TestInMethodAsync(
@"string[] i;

1927
i[[|Goo()|]];", "global::System.Int32");
1928 1929
        }

1930
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1931
        public async Task TestIndexerCall1()
1932
        {
1933
            await TestInMethodAsync(@"this[[|Goo()|]];", "global::System.Int32");
1934 1935
        }

1936
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1937
        public async Task TestIndexerCall2()
1938
        {
1939 1940 1941
            await TestInClassAsync(
@"void M()
{
1942
    this[[|Goo()|]];
1943 1944
}

1945
int this[long i] { get; }", "global::System.Int64");
1946 1947
        }

1948
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1949
        public async Task TestIndexerCall3()
1950
        {
1951 1952 1953
            await TestInClassAsync(
@"void M()
{
1954
    this[42, [|Goo()|]];
1955 1956
}

1957
int this[int i, string s] { get; }", "global::System.String");
1958 1959
        }

1960
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
1961
        public async Task TestIndexerCall5()
1962
        {
1963 1964 1965
            await TestInClassAsync(
@"void M()
{
1966
    this[s: [|Goo()|]];
1967 1968 1969
}

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

1972
        [Fact]
C
Cyrus Najmabadi 已提交
1973
        public async Task TestArrayInitializerInImplicitArrayCreationSimple()
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
        {
            var text =
@"using System.Collections.Generic;

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

C
CyrusNajmabadi 已提交
1986
            await TestAsync(text, "global::System.Int32");
1987 1988
        }

1989
        [Fact]
C
Cyrus Najmabadi 已提交
1990
        public async Task TestArrayInitializerInImplicitArrayCreation1()
1991 1992 1993 1994 1995 1996 1997 1998
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
1999
       var a = new[] { Bar(), [|Goo()|] };
2000 2001 2002
  }

  int Bar() { return 1; }
2003
  int Goo() { return 2; }
2004 2005
}";

C
CyrusNajmabadi 已提交
2006
            await TestAsync(text, "global::System.Int32");
2007 2008
        }

2009
        [Fact]
C
Cyrus Najmabadi 已提交
2010
        public async Task TestArrayInitializerInImplicitArrayCreation2()
2011 2012 2013 2014 2015 2016 2017 2018
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
2019
       var a = new[] { Bar(), [|Goo()|] };
2020 2021 2022 2023 2024
  }

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

C
CyrusNajmabadi 已提交
2025
            await TestAsync(text, "global::System.Int32");
2026 2027
        }

2028
        [Fact]
C
Cyrus Najmabadi 已提交
2029
        public async Task TestArrayInitializerInImplicitArrayCreation3()
2030 2031 2032 2033 2034 2035 2036 2037
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
2038
       var a = new[] { Bar(), [|Goo()|] };
2039 2040 2041
  }
}";

C
CyrusNajmabadi 已提交
2042
            await TestAsync(text, "global::System.Object");
2043 2044
        }

2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065
        [Fact(Skip = "https://github.com/dotnet/roslyn/issues/32459")]
        public async Task TestArrayInitializerInImplicitArrayCreationInferredAsNullable()
        {
            var text =
@"#nullable enable

using System.Collections.Generic;

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

  object? Bar() { return null; }
}";

            await TestAsync(text, "global::System.Object?");
        }

2066
        [Fact]
C
Cyrus Najmabadi 已提交
2067
        public async Task TestArrayInitializerInEqualsValueClauseSimple()
2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079
        {
            var text =
@"using System.Collections.Generic;

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

C
CyrusNajmabadi 已提交
2080
            await TestAsync(text, "global::System.Int32");
2081 2082
        }

2083
        [Fact]
C
Cyrus Najmabadi 已提交
2084
        public async Task TestArrayInitializerInEqualsValueClause()
2085 2086 2087 2088 2089 2090 2091 2092
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
2093
       int[] a = { Bar(), [|Goo()|] };
2094 2095 2096 2097 2098
  }

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

C
CyrusNajmabadi 已提交
2099
            await TestAsync(text, "global::System.Int32");
2100 2101
        }

2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120
        [Fact]
        public async Task TestArrayInitializerInEqualsValueClauseNullableElement()
        {
            var text =
@"#nullable enable

using System.Collections.Generic;

class C
{
  void M()
  {
       string?[] a = { [|Goo()|] };
  }
}";

            await TestAsync(text, "global::System.String?");
        }

2121
        [Fact]
J
Jared Parsons 已提交
2122
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
2123
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2124
        public async Task TestCollectionInitializer1()
2125 2126 2127 2128 2129 2130 2131 2132
        {
            var text =
@"using System.Collections.Generic;

class C
{
  void M()
  {
2133
    new List<int>() { [|Goo()|] };
2134 2135 2136
  }
}";

C
CyrusNajmabadi 已提交
2137
            await TestAsync(text, "global::System.Int32");
2138 2139
        }

2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159
        [Fact]
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestCollectionInitializerNullableElement()
        {
            var text =
@"#nullable enable

using System.Collections.Generic;

class C
{
  void M()
  {
    new List<string?>() { [|Goo()|] };
  }
}";

            await TestAsync(text, "global::System.String?");
        }

2160
        [Fact]
J
Jared Parsons 已提交
2161
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
2162
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2163
        public async Task TestCollectionInitializer2()
2164 2165 2166 2167 2168 2169 2170 2171 2172
        {
            var text =
@"
using System.Collections.Generic;

class C
{
  void M()
  {
2173
    new Dictionary<int,string>() { { [|Goo()|], """" } };
2174 2175 2176
  }
}";

C
CyrusNajmabadi 已提交
2177
            await TestAsync(text, "global::System.Int32");
2178 2179
        }

2180
        [Fact]
J
Jared Parsons 已提交
2181
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
2182
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2183
        public async Task TestCollectionInitializer3()
2184 2185 2186 2187 2188 2189 2190 2191 2192
        {
            var text =
@"
using System.Collections.Generic;

class C
{
  void M()
  {
2193
    new Dictionary<int,string>() { { 0, [|Goo()|] } };
2194 2195 2196
  }
}";

C
CyrusNajmabadi 已提交
2197
            await TestAsync(text, "global::System.String");
2198 2199
        }

2200
        [Fact]
J
Jared Parsons 已提交
2201
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
2202
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2203
        public async Task TestCustomCollectionInitializerAddMethod1()
2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221
        {
            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 已提交
2222
            await TestAsync(text, "global::System.Int32", testPosition: false);
2223 2224
        }

2225
        [Fact]
J
Jared Parsons 已提交
2226
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
2227
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2228
        public async Task TestCustomCollectionInitializerAddMethod2()
2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246
        {
            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 已提交
2247
            await TestAsync(text, "global::System.Boolean");
2248 2249
        }

2250
        [Fact]
J
Jared Parsons 已提交
2251
        [WorkItem(529480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529480")]
2252
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2253
        public async Task TestCustomCollectionInitializerAddMethod3()
2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271
        {
            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 已提交
2272
            await TestAsync(text, "global::System.String");
2273 2274
        }

2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298
        [Fact]
        [Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestCustomCollectionInitializerAddMethodWithNullableParameter()
        {
            var text =
@"class C : System.Collections.IEnumerable
{
    void M()
    {
        var x = new C() { { ""test"", [|s|] } };
    }

    void Add(int i) { }
    void Add(string s, string? s2) { }

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

            await TestAsync(text, "global::System.String?");
        }

2299
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2300
        public async Task TestArrayInference1()
2301 2302 2303 2304 2305
        {
            var text =
@"
class A
{
2306
    void Goo()
2307 2308 2309 2310 2311
    {
        A[] x = new [|C|][] { };
    }
}";

C
Cyrus Najmabadi 已提交
2312
            await TestAsync(text, "global::A", testPosition: false);
2313 2314
        }

2315
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2316
        public async Task TestArrayInference1_Position()
2317 2318 2319 2320 2321
        {
            var text =
@"
class A
{
2322
    void Goo()
2323 2324 2325 2326 2327
    {
        A[] x = new [|C|][] { };
    }
}";

C
Cyrus Najmabadi 已提交
2328
            await TestAsync(text, "global::A[]", testNode: false);
2329 2330
        }

2331
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2332
        public async Task TestArrayInference2()
2333 2334 2335 2336 2337
        {
            var text =
@"
class A
{
2338
    void Goo()
2339 2340 2341 2342 2343
    {
        A[][] x = new [|C|][][] { };
    }
}";

C
Cyrus Najmabadi 已提交
2344
            await TestAsync(text, "global::A", testPosition: false);
2345 2346
        }

2347
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2348
        public async Task TestArrayInference2_Position()
2349 2350 2351 2352 2353
        {
            var text =
@"
class A
{
2354
    void Goo()
2355 2356 2357 2358 2359
    {
        A[][] x = new [|C|][][] { };
    }
}";

C
Cyrus Najmabadi 已提交
2360
            await TestAsync(text, "global::A[][]", testNode: false);
2361 2362
        }

2363
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2364
        public async Task TestArrayInference3()
2365 2366 2367 2368 2369
        {
            var text =
@"
class A
{
2370
    void Goo()
2371 2372 2373 2374 2375
    {
        A[][] x = new [|C|][] { };
    }
}";

C
Cyrus Najmabadi 已提交
2376
            await TestAsync(text, "global::A[]", testPosition: false);
2377 2378
        }

2379
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2380
        public async Task TestArrayInference3_Position()
2381 2382 2383 2384 2385
        {
            var text =
@"
class A
{
2386
    void Goo()
2387 2388 2389 2390 2391
    {
        A[][] x = new [|C|][] { };
    }
}";

C
Cyrus Najmabadi 已提交
2392
            await TestAsync(text, "global::A[][]", testNode: false);
2393 2394
        }

2395
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2396
        public async Task TestArrayInference4()
2397 2398 2399 2400 2401 2402
        {
            var text =
@"
using System;
class A
{
2403
    void Goo()
2404 2405 2406 2407 2408
    {
        Func<int, int>[] x = new Func<int, int>[] { [|Bar()|] };
    }
}";

C
Cyrus Najmabadi 已提交
2409
            await TestAsync(text, "global::System.Func<global::System.Int32, global::System.Int32>");
2410 2411
        }

J
Jared Parsons 已提交
2412
        [WorkItem(538993, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538993")]
2413
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2414
        public async Task TestInsideLambda2()
2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425
        {
            var text =
@"using System;
class C
{
  void M()
  {
    Func<int,int> f = i => [|here|]
  }
}";

C
CyrusNajmabadi 已提交
2426
            await TestAsync(text, "global::System.Int32");
2427 2428
        }

2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestInsideLambdaNullableReturn()
        {
            var text =
@"#nullable enable

using System;
class C
{
  void M()
  {
    Func<int, string?> f = i => [|here|]
  }
}";

            await TestAsync(text, "global::System.String?");
        }

J
Jared Parsons 已提交
2447
        [WorkItem(539813, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539813")]
2448
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2449
        public async Task TestPointer1()
2450 2451 2452 2453 2454 2455
        {
            var text =
@"class C
{
  void M(int* i)
  {
2456
    var q = i[[|Goo()|]];
2457 2458 2459
  }
}";

C
CyrusNajmabadi 已提交
2460
            await TestAsync(text, "global::System.Int32");
2461 2462
        }

J
Jared Parsons 已提交
2463
        [WorkItem(539813, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539813")]
2464
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2465
        public async Task TestDynamic1()
2466 2467 2468 2469 2470 2471
        {
            var text =
@"class C
{
  void M(dynamic i)
  {
2472
    var q = i[[|Goo()|]];
2473 2474 2475
  }
}";

C
CyrusNajmabadi 已提交
2476
            await TestAsync(text, "global::System.Int32");
2477 2478
        }

2479
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
C
Cyrus Najmabadi 已提交
2480
        public async Task TestChecked1()
2481 2482 2483 2484 2485 2486
        {
            var text =
@"class C
{
  void M()
  {
2487
    string q = checked([|Goo()|]);
2488 2489 2490
  }
}";

C
CyrusNajmabadi 已提交
2491
            await TestAsync(text, "global::System.String");
2492 2493
        }

2494
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2495
        [WorkItem(553584, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/553584")]
C
Cyrus Najmabadi 已提交
2496
        public async Task TestAwaitTaskOfT()
2497 2498 2499 2500 2501 2502 2503
        {
            var text =
@"using System.Threading.Tasks;
class C
{
  void M()
  {
2504
    int x = await [|Goo()|];
2505 2506 2507
  }
}";

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

2511
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528
        public async Task TestAwaitTaskOfTNullableValue()
        {
            var text =
@"#nullable enable

using System.Threading.Tasks;
class C
{
  void M()
  {
    string? x = await [|Goo()|];
  }
}";

            await TestAsync(text, "global::System.Threading.Tasks.Task<global::System.String?>");
        }

2529
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2530
        [WorkItem(553584, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/553584")]
C
Cyrus Najmabadi 已提交
2531
        public async Task TestAwaitTaskOfTaskOfT()
2532 2533 2534 2535 2536 2537 2538
        {
            var text =
@"using System.Threading.Tasks;
class C
{
  void M()
  {
2539
    Task<int> x = await [|Goo()|];
2540 2541 2542
  }
}";

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

2546
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2547
        [WorkItem(553584, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/553584")]
C
Cyrus Najmabadi 已提交
2548
        public async Task TestAwaitTask()
2549 2550 2551 2552 2553 2554 2555
        {
            var text =
@"using System.Threading.Tasks;
class C
{
  void M()
  {
2556
    await [|Goo()|];
2557 2558 2559
  }
}";

C
Cyrus Najmabadi 已提交
2560
            await TestAsync(text, "global::System.Threading.Tasks.Task");
2561 2562
        }

2563
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2564
        [WorkItem(617622, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617622")]
C
Cyrus Najmabadi 已提交
2565
        public async Task TestLockStatement()
2566 2567 2568 2569 2570 2571
        {
            var text =
@"class C
{
  void M()
  {
2572
    lock([|Goo()|])
2573 2574 2575 2576 2577
    {
    }
  }
}";

C
CyrusNajmabadi 已提交
2578
            await TestAsync(text, "global::System.Object");
2579 2580
        }

2581
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2582
        [WorkItem(617622, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617622")]
C
Cyrus Najmabadi 已提交
2583
        public async Task TestAwaitExpressionInLockStatement()
2584 2585 2586 2587 2588 2589
        {
            var text =
@"class C
{
  async void M()
  {
2590
    lock(await [|Goo()|])
2591 2592 2593 2594 2595
    {
    }
  }
}";

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

2599
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2600
        [WorkItem(827897, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/827897")]
C
Cyrus Najmabadi 已提交
2601
        public async Task TestReturnFromAsyncTaskOfT()
2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612
        {
            var markup =
@"using System.Threading.Tasks;
class Program
{
    async Task<int> M()
    {
        await Task.Delay(1);
        return [|ab|]
    }
}";
C
CyrusNajmabadi 已提交
2613
            await TestAsync(markup, "global::System.Int32");
2614 2615
        }

2616
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2617
        [WorkItem(853840, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/853840")]
C
Cyrus Najmabadi 已提交
2618
        public async Task TestAttributeArguments1()
2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631
        {
            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 已提交
2632
            await TestAsync(markup, "global::System.DayOfWeek");
2633 2634
        }

2635
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2636
        [WorkItem(853840, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/853840")]
C
Cyrus Najmabadi 已提交
2637
        public async Task TestAttributeArguments2()
2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650
        {
            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 已提交
2651
            await TestAsync(markup, "global::System.Double");
2652 2653
        }

2654
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2655
        [WorkItem(853840, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/853840")]
C
Cyrus Najmabadi 已提交
2656
        public async Task TestAttributeArguments3()
2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669
        {
            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 已提交
2670
            await TestAsync(markup, "global::System.String");
2671 2672
        }

2673
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2674
        [WorkItem(757111, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/757111")]
C
Cyrus Najmabadi 已提交
2675
        public async Task TestReturnStatementWithinDelegateWithinAMethodCall()
2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693
        {
            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 已提交
2694
            await TestAsync(text, "global::System.String");
2695 2696
        }

2697
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2698
        [WorkItem(994388, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994388")]
C
Cyrus Najmabadi 已提交
2699
        public async Task TestCatchFilterClause()
2700 2701 2702 2703 2704 2705 2706
        {
            var text =
@"
try
{ }
catch (Exception) if ([|M()|])
}";
C
CyrusNajmabadi 已提交
2707
            await TestInMethodAsync(text, "global::System.Boolean");
2708 2709
        }

2710
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2711
        [WorkItem(994388, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994388")]
C
Cyrus Najmabadi 已提交
2712
        public async Task TestCatchFilterClause1()
2713 2714 2715 2716 2717 2718 2719
        {
            var text =
@"
try
{ }
catch (Exception) if ([|M|])
}";
C
CyrusNajmabadi 已提交
2720
            await TestInMethodAsync(text, "global::System.Boolean");
2721 2722
        }

2723
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jared Parsons 已提交
2724
        [WorkItem(994388, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994388")]
C
Cyrus Najmabadi 已提交
2725
        public async Task TestCatchFilterClause2()
2726 2727 2728 2729 2730 2731 2732
        {
            var text =
@"
try
{ }
catch (Exception) if ([|M|].N)
}";
C
CyrusNajmabadi 已提交
2733
            await TestInMethodAsync(text, "global::System.Object", testPosition: false);
2734
        }
J
Jonathon Marolf 已提交
2735

2736
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jonathon Marolf 已提交
2737
        [WorkItem(643, "https://github.com/dotnet/roslyn/issues/643")]
C
Cyrus Najmabadi 已提交
2738
        public async Task TestAwaitExpressionWithChainingMethod()
J
Jonathon Marolf 已提交
2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750
        {
            var text =
@"using System;
using System.Threading.Tasks;

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

2754
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jonathon Marolf 已提交
2755
        [WorkItem(643, "https://github.com/dotnet/roslyn/issues/643")]
C
Cyrus Najmabadi 已提交
2756
        public async Task TestAwaitExpressionWithChainingMethod2()
J
Jonathon Marolf 已提交
2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768
        {
            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 已提交
2769
            await TestAsync(text, "global::System.Threading.Tasks.Task<global::System.Object>", testPosition: false);
J
Jonathon Marolf 已提交
2770
        }
2771

2772
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
2773
        [WorkItem(4233, "https://github.com/dotnet/roslyn/issues/4233")]
C
Cyrus Najmabadi 已提交
2774
        public async Task TestAwaitExpressionWithGenericMethod1()
2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787
        {
            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 已提交
2788
            await TestAsync(text, "global::System.Boolean", testPosition: false);
2789 2790
        }

2791
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
2792
        [WorkItem(4233, "https://github.com/dotnet/roslyn/issues/4233")]
C
Cyrus Najmabadi 已提交
2793
        public async Task TestAwaitExpressionWithGenericMethod2()
2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806
        {
            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 已提交
2807
            await TestAsync(text, "global::System.Boolean");
2808
        }
2809

2810
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
2811
        [WorkItem(4483, "https://github.com/dotnet/roslyn/issues/4483")]
C
Cyrus Najmabadi 已提交
2812
        public async Task TestNullCoalescingOperator1()
2813 2814 2815 2816 2817 2818 2819 2820 2821
        {
            var text =
    @"class C
{
    void M()
    {
        object z = [|a|]?? null;
    }
}";
C
CyrusNajmabadi 已提交
2822
            await TestAsync(text, "global::System.Object");
2823 2824
        }

2825
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
2826
        [WorkItem(4483, "https://github.com/dotnet/roslyn/issues/4483")]
C
Cyrus Najmabadi 已提交
2827
        public async Task TestNullCoalescingOperator2()
2828 2829 2830 2831 2832 2833 2834 2835 2836
        {
            var text =
    @"class C
{
    void M()
    {
        object z = [|a|] ?? b ?? c;
    }
}";
C
CyrusNajmabadi 已提交
2837
            await TestAsync(text, "global::System.Object");
2838 2839
        }

2840
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
2841
        [WorkItem(4483, "https://github.com/dotnet/roslyn/issues/4483")]
C
Cyrus Najmabadi 已提交
2842
        public async Task TestNullCoalescingOperator3()
2843 2844 2845 2846 2847 2848 2849 2850 2851
        {
            var text =
    @"class C
{
    void M()
    {
        object z = a ?? [|b|] ?? c;
    }
}";
C
CyrusNajmabadi 已提交
2852
            await TestAsync(text, "global::System.Object");
2853
        }
J
Jonathon Marolf 已提交
2854

2855
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jonathon Marolf 已提交
2856
        [WorkItem(5126, "https://github.com/dotnet/roslyn/issues/5126")]
C
Cyrus Najmabadi 已提交
2857
        public async Task TestSelectLambda()
J
Jonathon Marolf 已提交
2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869
        {
            var text =
    @"using System.Collections.Generic;
using System.Linq;

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

2873
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
J
Jonathon Marolf 已提交
2874
        [WorkItem(5126, "https://github.com/dotnet/roslyn/issues/5126")]
C
Cyrus Najmabadi 已提交
2875
        public async Task TestSelectLambda2()
J
Jonathon Marolf 已提交
2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887
        {
            var text =
    @"using System.Collections.Generic;
using System.Linq;

class C
{
    void M(IEnumerable<string> args)
    {
        args = args.Select(a =>[|b|])
    }
}";
C
CyrusNajmabadi 已提交
2888
            await TestAsync(text, "global::System.String", testPosition: false);
2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904
        }

        [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)
    {
2905
        return a.Select(i => [|Goo(i)|]);
2906 2907 2908
    }
}";
            await TestAsync(text, "global::B");
J
Jonathon Marolf 已提交
2909
        }
2910

R
Ravi Chande 已提交
2911 2912
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        [WorkItem(6765, "https://github.com/dotnet/roslyn/issues/6765")]
A
Andy Gocke 已提交
2913
        public async Task TestDefaultStatement1()
R
Ravi Chande 已提交
2914 2915 2916 2917 2918 2919 2920 2921 2922
        {
            var text =
    @"class C
{
    static void Main(string[] args)
    {
        System.ConsoleModifiers c = default([||])
    }
}";
2923
            await TestAsync(text, "global::System.ConsoleModifiers", testNode: false);
R
Ravi Chande 已提交
2924 2925 2926 2927
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        [WorkItem(6765, "https://github.com/dotnet/roslyn/issues/6765")]
A
Andy Gocke 已提交
2928
        public async Task TestDefaultStatement2()
R
Ravi Chande 已提交
2929 2930 2931 2932
        {
            var text =
    @"class C
{
2933
    static void Goo(System.ConsoleModifiers arg)
R
Ravi Chande 已提交
2934
    {
2935
        Goo(default([||])
R
Ravi Chande 已提交
2936 2937
    }
}";
A
Andy Gocke 已提交
2938
            await TestAsync(text, "global::System.ConsoleModifiers", testNode: false);
R
Ravi Chande 已提交
2939
        }
2940 2941 2942 2943 2944 2945 2946 2947 2948

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestWhereCall()
        {
            var text =
    @"
using System.Collections.Generic;
class C
{
2949
    void Goo()
2950 2951 2952 2953
    {
        [|ints|].Where(i => i > 10);
    }
}";
C
CyrusNajmabadi 已提交
2954
            await TestAsync(text, "global::System.Collections.Generic.IEnumerable<global::System.Int32>", testPosition: false);
2955 2956 2957 2958 2959 2960 2961 2962 2963 2964
        }

        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestWhereCall2()
        {
            var text =
    @"
using System.Collections.Generic;
class C
{
2965
    void Goo()
2966 2967 2968 2969
    {
        [|ints|].Where(i => null);
    }
}";
C
CyrusNajmabadi 已提交
2970
            await TestAsync(text, "global::System.Collections.Generic.IEnumerable<global::System.Object>", testPosition: false);
2971
        }
R
Ravi Chande 已提交
2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990

        [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);
        }
2991 2992

        [WorkItem(15468, "https://github.com/dotnet/roslyn/issues/15468")]
C
Cyrus Najmabadi 已提交
2993
        [WorkItem(25305, "https://github.com/dotnet/roslyn/issues/25305")]
2994 2995 2996 2997
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
        public async Task TestDeconstruction()
        {
            await TestInMethodAsync(
C
Cyrus Najmabadi 已提交
2998 2999 3000 3001 3002 3003 3004 3005 3006 3007
@"[|(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);
3008
        }
3009

3010
        [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
3011 3012 3013 3014 3015 3016
        public async Task TestDeconstructionWithNullableElement()
        {
            await TestInMethodAsync(
@"[|(string? s, _)|] =", "(global::System.String? s, global::System.Object _)", testPosition: false);
        }

3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032
        [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);
        }
3033

3034
        [Fact(Skip = "https://github.com/dotnet/roslyn/issues/37310"), Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051
        public async Task TestInferringThroughGenericFunctionWithNullableReturn()
        {
            var text =
@"#nullable enable

class Program
{
    static void Main(string[] args)
    {
        string? s = Identity([|input|]);
    }

    static T Identity<T>(T value) { return value; }
}";

            await TestAsync(text, "global::System.String?");
        }
3052
    }
S
Sam Harwell 已提交
3053
}