提交 8c17b4e1 编写于 作者: R Ravi Chande 提交者: GitHub

Merge pull request #12907 from rchande/fix12755

Fix #12755
......@@ -1850,5 +1850,24 @@ void Foo()
}";
await TestAsync(text, "global::System.Collections.Generic.IEnumerable<global::System.Object>", testPosition: false);
}
[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);
}
}
}
\ No newline at end of file
......@@ -702,6 +702,21 @@ private void DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol
return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
}
if (previousToken.HasValue && previousToken.Value.GetPreviousToken().Kind() == SyntaxKind.EqualsToken)
{
// We parsed an array creation but the token before `new` is `=`.
// This could be a case like:
//
// int[] array;
// Program p = new |
// array[4] = 4;
//
// This is similar to the cases described in `InferTypeInObjectCreationExpression`.
// Again, all we have to do is back up to before `new`.
return InferTypes(previousToken.Value.SpanStart);
}
var outerTypes = InferTypes(arrayCreationExpression);
return outerTypes.Where(o => o is IArrayTypeSymbol);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册