Skip to content

Commit 9aeba50

Browse files
committed
C#: Use cast expressions for object defaults.
1 parent 6c30f6a commit 9aeba50

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,6 @@ private static bool ContainsPattern(SyntaxNode node) =>
202202
return Default.CreateGenerated(cx, parent, childIndex, location, parameter.Type.IsReferenceType ? ValueAsString(null) : null);
203203
}
204204

205-
if (parameter.Type.SpecialType is SpecialType.System_Object)
206-
{
207-
// this can happen in VB.NET
208-
cx.ExtractionError($"Extracting default argument value 'object {parameter.Name} = default' instead of 'object {parameter.Name} = {defaultValue}'. The latter is not supported in C#.",
209-
null, null, severity: Semmle.Util.Logging.Severity.Warning);
210-
211-
// we're generating a default expression:
212-
return Default.CreateGenerated(cx, parent, childIndex, location, ValueAsString(null));
213-
}
214-
215205
if (type.SpecialType is SpecialType.None)
216206
{
217207
return ImplicitCast.CreateGeneratedConversion(cx, parent, childIndex, type, defaultValue, location);
@@ -222,7 +212,9 @@ private static bool ContainsPattern(SyntaxNode node) =>
222212
return DateTimeObjectCreation.CreateGenerated(cx, parent, childIndex, type, defaultValue, location);
223213
}
224214

225-
if (type.SpecialType is SpecialType.System_IntPtr || type.SpecialType is SpecialType.System_UIntPtr)
215+
if (type.SpecialType is SpecialType.System_Object ||
216+
type.SpecialType is SpecialType.System_IntPtr ||
217+
type.SpecialType is SpecialType.System_UIntPtr)
226218
{
227219
return ImplicitCast.CreateGenerated(cx, parent, childIndex, type, defaultValue, location);
228220
}

0 commit comments

Comments
 (0)