Skip to content

C#: Fix an InvalidCastException #2086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2019
Merged

Conversation

calumgrant
Copy link
Contributor

Works around a bug in Roslyn whereby IPropertySymbol.IsIndexer would yield erroneous results, resulting in

Unable to cast object of type 'Semmle.Extraction.CSharp.Entities.Property' to type 'Semmle.Extraction.CSharp.Entities.Indexer'.

appearing in csharp.log.

Unable to reproduce in a qltest.

@calumgrant calumgrant requested a review from a team as a code owner October 4, 2019 15:32
@calumgrant calumgrant added the C# label Oct 4, 2019
@@ -111,7 +111,7 @@ public override Microsoft.CodeAnalysis.Location FullLocation

public static Property Create(Context cx, IPropertySymbol prop)
{
bool isIndexer = prop.IsIndexer || prop.ExplicitInterfaceImplementations.Any(e => e.IsIndexer);
bool isIndexer = prop.IsIndexer || prop.ExplicitInterfaceImplementations.Any(e => e.IsIndexer) || prop.Parameters.Any();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, simplify this to prop.IsIndexer || prop.Parameters.Any() and make sure we have a test for an indexer that explicitly implements an interface indexer.

@hvitved hvitved merged commit 3f17014 into github:master Oct 15, 2019
@calumgrant calumgrant deleted the cs/indexer-detection branch November 19, 2019 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants