C#: Use cast expressions for object defaults.

This commit is contained in:
Michael Nebel
2023-12-08 15:37:12 +01:00
parent 6c30f6a748
commit 9aeba5063f

View File

@@ -202,16 +202,6 @@ namespace Semmle.Extraction.CSharp.Entities
return Default.CreateGenerated(cx, parent, childIndex, location, parameter.Type.IsReferenceType ? ValueAsString(null) : null);
}
if (parameter.Type.SpecialType is SpecialType.System_Object)
{
// this can happen in VB.NET
cx.ExtractionError($"Extracting default argument value 'object {parameter.Name} = default' instead of 'object {parameter.Name} = {defaultValue}'. The latter is not supported in C#.",
null, null, severity: Semmle.Util.Logging.Severity.Warning);
// we're generating a default expression:
return Default.CreateGenerated(cx, parent, childIndex, location, ValueAsString(null));
}
if (type.SpecialType is SpecialType.None)
{
return ImplicitCast.CreateGeneratedConversion(cx, parent, childIndex, type, defaultValue, location);
@@ -222,7 +212,9 @@ namespace Semmle.Extraction.CSharp.Entities
return DateTimeObjectCreation.CreateGenerated(cx, parent, childIndex, type, defaultValue, location);
}
if (type.SpecialType is SpecialType.System_IntPtr || type.SpecialType is SpecialType.System_UIntPtr)
if (type.SpecialType is SpecialType.System_Object ||
type.SpecialType is SpecialType.System_IntPtr ||
type.SpecialType is SpecialType.System_UIntPtr)
{
return ImplicitCast.CreateGenerated(cx, parent, childIndex, type, defaultValue, location);
}