mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
C#: Use cast expressions for object defaults.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user