Language: C# | Type: CODE_SMELL | Severity: Critical
Tags: breaking-change, csharp14
Using partial as a return type identifier will cause a compilation error when upgrading to C# 14.
In C# 14, partial in a return type position is always treated as a modifier, even when a type named partial is in scope.
This causes compilation errors in code that previously compiled successfully.
The issue specifically affects method declarations where a custom type named partial is used as the return type. Other uses of the
partial type (such as in variable declarations or constructor calls) are not affected by this change.
This breaking change will cause compilation failures when upgrading existing codebases to C# 14. The compilation error prevents the application from building, requiring immediate attention to fix the syntax.
While this is not a runtime issue, it can block development and deployment processes until resolved. The fix is straightforward but must be applied to all affected method declarations.
Add the @ prefix before partial when used as a return type. This tells the compiler to treat partial as an
identifier rather than a modifier. Alternatively, rename the type to avoid the conflict.
class C
{
partial F() => new partial(); // Noncompliant
}
class partial { }
class C
{
@partial F() => new partial();
}
class partial { }
class C
{
partial F() => new partial(); // Noncompliant
}
class partial { }
class C
{
PartialItem F() => new PartialItem();
}
class PartialItem { }
partial cannot be a return type of methods