Respond to PR feedback

上级 f2ac8cac
...@@ -589,18 +589,19 @@ private TypeSymbol BindTupleType(TupleTypeSyntax syntax, DiagnosticBag diagnosti ...@@ -589,18 +589,19 @@ private TypeSymbol BindTupleType(TupleTypeSyntax syntax, DiagnosticBag diagnosti
throw ExceptionUtilities.UnexpectedValue(typesArray.Length); throw ExceptionUtilities.UnexpectedValue(typesArray.Length);
} }
bool includeNullability = Compilation.IsFeatureEnabled(MessageID.IDS_FeatureNullableReferenceTypes);
return TupleTypeSymbol.Create(syntax.Location, return TupleTypeSymbol.Create(syntax.Location,
typesArray, typesArray,
locationsArray, locationsArray,
elementNames == null ? elementNames == null ?
default(ImmutableArray<string>) : default(ImmutableArray<string>) :
elementNames.ToImmutableAndFree(), elementNames.ToImmutableAndFree(),
this.Compilation, this.Compilation,
this.ShouldCheckConstraints, this.ShouldCheckConstraints,
includeNullability: this.ShouldCheckConstraints, includeNullability: this.ShouldCheckConstraints && includeNullability,
errorPositions: default(ImmutableArray<bool>), errorPositions: default(ImmutableArray<bool>),
syntax: syntax, syntax: syntax,
diagnostics: diagnostics); diagnostics: diagnostics);
} }
private static void CollectTupleFieldMemberName(string name, int elementIndex, int tupleSize, ref ArrayBuilder<string> elementNames) 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 ...@@ -387,7 +387,7 @@ private bool FailsConstraintChecks(MethodSymbol method, out ArrayBuilder<TypePar
includeNullability: false, includeNullability: false,
this.Compilation, this.Compilation,
diagnosticsBuilder, diagnosticsBuilder,
nullabilityBuilderOpt: null, nullabilityDiagnosticsBuilderOpt: null,
ref useSiteDiagnosticsBuilder); ref useSiteDiagnosticsBuilder);
if (!constraintsSatisfied) if (!constraintsSatisfied)
......
...@@ -530,7 +530,6 @@ private static bool CheckConstraintsSingleType(TypeSymbol type, CheckConstraints ...@@ -530,7 +530,6 @@ private static bool CheckConstraintsSingleType(TypeSymbol type, CheckConstraints
Compilation currentCompilation, Compilation currentCompilation,
DiagnosticBag diagnosticsOpt, DiagnosticBag diagnosticsOpt,
DiagnosticBag nullabilityDiagnosticsOpt) DiagnosticBag nullabilityDiagnosticsOpt)
{ {
NamedTypeSymbol type = tuple.TupleUnderlyingType; NamedTypeSymbol type = tuple.TupleUnderlyingType;
if (!RequiresChecking(type)) if (!RequiresChecking(type))
...@@ -559,17 +558,16 @@ private static bool CheckConstraintsSingleType(TypeSymbol type, CheckConstraints ...@@ -559,17 +558,16 @@ private static bool CheckConstraintsSingleType(TypeSymbol type, CheckConstraints
diagnosticsBuilder.AddRange(useSiteDiagnosticsBuilder); diagnosticsBuilder.AddRange(useSiteDiagnosticsBuilder);
} }
populateDiagnostics(diagnosticsBuilder, diagnosticsOpt); populateDiagnosticsAndClear(diagnosticsBuilder, diagnosticsOpt);
populateDiagnostics(nullabilityDiagnosticsBuilder, nullabilityDiagnosticsOpt); populateDiagnosticsAndClear(nullabilityDiagnosticsBuilder, nullabilityDiagnosticsOpt);
diagnosticsBuilder.Clear();
nullabilityDiagnosticsBuilder.Clear();
offset += TupleTypeSymbol.RestIndex; offset += TupleTypeSymbol.RestIndex;
void populateDiagnostics(ArrayBuilder<TypeParameterDiagnosticInfo> builder, DiagnosticBag bag) void populateDiagnosticsAndClear(ArrayBuilder<TypeParameterDiagnosticInfo> builder, DiagnosticBag bag)
{ {
if (bag is null) if (bag is null)
{ {
builder.Clear();
return; return;
} }
...@@ -582,6 +580,8 @@ void populateDiagnostics(ArrayBuilder<TypeParameterDiagnosticInfo> builder, Diag ...@@ -582,6 +580,8 @@ void populateDiagnostics(ArrayBuilder<TypeParameterDiagnosticInfo> builder, Diag
var location = ordinal == TupleTypeSymbol.RestIndex ? typeSyntax.Location : elementLocations[ordinal + offset]; var location = ordinal == TupleTypeSymbol.RestIndex ? typeSyntax.Location : elementLocations[ordinal + offset];
bag.Add(new CSDiagnostic(pair.DiagnosticInfo, location)); bag.Add(new CSDiagnostic(pair.DiagnosticInfo, location));
} }
builder.Clear();
} }
} }
...@@ -744,7 +744,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy ...@@ -744,7 +744,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy
var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance(); var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null; 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) if (useSiteDiagnosticsBuilder != null)
{ {
...@@ -775,7 +775,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy ...@@ -775,7 +775,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy
var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance(); var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null; 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) if (useSiteDiagnosticsBuilder != null)
{ {
...@@ -819,7 +819,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy ...@@ -819,7 +819,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy
bool includeNullability, bool includeNullability,
Compilation currentCompilation, Compilation currentCompilation,
ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder, ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder,
ArrayBuilder<TypeParameterDiagnosticInfo> nullabilityBuilderOpt, ArrayBuilder<TypeParameterDiagnosticInfo> nullabilityDiagnosticsBuilderOpt,
ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder, ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder,
BitVector skipParameters = default(BitVector)) BitVector skipParameters = default(BitVector))
{ {
...@@ -832,7 +832,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy ...@@ -832,7 +832,7 @@ private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<TypeSy
method.TypeArguments, method.TypeArguments,
currentCompilation, currentCompilation,
diagnosticsBuilder, diagnosticsBuilder,
nullabilityBuilderOpt, nullabilityDiagnosticsBuilderOpt,
ref useSiteDiagnosticsBuilder, ref useSiteDiagnosticsBuilder,
skipParameters); skipParameters);
} }
......
...@@ -53357,10 +53357,10 @@ class C { ...@@ -53357,10 +53357,10 @@ class C {
string s1; string s1;
string? s2; string? s2;
C c = new C(); C c = new C();
(s1, s1) = (string.Empty, string.Empty); (s1, s1) = ("""", """");
(s2, s1) = ((string)null, string.Empty); (s2, s1) = ((string)null, """");
var v1 = (s2, s1) = ((string)null, string.Empty); // 1 var v1 = (s2, s1) = ((string)null, """"); // 1
var v2 = (s1, s1) = ((string)null, string.Empty); // 2 var v2 = (s1, s1) = ((string)null, """"); // 2
(s2, s1) = c; (s2, s1) = c;
(string? s3, string s4) = c; (string? s3, string s4) = c;
var v2 = (s2, s1) = c; // 3 var v2 = (s2, s1) = c; // 3
...@@ -53377,6 +53377,67 @@ class C { ...@@ -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] [Fact]
public void UnconstrainedTypeParameter_Local() public void UnconstrainedTypeParameter_Local()
{ {
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册