Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial properties: misc compiler layer work #73527

Merged
Prev Previous commit
Next Next commit
Check LangVersion
  • Loading branch information
RikkiGibson committed May 17, 2024
commit 6a79b2e1bae0df0ecbc37fa43a9720134185cd26
5 changes: 4 additions & 1 deletion src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ internal enum MessageID
IDS_FeatureParamsCollections = MessageBase + 12842,

IDS_FeatureRefUnsafeInIteratorAsync = MessageBase + 12843,

// PROTOTYPE(partial-properties): pack
IDS_FeaturePartialProperties = MessageBase + 13000,
}

// Message IDs may refer to strings that need to be localized.
Expand Down Expand Up @@ -468,7 +471,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
case MessageID.IDS_FeatureImplicitIndexerInitializer:
case MessageID.IDS_FeatureLockObject:
case MessageID.IDS_FeatureParamsCollections:
case MessageID.IDS_FeatureRefUnsafeInIteratorAsync:
case MessageID.IDS_FeaturePartialProperties:
return LanguageVersion.Preview;

// C# 12.0 features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,18 @@ private static (DeclarationModifiers modifiers, bool hasExplicitAccessMod) MakeM
hasExplicitAccessMod = true;
}

if ((mods & DeclarationModifiers.Partial) != 0)
{
Debug.Assert(location.SourceTree is not null);

LanguageVersion availableVersion = ((CSharpParseOptions)location.SourceTree.Options).LanguageVersion;
LanguageVersion requiredVersion = MessageID.IDS_FeaturePartialProperties.RequiredVersion();
if (availableVersion < requiredVersion)
{
ModifierUtils.ReportUnsupportedModifiersForLanguageVersion(mods, DeclarationModifiers.Partial, location, diagnostics, availableVersion, requiredVersion);
}
}

ModifierUtils.CheckFeatureAvailabilityForStaticAbstractMembersInInterfacesIfNeeded(mods, isExplicitInterfaceImplementation, location, diagnostics);

containingType.CheckUnsafeModifier(mods, location, diagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public extern static partial int F
}
}
""";
CompileAndVerify(source, parseOptions: TestOptions.Regular.WithNoRefSafetyRulesAttribute(), assemblyValidator: (assembly) =>
CompileAndVerify(source, parseOptions: TestOptions.RegularPreview.WithNoRefSafetyRulesAttribute(), assemblyValidator: (assembly) =>
{
var metadataReader = assembly.GetMetadataReader();

Expand Down Expand Up @@ -4410,6 +4410,39 @@ public int P
Assert.Empty(symbolInfo.CandidateSymbols);
}

[Fact]
public void LangVersion_01()
{
var source = """
partial class C
{
public partial int P { get; set; }
public partial int P { get => 1; set { } }

public partial int this[int i] { get; }
public partial int this[int i] { get => i; }
}
""";

var comp = CreateCompilation(source);
RikkiGibson marked this conversation as resolved.
Show resolved Hide resolved
comp.VerifyEmitDiagnostics();

comp = CreateCompilation(source, parseOptions: TestOptions.Regular12);
comp.VerifyEmitDiagnostics(
// (3,24): error CS8703: The modifier 'partial' is not valid for this item in C# 12.0. Please use language version 'preview' or greater.
// public partial int P { get; set; }
Diagnostic(ErrorCode.ERR_InvalidModifierForLanguageVersion, "P").WithArguments("partial", "12.0", "preview").WithLocation(3, 24),
// (4,24): error CS8703: The modifier 'partial' is not valid for this item in C# 12.0. Please use language version 'preview' or greater.
// public partial int P { get => 1; set { } }
Diagnostic(ErrorCode.ERR_InvalidModifierForLanguageVersion, "P").WithArguments("partial", "12.0", "preview").WithLocation(4, 24),
// (6,24): error CS8703: The modifier 'partial' is not valid for this item in C# 12.0. Please use language version 'preview' or greater.
// public partial int this[int i] { get; }
Diagnostic(ErrorCode.ERR_InvalidModifierForLanguageVersion, "this").WithArguments("partial", "12.0", "preview").WithLocation(6, 24),
// (7,24): error CS8703: The modifier 'partial' is not valid for this item in C# 12.0. Please use language version 'preview' or greater.
// public partial int this[int i] { get => i; }
Diagnostic(ErrorCode.ERR_InvalidModifierForLanguageVersion, "this").WithArguments("partial", "12.0", "preview").WithLocation(7, 24));
}

// PROTOTYPE(partial-properties): override partial property where base has modopt
}
}
Loading