Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4714,6 +4714,20 @@ static void M()
}
""", "x");

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/82750")]
public Task TypeWithSameNameAsInstancePropertyInStaticMethod()
=> VerifyItemExistsAsync("""
public sealed record SourceContainer(Source Source)
{
public static SourceContainer From(string source)
{
Sour$$
}
}

public sealed record Source(string Content);
""", "Source", expectedDescriptionOrNull: "record Source");

[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543601")]
public Task NoInstanceFieldsInStaticFieldInitializer()
=> VerifyItemIsAbsentAsync("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,35 @@ private ImmutableArray<ISymbol> GetSymbolsForExpressionOrStatementContext()
}
else
{
symbols = contextNode.IsInStaticContext()
? semanticModel.LookupStaticMembers(_context.LeftToken.SpanStart)
: semanticModel.LookupSymbols(_context.LeftToken.SpanStart);
if (contextNode.IsInStaticContext())
{
var position = _context.LeftToken.SpanStart;
symbols = semanticModel.LookupStaticMembers(position);

// Primary constructor parameters are returned by LookupStaticMembers, but are unusable in a static
// context. They can hide a namespace or type with the same name, so recover those candidates.
if (!_context.IsInstanceContext)
{
using var _ = ArrayBuilder<ISymbol>.GetInstance(symbols.Length, out var staticSymbols);
foreach (var symbol in symbols)
{
if (symbol is IParameterSymbol parameter && parameter.IsPrimaryConstructor(_cancellationToken))
{
staticSymbols.AddRange(semanticModel.LookupNamespacesAndTypes(position, name: parameter.Name));
}
else
{
staticSymbols.Add(symbol);
}
}

symbols = staticSymbols.ToImmutableAndClear();
}
}
else
{
symbols = semanticModel.LookupSymbols(_context.LeftToken.SpanStart);
}

symbols = FilterOutUncapturableParameters(symbols, contextNode);
}
Expand Down
Loading