Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8497,4 +8497,66 @@ void M(object[] p)
}
""",
new(parseOptions: TestOptions.Regular));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/80982")]
public Task TestFunctionPointerType()
=> TestInRegularAndScriptAsync(
"""
unsafe class C
{
public delegate* managed<void> D
{
get
{
return [|field|];
}
}
}
""",
"""
unsafe class C
{
public delegate* managed<void> D
{
get
{
delegate*<void> {|Rename:value|} = field;
return value;
}
}
}
""");

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/80982")]
public Task TestPointerType()
=> TestInRegularAndScriptAsync(
"""
unsafe class C
{
class Customer { }

public Customer* D
{
get
{
return [|field|];
}
}
}
""",
"""
unsafe class C
{
class Customer { }

public Customer* D
{
get
{
Customer* {|Rename:customer|} = field;
return customer;
}
}
}
""");
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,23 @@ public static string GenerateNameFromType(this SemanticModel semanticModel, ITyp

// We may be able to use the type's arguments to generate a name if we're working with an enumerable type.
if (pluralize && TryGeneratePluralizedNameFromTypeArgument(syntaxFacts, typeArguments, capitalize, out var typeArgumentParameterName))
{
return typeArgumentParameterName;
}

// If there's no type argument and we have an array type, we should pluralize, e.g. using 'frogs' for 'new Frog[]' instead of 'frog'
if (type.TypeKind == TypeKind.Array && typeArguments.IsEmpty)
{
return Pluralize(type.CreateParameterName(capitalize));
}

if (type is IPointerTypeSymbol pointerType)
return GenerateNameFromType(semanticModel, pointerType.PointedAtType, syntaxFacts, capitalize);

if (type.IsNullable(out var underlyingType))
return GenerateNameFromType(semanticModel, underlyingType, syntaxFacts, capitalize);

// Otherwise assume no pluralization, e.g. using 'immutableArray', 'list', etc. instead of their
// plural forms
if (type.IsSpecialType() ||
type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T ||
type.TypeKind == TypeKind.Pointer)
{
return capitalize ? DefaultBuiltInParameterName.ToUpper() : DefaultBuiltInParameterName;
}
else
{
return type.CreateParameterName(capitalize);
}
return type.IsSpecialType()
? capitalize ? DefaultBuiltInParameterName.ToUpper() : DefaultBuiltInParameterName
: type.CreateParameterName(capitalize);
}

private static bool ShouldPluralize(this SemanticModel semanticModel, ITypeSymbol type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,14 @@ public static string CreateParameterName(this ITypeSymbol type, bool capitalize
type = arrayType.ElementType;
continue;
case IPointerTypeSymbol pointerType:
// For normal pointers like Customer*, unwrap to get a meaningful name (customer)
// rather than using a generic default
type = pointerType.PointedAtType;
continue;
case IFunctionPointerTypeSymbol:
// Function pointer types like "delegate*<void>" don't have a meaningful underlying type
// to generate a name from, so use the default parameter name
return capitalize ? DefaultParameterName.ToPascalCase() : DefaultParameterName;
}

break;
Expand Down
Loading