Skip to content

C#: Enable nullability of Semmle.Extraction.CSharp.Standalone#4115

Merged
tamasvajk merged 4 commits intogithub:mainfrom
tamasvajk:feature/nullability-extraction-csharp-standalone
Sep 14, 2020
Merged

C#: Enable nullability of Semmle.Extraction.CSharp.Standalone#4115
tamasvajk merged 4 commits intogithub:mainfrom
tamasvajk:feature/nullability-extraction-csharp-standalone

Conversation

@tamasvajk
Copy link
Contributor

No description provided.

@tamasvajk tamasvajk added the C# label Aug 20, 2020
@tamasvajk tamasvajk requested a review from a team August 20, 2020 15:00
@tamasvajk tamasvajk force-pushed the feature/nullability-extraction-csharp-standalone branch 2 times, most recently from 66fd9d7 to 69050fa Compare August 27, 2020 14:44
public static AssemblyInfo MakeFromAssembly(Assembly assembly) => new AssemblyInfo() { Valid = true, Filename = assembly.Location, Id = assembly.FullName };
public static AssemblyInfo MakeFromAssembly(Assembly assembly)
{
if (assembly.FullName is null)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a slight change in functionality. FullName can be null, now we're explicitly throwing an exception, previously the first access would have thrown (a different type of exception).

{
var sortedReferences = usedReferences.
Select(r => assemblyCache.GetAssemblyInfo(r.Key)).
Where(r => r != AssemblyInfo.Invalid).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This validity check was missing before.

@tamasvajk tamasvajk marked this pull request as ready for review August 27, 2020 15:07
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

This is excellent, Tamas. Nice refactorings.

// Fast path if we've already seen this before.
if (failedAssemblyInfoIds.Contains(id))
return AssemblyInfo.Invalid;
throw new AssemblyLoadException();
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like we should have more information in this exception, for example pass id to the constructor of AssemblyLoadException.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add it, but it would not be used at the moment. Previously, we had the static AssemblyInfo.Invalid, which also didn't have any more information. The reason why I changed it to an exception is that AssemblyInfo.Invalid was basically a partially constructed AssemblyInfo, which had a lot of uninitialized properties.

}
catch (AssemblyLoadException)
{
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It does feel like we should record this failure somewhere. Why not call UnresolvedReference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't call UnresolvedReference because at this point we're not in a project context, so we wouldn't be able to pass the second parameter.

At the same time, I'm not sure this catch is required at all. We're iterating over usedReferences, which should all be already resolved once, so I don't think this can fail. Also, we had no equality check here previously for the AssemblyInfo.Invalid either.

I'm adding logging to this catch.

hvitved
hvitved previously approved these changes Sep 7, 2020
@tamasvajk
Copy link
Contributor Author

tamasvajk commented Sep 9, 2020

@tamasvajk tamasvajk force-pushed the feature/nullability-extraction-csharp-standalone branch from 096ee6b to 558a012 Compare September 10, 2020 08:26
@tamasvajk tamasvajk merged commit f5f4b8e into github:main Sep 14, 2020
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.

3 participants