Respond to PR feedback

上级 f2ac8cac
......@@ -589,18 +589,19 @@ private TypeSymbol BindTupleType(TupleTypeSyntax syntax, DiagnosticBag diagnosti
throw ExceptionUtilities.UnexpectedValue(typesArray.Length);
}
bool includeNullability = Compilation.IsFeatureEnabled(MessageID.IDS_FeatureNullableReferenceTypes);
return TupleTypeSymbol.Create(syntax.Location,
typesArray,
locationsArray,
elementNames == null ?
default(ImmutableArray<string>) :
elementNames.ToImmutableAndFree(),
this.Compilation,
this.ShouldCheckConstraints,
includeNullability: this.ShouldCheckConstraints,
errorPositions: default(ImmutableArray<bool>),
syntax: syntax,
diagnostics: diagnostics);
typesArray,
locationsArray,
elementNames == null ?
default(ImmutableArray<string>) :
elementNames.ToImmutableAndFree(),
this.Compilation,
this.ShouldCheckConstraints,
includeNullability: this.ShouldCheckConstraints && includeNullability,
errorPositions: default(ImmutableArray<bool>),
syntax: syntax,
diagnostics: diagnostics);
}
private static void CollectTupleFieldMemberName(string name, int elementIndex, int tupleSize, ref ArrayBuilder<string> elementNames)
......
......@@ -387,7 +387,7 @@ private bool FailsConstraintChecks(MethodSymbol method, out ArrayBuilder<TypePar
includeNullability: false,
this.Compilation,
diagnosticsBuilder,
nullabilityBuilderOpt: null,
nullabilityDiagnosticsBuilderOpt: null,
ref useSiteDiagnosticsBuilder);
if (!constraintsSatisfied)
......
......@@ -530,7 +530,6 @@ private static bool CheckConstraintsSingleType(TypeSymbol type, CheckConstraints
Compilation currentCompilation,
DiagnosticBag diagnosticsOpt,
DiagnosticBag nullabilityDiagnosticsOpt)
{
NamedTypeSymbol type = tuple.TupleUnderlyingType;
if (!RequiresChecking(type))
......@@ -559,17 +558,16 @@ private static bool CheckConstraintsSingleType(TypeSymbol type, CheckConstraints
diagnosticsBuilder.AddRange(useSiteDiagnosticsBuilder);
}
populateDiagnostics(diagnosticsBuilder, diagnosticsOpt);
populateDiagnostics(nullabilityDiagnosticsBuilder, nullabilityDiagnosticsOpt);
populateDiagnosticsAndClear(diagnosticsBuilder, diagnosticsOpt);
populateDiagnosticsAndClear(nullabilityDiagnosticsBuilder, nullabilityDiagnosticsOpt);
diagnosticsBuilder.Clear();
nullabilityDiagnosticsBuilder.Clear();
offset += TupleTypeSymbol.RestIndex;
void populateDiagnostics(ArrayBuilder<TypeParameterDiagnosticInfo> builder, DiagnosticBag bag)
void populateDiagnosticsAndClear(ArrayBuilder<TypeParameterDiagnosticInfo> builder, DiagnosticBag bag)
{
if (bag is null)
{
builder.Clear();
return;
}
......@@ -582,6 +580,8 @@ void populateDiagnostics(ArrayBuilder<TypeParameterDiagnosticInfo> builder, Diag
var location = ordinal == TupleTypeSymbol.RestIndex ? typeSyntax.Location : elementLocations[ordinal + offset];
bag.Add(new CSDiagnostic(pair.DiagnosticInfo, location));
}
builder.Clear();
}
}
......@@ -744,7 +744,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy
var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null;
var result = CheckMethodConstraints(method, conversions, includeNullability: false, currentCompilation, diagnosticsBuilder, nullabilityBuilderOpt: null, ref useSiteDiagnosticsBuilder);
var result = CheckMethodConstraints(method, conversions, includeNullability: false, currentCompilation, diagnosticsBuilder, nullabilityDiagnosticsBuilderOpt: null, ref useSiteDiagnosticsBuilder);
if (useSiteDiagnosticsBuilder != null)
{
......@@ -775,7 +775,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy
var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null;
var result = CheckMethodConstraints(method, conversions, includeNullability: false, currentCompilation, diagnosticsBuilder, nullabilityBuilderOpt: null, ref useSiteDiagnosticsBuilder);
var result = CheckMethodConstraints(method, conversions, includeNullability: false, currentCompilation, diagnosticsBuilder, nullabilityDiagnosticsBuilderOpt: null, ref useSiteDiagnosticsBuilder);
if (useSiteDiagnosticsBuilder != null)
{
......@@ -819,7 +819,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy
bool includeNullability,
Compilation currentCompilation,
ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder,
ArrayBuilder<TypeParameterDiagnosticInfo> nullabilityBuilderOpt,
ArrayBuilder<TypeParameterDiagnosticInfo> nullabilityDiagnosticsBuilderOpt,
ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder,
BitVector skipParameters = default(BitVector))
{
......@@ -832,7 +832,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy
method.TypeArguments,
currentCompilation,
diagnosticsBuilder,
nullabilityBuilderOpt,
nullabilityDiagnosticsBuilderOpt,
ref useSiteDiagnosticsBuilder,
skipParameters);
}
......
......@@ -53357,10 +53357,10 @@ class C {
string s1;
string? s2;
C c = new C();
(s1, s1) = (string.Empty, string.Empty);
(s2, s1) = ((string)null, string.Empty);
var v1 = (s2, s1) = ((string)null, string.Empty); // 1
var v2 = (s1, s1) = ((string)null, string.Empty); // 2
(s1, s1) = ("""", """");
(s2, s1) = ((string)null, """");
var v1 = (s2, s1) = ((string)null, """"); // 1
var v2 = (s1, s1) = ((string)null, """"); // 2
(s2, s1) = c;
(string? s3, string s4) = c;
var v2 = (s2, s1) = c; // 3
......@@ -53377,6 +53377,67 @@ class C {
);
}
[Fact]
[WorkItem(33303, "https://github.com/dotnet/roslyn/issues/33303")]
public void Constraints_79()
{
var source = @"
using System;
#nullable enable
#pragma warning disable 168
class C {
void TupleTypes() {
(string?, string) t1;
Type t2 = typeof((string?, string));
}
}
";
var compilation = CreateCompilation(new[] { Tuple2NonNullable, TupleRestNonNullable, source }, targetFramework: TargetFramework.Mscorlib46, parseOptions: TestOptions.Regular7_3, skipUsesIsNullable: true);
compilation.VerifyDiagnostics(
// (3,2): error CS8652: The feature 'nullable reference types' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// #nullable enable
Diagnostic(ErrorCode.ERR_FeatureInPreview, "nullable").WithArguments("nullable reference types").WithLocation(3, 2),
// (4,2): error CS8652: The feature 'nullable reference types' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// #nullable enable
Diagnostic(ErrorCode.ERR_FeatureInPreview, "nullable").WithArguments("nullable reference types").WithLocation(4, 2),
// (5,2): error CS8652: The feature 'nullable reference types' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// #nullable enable
Diagnostic(ErrorCode.ERR_FeatureInPreview, "nullable").WithArguments("nullable reference types").WithLocation(5, 2),
// (6,20): error CS8652: The feature 'object generic type constraint' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// where T1 : object
Diagnostic(ErrorCode.ERR_FeatureInPreview, "object").WithArguments("object generic type constraint").WithLocation(6, 20),
// (7,16): error CS8652: The feature 'nullable reference types' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// (string?, string) t1;
Diagnostic(ErrorCode.ERR_FeatureInPreview, "?").WithArguments("nullable reference types").WithLocation(7, 16),
// (7,20): error CS8652: The feature 'object generic type constraint' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// where T2 : object
Diagnostic(ErrorCode.ERR_FeatureInPreview, "object").WithArguments("object generic type constraint").WithLocation(7, 20),
// (8,20): error CS8652: The feature 'object generic type constraint' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// where T3 : object
Diagnostic(ErrorCode.ERR_FeatureInPreview, "object").WithArguments("object generic type constraint").WithLocation(8, 20),
// (8,20): error CS8652: The feature 'object generic type constraint' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// where T1 : object
Diagnostic(ErrorCode.ERR_FeatureInPreview, "object").WithArguments("object generic type constraint").WithLocation(8, 20),
// (8,33): error CS8652: The feature 'nullable reference types' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// Type t2 = typeof((string?, string));
Diagnostic(ErrorCode.ERR_FeatureInPreview, "?").WithArguments("nullable reference types").WithLocation(8, 33),
// (9,20): error CS8652: The feature 'object generic type constraint' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// where T4 : object
Diagnostic(ErrorCode.ERR_FeatureInPreview, "object").WithArguments("object generic type constraint").WithLocation(9, 20),
// (9,20): error CS8652: The feature 'object generic type constraint' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// where T2 : object
Diagnostic(ErrorCode.ERR_FeatureInPreview, "object").WithArguments("object generic type constraint").WithLocation(9, 20),
// (10,20): error CS8652: The feature 'object generic type constraint' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// where T5 : object
Diagnostic(ErrorCode.ERR_FeatureInPreview, "object").WithArguments("object generic type constraint").WithLocation(10, 20),
// (11,20): error CS8652: The feature 'object generic type constraint' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// where T6 : object
Diagnostic(ErrorCode.ERR_FeatureInPreview, "object").WithArguments("object generic type constraint").WithLocation(11, 20),
// (12,20): error CS8652: The feature 'object generic type constraint' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// where T7 : object
Diagnostic(ErrorCode.ERR_FeatureInPreview, "object").WithArguments("object generic type constraint").WithLocation(12, 20));
}
[Fact]
public void UnconstrainedTypeParameter_Local()
{
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册