diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 0f68d07ad5d5a..c94dda61344e8 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -864,14 +864,14 @@ Use of possibly unassigned auto-implemented property - - Field '{0}' must be fully assigned before control is returned to the caller + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. - - Field '{0}' must be fully assigned before control is returned to the caller + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another @@ -939,14 +939,14 @@ Use of default literal is not valid in this context - - The 'this' object cannot be used before all of its fields have been assigned + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. - - The 'this' object cannot be used before all of its fields have been assigned + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. The __arglist construct is valid only within a variable argument method @@ -2318,14 +2318,14 @@ If such a class is used as a base class and if the deriving class defines a dest Type of '{0}' cannot be inferred since its initializer directly or indirectly refers to the definition. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - An auto-implemented property must be fully assigned before control is returned to the caller. + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. @@ -6697,6 +6697,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ line span directive + + auto default struct fields + The #line directive value is missing or out of range @@ -6769,6 +6772,63 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ List patterns may not be used for a value of type '{0}'. No suitable 'Length' or 'Count' property was found. + + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Slice patterns may not be used for a value of type '{0}'. diff --git a/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs b/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs index 29ed8c74a05ca..1a2926bee89d8 100644 --- a/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs +++ b/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs @@ -1015,7 +1015,7 @@ private void CompileMethod( } var unusedDiagnostics = DiagnosticBag.GetInstance(); - DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, initializerStatements, unusedDiagnostics, requireOutParamsAssigned: false); + DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, initializerStatements, unusedDiagnostics, out _, requireOutParamsAssigned: false); DiagnosticsPass.IssueDiagnostics(_compilation, initializerStatements, BindingDiagnosticBag.Discarded, methodSymbol); unusedDiagnostics.Free(); } @@ -1077,7 +1077,7 @@ processedInitializers.AfterInitializersState is null && // Flow analysis over the initializers is necessary in order to find assignments to fields. // Bodies of implicit constructors do not get flow analysis later, so the initializers // are analyzed here. - DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, analyzedInitializers, diagsForCurrentMethod.DiagnosticBag, requireOutParamsAssigned: false); + DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, analyzedInitializers, diagsForCurrentMethod.DiagnosticBag, out _, requireOutParamsAssigned: false); } // In order to get correct diagnostics, we need to analyze initializers and the body together. @@ -1089,7 +1089,7 @@ processedInitializers.AfterInitializersState is null && { // These analyses check for diagnostics in lambdas. // Control flow analysis and implicit return insertion are unnecessary. - DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, analyzedInitializers, diagsForCurrentMethod.DiagnosticBag, requireOutParamsAssigned: false); + DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, analyzedInitializers, diagsForCurrentMethod.DiagnosticBag, out _, requireOutParamsAssigned: false); DiagnosticsPass.IssueDiagnostics(_compilation, analyzedInitializers, diagsForCurrentMethod, methodSymbol); } } @@ -1122,7 +1122,7 @@ processedInitializers.AfterInitializersState is null && BoundBlock flowAnalyzedBody = null; if (body != null) { - flowAnalyzedBody = FlowAnalysisPass.Rewrite(methodSymbol, body, diagsForCurrentMethod.DiagnosticBag, hasTrailingExpression: hasTrailingExpression, originalBodyNested: originalBodyNested); + flowAnalyzedBody = FlowAnalysisPass.Rewrite(methodSymbol, body, compilationState, diagsForCurrentMethod, hasTrailingExpression: hasTrailingExpression, originalBodyNested: originalBodyNested); } bool hasErrors = _hasDeclarationErrors || diagsForCurrentMethod.HasAnyErrors() || processedInitializers.HasErrors; diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index d0699be0ce7ec..72f6a8ebe968a 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -145,7 +145,7 @@ internal enum ErrorCode WRN_UnreferencedVar = 168, WRN_UnreferencedField = 169, ERR_UseDefViolationField = 170, - ERR_UnassignedThis = 171, + ERR_UnassignedThisUnsupportedVersion = 171, ERR_AmbigQM = 172, ERR_InvalidQM = 173, // Requires SymbolDistinguisher. ERR_NoBaseClass = 174, @@ -161,7 +161,7 @@ internal enum ErrorCode WRN_IsAlwaysFalse = 184, ERR_LockNeedsReference = 185, ERR_NullNotValid = 186, - ERR_UseDefViolationThis = 188, + ERR_UseDefViolationThisUnsupportedVersion = 188, ERR_ArgsInvalid = 190, ERR_AssgReadonly = 191, ERR_RefReadonly = 192, @@ -582,7 +582,7 @@ internal enum ErrorCode //ERR_AutoPropertiesMustHaveBothAccessors = 840, ERR_VariableUsedBeforeDeclaration = 841, //ERR_ExplicitLayoutAndAutoImplementedProperty = 842, - ERR_UnassignedThisAutoProperty = 843, + ERR_UnassignedThisAutoPropertyUnsupportedVersion = 843, ERR_VariableUsedBeforeDeclarationAndHidesField = 844, ERR_ExpressionTreeContainsBadCoalesce = 845, ERR_ArrayInitializerExpected = 846, @@ -1885,12 +1885,12 @@ internal enum ErrorCode // The following warnings correspond to errors of the same name, but are reported // when a definite assignment issue is reported due to private fields imported from metadata. - WRN_UnassignedThisAutoProperty = 8880, - WRN_UnassignedThis = 8881, + WRN_UnassignedThisAutoPropertyUnsupportedVersion = 8880, + WRN_UnassignedThisUnsupportedVersion = 8881, WRN_ParamUnassigned = 8882, WRN_UseDefViolationProperty = 8883, WRN_UseDefViolationField = 8884, - WRN_UseDefViolationThis = 8885, + WRN_UseDefViolationThisUnsupportedVersion = 8885, WRN_UseDefViolationOut = 8886, WRN_UseDefViolation = 8887, @@ -2051,6 +2051,17 @@ internal enum ErrorCode ERR_MisplacedRecord = 9012, ERR_PatternSpanCharCannotBeStringNull = 9013, + ERR_UseDefViolationPropertyUnsupportedVersion = 9014, + ERR_UseDefViolationFieldUnsupportedVersion = 9015, + WRN_UseDefViolationPropertyUnsupportedVersion = 9016, + WRN_UseDefViolationFieldUnsupportedVersion = 9017, + + WRN_UseDefViolationPropertySupportedVersion = 9018, + WRN_UseDefViolationFieldSupportedVersion = 9019, + WRN_UseDefViolationThisSupportedVersion = 9020, + WRN_UnassignedThisAutoPropertySupportedVersion = 9021, + WRN_UnassignedThisSupportedVersion = 9022, + #endregion // Note: you will need to re-generate compiler code after adding warnings (eng\generate-compiler-code.cmd) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index 137316a152edc..d427a18300a58 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -217,12 +217,14 @@ internal static int GetWarningLevel(ErrorCode code) case ErrorCode.WRN_NubExprIsConstBool2: case ErrorCode.WRN_StaticInAsOrIs: case ErrorCode.WRN_PrecedenceInversion: - case ErrorCode.WRN_UnassignedThisAutoProperty: - case ErrorCode.WRN_UnassignedThis: + case ErrorCode.WRN_UseDefViolationPropertyUnsupportedVersion: + case ErrorCode.WRN_UseDefViolationFieldUnsupportedVersion: + case ErrorCode.WRN_UnassignedThisAutoPropertyUnsupportedVersion: + case ErrorCode.WRN_UnassignedThisUnsupportedVersion: case ErrorCode.WRN_ParamUnassigned: case ErrorCode.WRN_UseDefViolationProperty: case ErrorCode.WRN_UseDefViolationField: - case ErrorCode.WRN_UseDefViolationThis: + case ErrorCode.WRN_UseDefViolationThisUnsupportedVersion: case ErrorCode.WRN_UseDefViolationOut: case ErrorCode.WRN_UseDefViolation: case ErrorCode.WRN_SyncAndAsyncEntryPoints: @@ -494,6 +496,11 @@ internal static int GetWarningLevel(ErrorCode code) case ErrorCode.WRN_InterpolatedStringHandlerArgumentAttributeIgnoredOnLambdaParameters: case ErrorCode.WRN_CompileTimeCheckedOverflow: case ErrorCode.WRN_MethGrpToNonDel: + case ErrorCode.WRN_UseDefViolationPropertySupportedVersion: + case ErrorCode.WRN_UseDefViolationFieldSupportedVersion: + case ErrorCode.WRN_UseDefViolationThisSupportedVersion: + case ErrorCode.WRN_UnassignedThisAutoPropertySupportedVersion: + case ErrorCode.WRN_UnassignedThisSupportedVersion: return 1; default: return 0; diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index d3385e7a1ab0d..be811f9f722e8 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -246,6 +246,7 @@ internal enum MessageID IDS_FeatureRawStringLiterals = MessageBase + 12817, IDS_FeatureSpanCharConstantPattern = MessageBase + 12818, IDS_FeatureDisposalPattern = MessageBase + 12819, + IDS_FeatureAutoDefaultStructs = MessageBase + 12820, } // Message IDs may refer to strings that need to be localized. @@ -363,6 +364,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature) case MessageID.IDS_FeatureCacheStaticMethodGroupConversion: // lowering check case MessageID.IDS_ParameterNullChecking: // syntax check case MessageID.IDS_FeatureSpanCharConstantPattern: + case MessageID.IDS_FeatureAutoDefaultStructs: // semantic check return LanguageVersion.Preview; // C# 10.0 features. diff --git a/src/Compilers/CSharp/Portable/Errors/MessageProvider.cs b/src/Compilers/CSharp/Portable/Errors/MessageProvider.cs index 7a470ff4bcff1..c718dbd8605e3 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageProvider.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageProvider.cs @@ -118,6 +118,15 @@ public override string GetErrorDisplayString(ISymbol symbol) return SymbolDisplay.ToDisplayString(symbol, SymbolDisplayFormat.CSharpShortErrorMessageFormat); } + public override bool GetIsEnabledByDefault(int code) => + (ErrorCode)code is not ( + ErrorCode.WRN_UseDefViolationPropertySupportedVersion + or ErrorCode.WRN_UseDefViolationFieldSupportedVersion + or ErrorCode.WRN_UseDefViolationThisSupportedVersion + or ErrorCode.WRN_UnassignedThisAutoPropertySupportedVersion + or ErrorCode.WRN_UnassignedThisSupportedVersion + ); + public override ReportDiagnostic GetDiagnosticReport(DiagnosticInfo diagnosticInfo, CompilationOptions options) { bool hasPragmaSuppression; diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs index 45e47e130cc92..be4124bb79e00 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs @@ -81,6 +81,29 @@ internal partial class DefiniteAssignmentPass : LocalDataFlowPass< /// private readonly PooledHashSet _writtenVariables = PooledHashSet.GetInstance(); + /// + /// Struct fields that are implicitly initialized, due to being used before being written, or not being written at an exit point. + /// + private PooledHashSet? _implicitlyInitializedFieldsOpt; + + private void AddImplicitlyInitializedField(FieldSymbol field) + { + if (TrackImplicitlyInitializedFields) + { + (_implicitlyInitializedFieldsOpt ??= PooledHashSet.GetInstance()).Add(field); + } + } + + private bool TrackImplicitlyInitializedFields + { + get + { + return _requireOutParamsAssigned + && !this._emptyStructTypeCache._dev12CompilerCompatibility + && CurrentSymbol is MethodSymbol { MethodKind: MethodKind.Constructor, ContainingType.TypeKind: TypeKind.Struct }; + } + } + /// /// Map from variables that had their addresses taken, to the location of the first corresponding /// address-of expression. @@ -230,6 +253,7 @@ protected override void Free() _variableSlot.Free(); _usedVariables.Free(); _readParameters?.Free(); + _implicitlyInitializedFieldsOpt?.Free(); _usedLocalFunctions.Free(); _writtenVariables.Free(); _capturedVariables.Free(); @@ -431,14 +455,24 @@ protected virtual void ReportUnassignedOutParameter(ParameterSymbol parameter, S if (fieldSlot == -1 || !this.State.IsAssigned(fieldSlot)) { Symbol associatedPropertyOrEvent = field.AssociatedSymbol; - if (associatedPropertyOrEvent?.Kind == SymbolKind.Property) + bool hasAssociatedProperty = associatedPropertyOrEvent?.Kind == SymbolKind.Property; + if (compilation.IsFeatureEnabled(MessageID.IDS_FeatureAutoDefaultStructs)) { - Diagnostics.Add(ErrorCode.ERR_UnassignedThisAutoProperty, location, associatedPropertyOrEvent); + Diagnostics.Add( + hasAssociatedProperty ? ErrorCode.WRN_UnassignedThisAutoPropertySupportedVersion : ErrorCode.WRN_UnassignedThisSupportedVersion, + location, + hasAssociatedProperty ? associatedPropertyOrEvent : field); } else { - Diagnostics.Add(ErrorCode.ERR_UnassignedThis, location, field); + Diagnostics.Add( + hasAssociatedProperty ? ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion : ErrorCode.ERR_UnassignedThisUnsupportedVersion, + location, + hasAssociatedProperty ? associatedPropertyOrEvent : field, + new CSharpRequiredLanguageVersion(MessageID.IDS_FeatureAutoDefaultStructs.RequiredVersion())); } + + this.AddImplicitlyInitializedField(field); } } reported = true; @@ -461,22 +495,24 @@ public static void Analyze( MethodSymbol member, BoundNode node, DiagnosticBag diagnostics, - bool requireOutParamsAssigned = true) + out ImmutableArray implicitlyInitializedFieldsOpt, + bool requireOutParamsAssigned) { Debug.Assert(diagnostics != null); // Run the strongest version of analysis - DiagnosticBag strictDiagnostics = analyze(strictAnalysis: true); - if (strictDiagnostics.IsEmptyWithoutResolution) + (DiagnosticBag strictDiagnostics, implicitlyInitializedFieldsOpt) = analyze(strictAnalysis: true); + if (!strictDiagnostics.HasAnyErrors()) { - // If it reports nothing, there is nothing to report and we are done. - strictDiagnostics.Free(); + // if we have no diagnostics or only warning-level diagnostics, we know we don't need to run the compat analysis. + diagnostics.AddRangeAndFree(strictDiagnostics); return; } // Also run the compat (weaker) version of analysis to see if we get the same diagnostics. // If any are missing, the extra ones from the strong analysis will be downgraded to a warning. - DiagnosticBag compatDiagnostics = analyze(strictAnalysis: false); + (DiagnosticBag compatDiagnostics, var unused) = analyze(strictAnalysis: false); + Debug.Assert(unused.IsDefault); // If the compat diagnostics caused a stack overflow, the two analyses might not produce comparable sets of diagnostics. // So we just report the compat ones including that error. @@ -513,14 +549,16 @@ public static void Analyze( ErrorCode newCode = oldCode switch { #pragma warning disable format - ErrorCode.ERR_UnassignedThisAutoProperty => ErrorCode.WRN_UnassignedThisAutoProperty, - ErrorCode.ERR_UnassignedThis => ErrorCode.WRN_UnassignedThis, - ErrorCode.ERR_ParamUnassigned => ErrorCode.WRN_ParamUnassigned, - ErrorCode.ERR_UseDefViolationProperty => ErrorCode.WRN_UseDefViolationProperty, - ErrorCode.ERR_UseDefViolationField => ErrorCode.WRN_UseDefViolationField, - ErrorCode.ERR_UseDefViolationThis => ErrorCode.WRN_UseDefViolationThis, - ErrorCode.ERR_UseDefViolationOut => ErrorCode.WRN_UseDefViolationOut, - ErrorCode.ERR_UseDefViolation => ErrorCode.WRN_UseDefViolation, + ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion => ErrorCode.WRN_UnassignedThisAutoPropertyUnsupportedVersion, + ErrorCode.ERR_UnassignedThisUnsupportedVersion => ErrorCode.WRN_UnassignedThisUnsupportedVersion, + ErrorCode.ERR_ParamUnassigned => ErrorCode.WRN_ParamUnassigned, + ErrorCode.ERR_UseDefViolationProperty => ErrorCode.WRN_UseDefViolationProperty, + ErrorCode.ERR_UseDefViolationField => ErrorCode.WRN_UseDefViolationField, + ErrorCode.ERR_UseDefViolationThisUnsupportedVersion => ErrorCode.WRN_UseDefViolationThisUnsupportedVersion, + ErrorCode.ERR_UseDefViolationPropertyUnsupportedVersion => ErrorCode.WRN_UseDefViolationPropertyUnsupportedVersion, + ErrorCode.ERR_UseDefViolationFieldUnsupportedVersion => ErrorCode.WRN_UseDefViolationFieldUnsupportedVersion, + ErrorCode.ERR_UseDefViolationOut => ErrorCode.WRN_UseDefViolationOut, + ErrorCode.ERR_UseDefViolation => ErrorCode.WRN_UseDefViolation, _ => oldCode, // rare but possible, e.g. ErrorCode.ERR_InsufficientStack occurring in strict mode only due to needing extra frames #pragma warning restore format }; @@ -535,9 +573,10 @@ public static void Analyze( strictDiagnostics.Free(); return; - DiagnosticBag analyze(bool strictAnalysis) + (DiagnosticBag, ImmutableArray implicitlyInitializedFieldsOpt) analyze(bool strictAnalysis) { DiagnosticBag result = DiagnosticBag.GetInstance(); + ImmutableArray implicitlyInitializedFieldsOpt = default; var walker = new DefiniteAssignmentPass( compilation, member, @@ -550,6 +589,18 @@ DiagnosticBag analyze(bool strictAnalysis) { bool badRegion = false; walker.Analyze(ref badRegion, result); + if (walker._implicitlyInitializedFieldsOpt is { } implicitlyInitializedFields) + { + Debug.Assert(walker.TrackImplicitlyInitializedFields); + var builder = ArrayBuilder.GetInstance(implicitlyInitializedFields.Count); + foreach (var field in implicitlyInitializedFields) + { + builder.Add(field); + } + builder.Sort(LexicalOrderSymbolComparer.Instance); + implicitlyInitializedFieldsOpt = builder.ToImmutableAndFree(); + } + Debug.Assert(!badRegion); } catch (BoundTreeVisitor.CancelledByStackGuardException ex) when (diagnostics != null) @@ -561,9 +612,11 @@ DiagnosticBag analyze(bool strictAnalysis) walker.Free(); } - return result; + Debug.Assert(strictAnalysis || implicitlyInitializedFieldsOpt.IsDefault); + return (result, implicitlyInitializedFieldsOpt); } } +#nullable disable private sealed class SameDiagnosticComparer : EqualityComparer { @@ -1104,44 +1157,129 @@ protected virtual void ReportUnassigned(Symbol symbol, SyntaxNode node, int slot // CONSIDER: could suppress this diagnostic in cases where the local was declared in a using // or fixed statement because there's a special error code for not initializing those. - ErrorCode errorCode; string symbolName = symbol.Name; if (symbol.Kind == SymbolKind.Field) { - var fieldSymbol = (FieldSymbol)symbol; - var associatedSymbol = fieldSymbol.AssociatedSymbol; - if (associatedSymbol?.Kind == SymbolKind.Property) - { - errorCode = ErrorCode.ERR_UseDefViolationProperty; - symbolName = associatedSymbol.Name; - } - else - { - errorCode = ErrorCode.ERR_UseDefViolationField; - } + addDiagnosticForStructField(slot, (FieldSymbol)symbol); } else if (symbol.Kind == SymbolKind.Parameter && ((ParameterSymbol)symbol).RefKind == RefKind.Out) { if (((ParameterSymbol)symbol).IsThis) { - errorCode = ErrorCode.ERR_UseDefViolationThis; + addDiagnosticForStructThis(symbol, slot); } else { - errorCode = ErrorCode.ERR_UseDefViolationOut; + Diagnostics.Add(ErrorCode.ERR_UseDefViolationOut, node.Location, symbolName); } } else { - errorCode = ErrorCode.ERR_UseDefViolation; + Diagnostics.Add(ErrorCode.ERR_UseDefViolation, node.Location, symbolName); } - Diagnostics.Add(errorCode, new SourceLocation(node), symbolName); } // mark the variable's slot so that we don't complain about the variable again _alreadyReported[slot] = true; + + return; + + void addDiagnosticForStructThis(Symbol thisParameter, int thisSlot) + { + Debug.Assert(CurrentSymbol is MethodSymbol { MethodKind: MethodKind.Constructor, ContainingType.TypeKind: TypeKind.Struct }); + if (TrackImplicitlyInitializedFields) + { +#if DEBUG + bool foundUnassignedField = false; +#endif + foreach (var field in _emptyStructTypeCache.GetStructInstanceFields(thisParameter.ContainingType)) + { + if (_emptyStructTypeCache.IsEmptyStructType(field.Type)) + continue; + + if (field is TupleErrorFieldSymbol) + continue; + + int slot = VariableSlot(field, thisSlot); + if (slot == -1 || !State.IsAssigned(slot)) + { + AddImplicitlyInitializedField(field); +#if DEBUG + foundUnassignedField = true; +#endif + } + } + +#if DEBUG + Debug.Assert(foundUnassignedField); +#endif + } + + if (compilation.IsFeatureEnabled(MessageID.IDS_FeatureAutoDefaultStructs)) + { + Diagnostics.Add(ErrorCode.WRN_UseDefViolationThisSupportedVersion, node.Location, thisParameter.Name); + } + else + { + Diagnostics.Add( + ErrorCode.ERR_UseDefViolationThisUnsupportedVersion, + node.Location, + thisParameter.Name, + new CSharpRequiredLanguageVersion(MessageID.IDS_FeatureAutoDefaultStructs.RequiredVersion())); + } + } + + void addDiagnosticForStructField(int fieldSlot, FieldSymbol fieldSymbol) + { + var associatedSymbol = fieldSymbol.AssociatedSymbol; + var hasAssociatedProperty = associatedSymbol?.Kind == SymbolKind.Property; + var symbolName = hasAssociatedProperty ? associatedSymbol.Name : fieldSymbol.Name; + if (CurrentSymbol is not MethodSymbol { MethodKind: MethodKind.Constructor, ContainingType.TypeKind: TypeKind.Struct }) + { + Diagnostics.Add(hasAssociatedProperty ? ErrorCode.ERR_UseDefViolationProperty : ErrorCode.ERR_UseDefViolationField, node.Location, symbolName); + return; + } + + var thisSlot = GetOrCreateSlot(CurrentSymbol.EnclosingThisSymbol()); + while (true) + { + if (fieldSlot == 0) + { + // the offending field access is not contained in 'this'. + Diagnostics.Add(hasAssociatedProperty ? ErrorCode.ERR_UseDefViolationProperty : ErrorCode.ERR_UseDefViolationField, node.Location, symbolName); + return; + } + + var fieldIdentifier = variableBySlot[fieldSlot]; + var containingSlot = fieldIdentifier.ContainingSlot; + if (containingSlot == thisSlot) + { + // should we handle nested fields here? https://github.com/dotnet/roslyn/issues/59890 + AddImplicitlyInitializedField((FieldSymbol)fieldIdentifier.Symbol); + + if (compilation.IsFeatureEnabled(MessageID.IDS_FeatureAutoDefaultStructs)) + { + Diagnostics.Add( + hasAssociatedProperty ? ErrorCode.WRN_UseDefViolationPropertySupportedVersion : ErrorCode.WRN_UseDefViolationFieldSupportedVersion, + node.Location, + symbolName); + } + else + { + Diagnostics.Add( + hasAssociatedProperty ? ErrorCode.ERR_UseDefViolationPropertyUnsupportedVersion : ErrorCode.ERR_UseDefViolationFieldUnsupportedVersion, + node.Location, + symbolName, + new CSharpRequiredLanguageVersion(MessageID.IDS_FeatureAutoDefaultStructs.RequiredVersion())); + } + return; + } + + fieldSlot = containingSlot; + } + } } protected virtual void CheckAssigned(BoundExpression expr, FieldSymbol fieldSymbol, SyntaxNode node) diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/EmptyStructTypeCache.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/EmptyStructTypeCache.cs index de42811ccdb6d..8a09d4519c02a 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/EmptyStructTypeCache.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/EmptyStructTypeCache.cs @@ -27,7 +27,7 @@ internal class EmptyStructTypeCache /// /// When set, we ignore private reference fields of structs loaded from metadata. /// - private readonly bool _dev12CompilerCompatibility; + internal readonly bool _dev12CompilerCompatibility; private readonly SourceAssemblySymbol _sourceAssembly; diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/FlowAnalysisPass.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/FlowAnalysisPass.cs index a0ea235df7f6e..448f67ca6deb5 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/FlowAnalysisPass.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/FlowAnalysisPass.cs @@ -22,6 +22,7 @@ internal class FlowAnalysisPass /// /// the method to be analyzed /// the method's body + /// The state of compilation of the enclosing type /// the receiver of the reported diagnostics /// indicates whether this Script had a trailing expression /// the original method body is the last statement in the block @@ -29,28 +30,41 @@ internal class FlowAnalysisPass public static BoundBlock Rewrite( MethodSymbol method, BoundBlock block, - DiagnosticBag diagnostics, + TypeCompilationState compilationState, + BindingDiagnosticBag diagnostics, bool hasTrailingExpression, bool originalBodyNested) { #if DEBUG // We should only see a trailingExpression if we're in a Script initializer. Debug.Assert(!hasTrailingExpression || method.IsScriptInitializer); - var initialDiagnosticCount = diagnostics.ToReadOnly().Length; + var initialDiagnosticCount = diagnostics.ToReadOnly().Diagnostics.Length; #endif var compilation = method.DeclaringCompilation; if (method.ReturnsVoid || method.IsIterator || method.IsAsyncEffectivelyReturningTask(compilation)) { + ImmutableArray implicitlyInitializedFields = default; + bool needsImplicitReturn = true; // we don't analyze synthesized void methods. if ((method.IsImplicitlyDeclared && !method.IsScriptInitializer) || - Analyze(compilation, method, block, diagnostics)) + Analyze(compilation, method, block, diagnostics.DiagnosticBag, out needsImplicitReturn, out implicitlyInitializedFields)) { - block = AppendImplicitReturn(block, method, originalBodyNested); + if (!implicitlyInitializedFields.IsDefault) + { + Debug.Assert(!implicitlyInitializedFields.IsEmpty); + block = PrependImplicitInitializations(block, method, implicitlyInitializedFields, compilationState, diagnostics); + } + if (needsImplicitReturn) + { + block = AppendImplicitReturn(block, method, originalBodyNested); + } } } - else if (Analyze(compilation, method, block, diagnostics)) + else if (Analyze(compilation, method, block, diagnostics.DiagnosticBag, out var needsImplicitReturn, out var unusedImplicitlyInitializedFields)) { + Debug.Assert(unusedImplicitlyInitializedFields.IsDefault); + Debug.Assert(needsImplicitReturn); // If the method is a lambda expression being converted to a non-void delegate type // and the end point is reachable then suppress the error here; a special error // will be reported by the lambda binder. @@ -70,9 +84,10 @@ public static BoundBlock Rewrite( // return in cases where one was missing should never produce different Diagnostics. IEnumerable getErrorsOnly(IEnumerable diags) => diags.Where(d => d.Severity == DiagnosticSeverity.Error); var flowAnalysisDiagnostics = DiagnosticBag.GetInstance(); - Debug.Assert(!Analyze(compilation, method, block, flowAnalysisDiagnostics)); + Debug.Assert(!Analyze(compilation, method, block, flowAnalysisDiagnostics, needsImplicitReturn: out _, out unusedImplicitlyInitializedFields)); + Debug.Assert(unusedImplicitlyInitializedFields.IsDefault); // Ignore warnings since flow analysis reports nullability mismatches. - Debug.Assert(getErrorsOnly(flowAnalysisDiagnostics.ToReadOnly()).SequenceEqual(getErrorsOnly(diagnostics.ToReadOnly().Skip(initialDiagnosticCount)))); + Debug.Assert(getErrorsOnly(flowAnalysisDiagnostics.ToReadOnly()).SequenceEqual(getErrorsOnly(diagnostics.ToReadOnly().Diagnostics.Skip(initialDiagnosticCount)))); flowAnalysisDiagnostics.Free(); #endif } @@ -87,6 +102,28 @@ public static BoundBlock Rewrite( return block; } + private static BoundBlock PrependImplicitInitializations(BoundBlock body, MethodSymbol method, ImmutableArray implicitlyInitializedFields, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics) + { + Debug.Assert(method.MethodKind == MethodKind.Constructor); + Debug.Assert(method.ContainingType.IsStructType()); + + var syntax = body.Syntax; + var F = new SyntheticBoundNodeFactory(method, syntax, compilationState, diagnostics); + + var builder = ArrayBuilder.GetInstance(implicitlyInitializedFields.Length + 1); + foreach (var field in implicitlyInitializedFields) + { + builder.Add(new BoundExpressionStatement( + syntax, + F.AssignmentExpression( + F.Field(F.This(), field), + F.Default(field.Type)))); + } + builder.Add(body); + + return BoundBlock.SynthesizedNoLocals(syntax, builder.ToImmutableAndFree()); + } + private static BoundBlock AppendImplicitReturn(BoundBlock body, MethodSymbol method, bool originalBodyNested) { if (originalBodyNested) @@ -133,11 +170,13 @@ private static bool Analyze( CSharpCompilation compilation, MethodSymbol method, BoundBlock block, - DiagnosticBag diagnostics) + DiagnosticBag diagnostics, + out bool needsImplicitReturn, + out ImmutableArray implicitlyInitializedFieldsOpt) { - var result = ControlFlowPass.Analyze(compilation, method, block, diagnostics); - DefiniteAssignmentPass.Analyze(compilation, method, block, diagnostics); - return result; + needsImplicitReturn = ControlFlowPass.Analyze(compilation, method, block, diagnostics); + DefiniteAssignmentPass.Analyze(compilation, method, block, diagnostics, out implicitlyInitializedFieldsOpt, requireOutParamsAssigned: true); + return needsImplicitReturn || !implicitlyInitializedFieldsOpt.IsDefault; } } } diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index 7c0fe97b4ecca..361d786c0b24a 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -875,9 +875,12 @@ bool needsDefaultInitialStateForMembers() return false; } - // We don't use a default initial state for value type instance constructors without `: this()` because - // any usages of uninitialized fields will get definite assignment errors anyway. - if (!method.HasThisConstructorInitializer(out _) && (!method.ContainingType.IsValueType || method.IsStatic)) + // Pre-C# 11, we don't use a default initial state for value type instance constructors without `: this()` + // because any usages of uninitialized fields will get definite assignment errors anyway. + if (!method.HasThisConstructorInitializer(out _) + && (!method.ContainingType.IsValueType + || method.IsStatic + || compilation.IsFeatureEnabled(MessageID.IDS_FeatureAutoDefaultStructs))) { return true; } diff --git a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs index ea9c801ae3cbb..f4b635dc89759 100644 --- a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs @@ -256,12 +256,12 @@ public static bool IsWarning(ErrorCode code) case ErrorCode.WRN_AnalyzerReferencesFramework: case ErrorCode.WRN_RecordEqualsWithoutGetHashCode: case ErrorCode.WRN_RecordNamedDisallowed: - case ErrorCode.WRN_UnassignedThisAutoProperty: - case ErrorCode.WRN_UnassignedThis: + case ErrorCode.WRN_UnassignedThisAutoPropertyUnsupportedVersion: + case ErrorCode.WRN_UnassignedThisUnsupportedVersion: case ErrorCode.WRN_ParamUnassigned: case ErrorCode.WRN_UseDefViolationProperty: case ErrorCode.WRN_UseDefViolationField: - case ErrorCode.WRN_UseDefViolationThis: + case ErrorCode.WRN_UseDefViolationThisUnsupportedVersion: case ErrorCode.WRN_UseDefViolationOut: case ErrorCode.WRN_UseDefViolation: case ErrorCode.WRN_SyncAndAsyncEntryPoints: @@ -282,6 +282,13 @@ public static bool IsWarning(ErrorCode code) case ErrorCode.WRN_LowerCaseTypeName: case ErrorCode.WRN_NullCheckedHasDefaultNull: case ErrorCode.WRN_NullCheckingOnNullableType: + case ErrorCode.WRN_UseDefViolationPropertyUnsupportedVersion: + case ErrorCode.WRN_UseDefViolationFieldUnsupportedVersion: + case ErrorCode.WRN_UseDefViolationPropertySupportedVersion: + case ErrorCode.WRN_UseDefViolationFieldSupportedVersion: + case ErrorCode.WRN_UseDefViolationThisSupportedVersion: + case ErrorCode.WRN_UnassignedThisAutoPropertySupportedVersion: + case ErrorCode.WRN_UnassignedThisSupportedVersion: return true; default: return false; diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 799607d1d100d..427f46897785a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -1347,6 +1347,16 @@ Aby se typ {0} dal použít jako konvence volání, musí být veřejný. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. {0} má atribut UnmanagedCallersOnly a nedá se volat napřímo. Pro tuto metodu získejte ukazatel na funkci. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Očekával se obecný návratový typ podobný úloze, ale typ {0} nalezený v atributu AsyncMethodBuilder nebyl vhodný. Musí se jednat o nevázaný obecný typ arity a jeho nadřazený typ (pokud existuje) nesmí být obecný. @@ -1392,6 +1417,11 @@ přepsání tvůrce asynchronní metody + + auto default struct fields + auto default struct fields + + covariant returns kovariantní návratové hodnoty @@ -3566,24 +3596,44 @@ Parametr typu má stejný typ jako parametr typu z vnější metody. - - Field '{0}' must be fully assigned before control is returned to the caller - Před předáním řízení volající proceduře musí být pole {0} plně přiřazené. + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Před vrácením řízení volajícímu modulu musí být plně přiřazená automaticky implementovaná vlastnost {0}. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - Před vrácením řízení volajícímu se musí plně přiřadit automaticky implementovaná vlastnost + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - Před vrácením řízení volajícímu se musí v konstruktoru plně přiřadit pole struktury + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ Použila se možná nepřiřazené pole {0}. + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field Použilo se pravděpodobně nepřiřazené pole @@ -3666,19 +3736,49 @@ Použití pravděpodobně nepřiřazené automaticky implementované vlastnosti {0} + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property Použily se pravděpodobně nepřiřazené automaticky implementované vlastnosti - - The 'this' object cannot be used before all of its fields have been assigned - Objekt this se nedá použít, dokud se nepřiřadí všechna jeho pole. + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - Objekt this se v konstruktoru nedá použít, dokud se nepřiřadí všechna jeho pole + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ Použití pravděpodobně nepřiřazené automaticky implementované vlastnosti {0} - - Field '{0}' must be fully assigned before control is returned to the caller - Před předáním řízení volající proceduře musí být pole {0} plně přiřazené. - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another Typ podmíněného výrazu nejde určit, protože {0} a {1} se implicitně převádějí jeden na druhého. @@ -4551,11 +4646,6 @@ Použití výchozího literálu není v tomto kontextu platné. - - The 'this' object cannot be used before all of its fields have been assigned - Objekt this se nedá použít, dokud se nepřiřadí všechna jeho pole. - - The __arglist construct is valid only within a variable argument method Konstrukce __arglist je platná jenom v rámci metody s proměnnými argumenty. @@ -6705,11 +6795,6 @@ Pokud se taková třída používá jako základní třída a pokud odvozující Typ pro {0} nejde odvodit, protože jeho inicializátor přímo nebo nepřímo odkazuje na definici. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Před vrácením řízení volajícímu modulu musí být plně přiřazená automaticky implementovaná vlastnost {0}. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. Lokální proměnnou {0} nejde použít dřív, než je deklarovaná. Deklarace lokální proměnné skryje pole {1}. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index ed17a8c2a6b3e..00832568f60ca 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -1347,6 +1347,16 @@ Der Typ "{0}" muss öffentlich sein, damit er als Aufrufkonvention verwendet werden kann. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. "{0}" ist mit dem Attribut "UnmanagedCallersOnly" versehen und kann nicht direkt aufgerufen werden. Rufen Sie einen Funktionszeiger auf diese Methode ab. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Ein generischer aufgabenähnlicher Rückgabetyp wurde erwartet, aber der Typ „{0}“, der im Attribut „AsyncMethodBuilder“ gefunden wurde, war nicht geeignet. Es muss sich um einen ungebundenen generischen Typ von Stelligkeit Eins handelt, und der enthaltende Typ (falls vorhanden) muss nicht generisch sein. @@ -1392,6 +1417,11 @@ Außerkraftsetzung des asynchronen Methoden-Generators + + auto default struct fields + auto default struct fields + + covariant returns Covariante Rückgaben @@ -3566,24 +3596,44 @@ Der Typparameter und der Typparameter der äußeren Methode weisen denselben Typ auf. - - Field '{0}' must be fully assigned before control is returned to the caller - Das Feld "{0}" muss vollständig zugewiesen werden, bevor die Steuerung wieder an den Aufrufer übergeben wird. + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Die automatisch implementierte Eigenschaft "{0}" muss vollständig zugewiesen werden, bevor das Steuerelement an den Aufrufer zurückgegeben wird. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - Eine automatisch implementierte Eigenschaft muss vollständig zugewiesen sein, bevor die Steuerung an den Aufrufer zurückgegeben wird. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - Felder einer Struktur müssen in einem Konstruktor vollständig zugewiesen sein, bevor die Steuerung an den Aufrufer zurückgegeben wird + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ Verwendung des möglicherweise nicht zugewiesenen Felds "{0}". + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field Verwendung eines möglicherweise nicht zugewiesenen Felds @@ -3666,19 +3736,49 @@ Verwenden einer möglicherweise nicht zugewiesenen, automatisch implementierten Eigenschaft "{0}" + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property Verwenden einer möglicherweise nicht zugewiesenen, automatisch implementierten Eigenschaft - - The 'this' object cannot be used before all of its fields have been assigned - Das this-Objekt kann erst verwendet werden, wenn alle zugehörigen Felder zugewiesen wurden. + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - Das this-Objekt kann erst in einem Konstruktor verwendet werden, wenn alle Felder zugewiesen wurden + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ Verwenden einer möglicherweise nicht zugewiesenen, automatisch implementierten Eigenschaft "{0}" - - Field '{0}' must be fully assigned before control is returned to the caller - Das Feld "{0}" muss vollständig zugewiesen werden, bevor die Steuerung wieder an den Aufrufer übergeben wird. - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another Der Typ des bedingten Ausdrucks kann nicht bestimmt werden, da "{0}" und "{1}" implizit ineinander konvertiert werden. @@ -4551,11 +4646,6 @@ Die Verwendung des Standardliterals ist in diesem Kontext nicht gültig. - - The 'this' object cannot be used before all of its fields have been assigned - Das this-Objekt kann erst verwendet werden, wenn alle zugehörigen Felder zugewiesen wurden. - - The __arglist construct is valid only within a variable argument method Das __arglist-Konstrukt ist nur innerhalb einer Variablenargumentmethode gültig. @@ -6705,11 +6795,6 @@ Wenn solch eine Klasse als Basisklasse verwendet wird und die ableitende Klasse Der Typ von "{0}" kann nicht abgeleitet werden, da der Initialisierer direkt oder indirekt auf die Definition verweist. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Die automatisch implementierte Eigenschaft "{0}" muss vollständig zugewiesen werden, bevor das Steuerelement an den Aufrufer zurückgegeben wird. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. Die lokale Variable "{0}" kann erst verwendet werden, nachdem sie deklariert wurde. Bei der Deklaration der lokalen Variablen wird das Feld "{1}" verborgen. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 8fa2ef07d34cb..135a7bcf92995 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -1347,6 +1347,16 @@ El tipo "{0}" debe ser público para poder usarlo como convención de llamada. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. "{0}" tiene un atributo "UnmanagedCallersOnly" y no se le puede llamar directamente. Obtenga un puntero de función a este método. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Se esperaba un tipo de valor devuelto genérico similar a una tarea, pero el tipo "{0}" encontrado en el atributo "AsyncMethodBuilder" no era adecuado. Debe ser un tipo genérico independiente de aridad uno y su tipo contenedor (si existe) debe ser no genérico. @@ -1392,6 +1417,11 @@ invalidación del generador de métodos asincrónicos + + auto default struct fields + auto default struct fields + + covariant returns valores devueltos de covariante @@ -3566,24 +3596,44 @@ El parámetro de tipo tiene el mismo tipo que el parámetro de tipo del método externo. - - Field '{0}' must be fully assigned before control is returned to the caller - El campo '{0}' debe estar totalmente asignado antes de que se devuelva el control al llamador + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - La propiedad '{0}' implementada automáticamente se debe asignar completamente antes de devolver el control al llamador. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - Una propiedad implementada automáticamente debe estar totalmente asignada antes de devolver el control al llamador. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - Los campos de una estructura deben estar totalmente asignados en un constructor antes de devolver el control al llamador + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ Uso del campo '{0}' posiblemente sin asignar + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field Uso de un campo posiblemente sin asignar @@ -3666,19 +3736,49 @@ Uso de una propiedad implementada automáticamente posiblemente sin asignar '{0}' + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property Uso de una propiedad implementada automáticamente posiblemente sin asignar - - The 'this' object cannot be used before all of its fields have been assigned - El objeto "this" no se puede utilizar antes de que se hayan asignado todos sus campos + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - No se puede usar el objeto "this" en un constructor antes de que se hayan asignado todos sus campos + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ Uso de una propiedad implementada automáticamente posiblemente sin asignar '{0}' - - Field '{0}' must be fully assigned before control is returned to the caller - El campo '{0}' debe estar totalmente asignado antes de que se devuelva el control al llamador - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another No se puede determinar el tipo de expresión condicional porque '{0}' y '{1}' se convierten implícitamente uno en el otro @@ -4551,11 +4646,6 @@ El uso del literal predeterminado no es válido en este contexto. - - The 'this' object cannot be used before all of its fields have been assigned - El objeto "this" no se puede utilizar antes de que se hayan asignado todos sus campos - - The __arglist construct is valid only within a variable argument method La construcción __arglist solo es válida dentro de un método de argumento de variable @@ -6705,11 +6795,6 @@ Si se utiliza una clase de este tipo como clase base y si la clase derivada defi El tipo de '{0}' no se puede inferir porque su inicializador hace referencia, directa o indirectamente, a la definición. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - La propiedad '{0}' implementada automáticamente se debe asignar completamente antes de devolver el control al llamador. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. No se puede usar la variable local '{0}' antes de declararla. La declaración de la variable local oculta el campo '{1}'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index d6f7eff7f9d66..a761eede90b24 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -1347,6 +1347,16 @@ Le type '{0}' doit être public pour être utilisé comme convention d'appel. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. '{0}' est attribué avec 'UnmanagedCallersOnly' et ne peut pas être appelé directement. Obtenez un pointeur de fonction vers cette méthode. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Un type de retour de type tâche générique est attendu, mais le type « {0} » trouvé dans l’attribut ’AsyncMethodBuilder’ n’était pas approprié. Il doit s’agir d’un type générique indépendant d’arité One, et son type conteneur (le cas échéant) doit être non générique. @@ -1392,6 +1417,11 @@ Remplacement du générateur de méthode asynchrone + + auto default struct fields + auto default struct fields + + covariant returns retours covariants @@ -3566,24 +3596,44 @@ Le paramètre de type a le même type que le paramètre de type de la méthode externe. - - Field '{0}' must be fully assigned before control is returned to the caller - Le champ '{0}' doit être entièrement assigné avant que le contrôle soit retourné à l'appelant + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - La propriété implémentée automatiquement '{0}' doit être entièrement assignée avant que le contrôle soit retourné à l'appelant. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - Une propriété implémentée automatiquement doit être entièrement assignée avant que le contrôle ne soit retourné à l'appelant. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - Les champs d'un struct doivent être entièrement assignés dans un constructeur avant que le contrôle ne soit retourné à l'appelant + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ Utilisation d'un champ potentiellement non assigné '{0}' + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field Utilisation d'un champ potentiellement non assigné @@ -3666,19 +3736,49 @@ Utilisation d'une propriété implémentée automatiquement éventuellement non assignée : '{0}' + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property Utilisation d'une propriété implémentée automatiquement éventuellement non assignée - - The 'this' object cannot be used before all of its fields have been assigned - Impossible d'utiliser l'objet 'this' tant que tous ses champs n'ont pas été assignés + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - Impossible d'utiliser l'objet 'this' dans un constructeur tant que tous ses champs n'ont pas été assignés + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ Utilisation d'une propriété implémentée automatiquement éventuellement non assignée : '{0}' - - Field '{0}' must be fully assigned before control is returned to the caller - Le champ '{0}' doit être entièrement assigné avant que le contrôle soit retourné à l'appelant - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another Impossible de déterminer le type d'expression conditionnelle, car '{0}' et '{1}' sont convertis implicitement l'un en l'autre @@ -4551,11 +4646,6 @@ L'utilisation d'un littéral par défaut est non valide dans ce contexte - - The 'this' object cannot be used before all of its fields have been assigned - Impossible d'utiliser l'objet 'this' tant que tous ses champs n'ont pas été assignés - - The __arglist construct is valid only within a variable argument method La construction __arglist est valide uniquement avec une méthode à arguments de variables @@ -6705,11 +6795,6 @@ Si une telle classe est utilisée en tant que classe de base et si la classe dé Impossible de déduire le type de '{0}', car son initialiseur fait directement ou indirectement référence à la définition. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - La propriété implémentée automatiquement '{0}' doit être entièrement assignée avant que le contrôle soit retourné à l'appelant. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. Impossible d'utiliser la variable locale '{0}' tant qu'elle n'est pas déclarée. La déclaration de la variable locale masque le champ '{1}'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index c0a40933c16ec..742745d2bda54 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -1347,6 +1347,16 @@ Il tipo '{0}' deve essere pubblico per poterlo usare come convenzione di chiamata. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. '{0}', a cui è assegnato l'attributo 'UnmanagedCallersOnly', non può essere chiamato direttamente. Ottenere un puntatore a funzione per questo metodo. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. È previsto un tipo restituito simile a un'attività generica, ma il tipo '{0}' trovato nell'attributo 'AsyncMethodBuilder' non è idoneo. Deve essere un tipo generico non associato di grado uno e il tipo che lo contiene (se presente) deve essere non generico. @@ -1392,6 +1417,11 @@ override del generatore di metodi asincroni + + auto default struct fields + auto default struct fields + + covariant returns tipi restituiti covarianti @@ -3566,24 +3596,44 @@ Il tipo del parametro di tipo è lo stesso del parametro di tipo del metodo esterno. - - Field '{0}' must be fully assigned before control is returned to the caller - Il campo '{0}' deve essere assegnato completamente prima che il controllo venga restituito al chiamante + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - La proprietà implementata automaticamente '{0}' deve essere completamente assegnata prima che il controllo venga restituito al chiamante. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - È necessario assegnare completamente una proprietà implementata automaticamente prima che il controllo venga restituito al chiamante. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - È necessario assegnare completamente i campi di uno struct in un costruttore prima che il controllo venga restituito al chiamante + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ Uso del campo '{0}' probabilmente non assegnato + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field Uso del campo probabilmente non assegnato @@ -3666,19 +3736,49 @@ Uso della proprietà implementata automaticamente '{0}' probabilmente non assegnata + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property Uso della proprietà implementata automaticamente probabilmente non assegnata - - The 'this' object cannot be used before all of its fields have been assigned - Non è possibile usare l'oggetto 'this' prima dell'assegnazione di tutti i relativi campi + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - Non è possibile usare l'oggetto 'this' in un costruttore prima dell'assegnazione di tutti i relativi campi + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ Uso della proprietà implementata automaticamente '{0}' probabilmente non assegnata - - Field '{0}' must be fully assigned before control is returned to the caller - Il campo '{0}' deve essere assegnato completamente prima che il controllo venga restituito al chiamante - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another Non è possibile determinare il tipo di espressione condizionale perché '{0}' e '{1}' sono reciprocamente convertibili in modo implicito @@ -4551,11 +4646,6 @@ In questo contesto non è possibile usare il valore letterale predefinito - - The 'this' object cannot be used before all of its fields have been assigned - Non è possibile usare l'oggetto 'this' prima dell'assegnazione di tutti i relativi campi - - The __arglist construct is valid only within a variable argument method Il costrutto __arglist è valido solo all'interno di un metodo con argomenti variabili @@ -6705,11 +6795,6 @@ Se si usa tale classe come classe base e se la classe di derivazione definisce u Il tipo di '{0}' non può essere dedotto perché il relativo inizializzatore fa riferimento in modo diretto o indiretto alla definizione. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - La proprietà implementata automaticamente '{0}' deve essere completamente assegnata prima che il controllo venga restituito al chiamante. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. Non è possibile usare la variabile locale '{0}' prima che sia dichiarata. La dichiarazione della variabile locale nasconde il campo '{1}'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 696220b661113..18a0f859961fc 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -1347,6 +1347,16 @@ 呼び出し規則として使用する型 '{0}' はパブリックでなければなりません。 + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. '{0}' は 'UnmanagedCallersOnly' 属性が設定されているため、直接呼び出すことはできません。このメソッドへの関数ポインターを取得してください。 @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. 汎用タスクのような戻り値の型が必要ですが、'AsyncMethodBuilder' 属性で見つかった型 '{0}' が適切ではありませんでした。アリティの非バインド ジェネリック型である必要があり、それを含む型 (存在する場合) は非ジェネリックでなければなりません。 @@ -1392,6 +1417,11 @@ 非同期メソッド ビルダーのオーバーライド + + auto default struct fields + auto default struct fields + + covariant returns covariant の戻り値 @@ -3566,24 +3596,44 @@ 型パラメーターの型は、外のメソッドからの型パラメーターと同じ型です。 - - Field '{0}' must be fully assigned before control is returned to the caller - フィールド '{0}' は、コントロールが呼び出し元に返される前に割り当てられている必要があります + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - 自動実装プロパティ '{0}' は、制御が呼び出し元に返される前に完全に割り当てられる必要があります。 + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - 自動実装プロパティは、制御が呼び出し元に返される前に完全に割り当てられる必要があります。 + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - 構造体のフィールドは、制御が呼び出し元に返される前に、コンストラクター内で完全に割り当てられる必要があります + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ フィールド '{0}' は、割り当てられていない可能性があります + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field 割り当てられていない可能性のあるフィールドの使用 @@ -3666,19 +3736,49 @@ 割り当てられていない可能性のある自動実装プロパティ '{0}' の使用 + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property 割り当てられていない可能性のある自動実装プロパティの使用 - - The 'this' object cannot be used before all of its fields have been assigned - すべてのフィールドが割り当てられるまで、この 'this' オブジェクトは使用できません + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - すべてのフィールドが割り当てられるまでは、この 'this' オブジェクトをコンストラクター内で使用することはできません + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ 割り当てられていない可能性のある自動実装プロパティ '{0}' の使用 - - Field '{0}' must be fully assigned before control is returned to the caller - フィールド '{0}' は、コントロールが呼び出し元に返される前に割り当てられている必要があります - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another '{0}' と '{1}' が暗黙的に変換し合うため、条件式の型がわかりません @@ -4551,11 +4646,6 @@ このコンテキストでの既定のリテラルの使用は無効です - - The 'this' object cannot be used before all of its fields have been assigned - すべてのフィールドが割り当てられるまで、この 'this' オブジェクトは使用できません - - The __arglist construct is valid only within a variable argument method __arglist 構文は可変個の引数メソッド内でのみ有効です @@ -6705,11 +6795,6 @@ If such a class is used as a base class and if the deriving class defines a dest 初期化子が直接的または間接的に定義を参照しているため、'{0}' の型を推論することはできません。 - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - 自動実装プロパティ '{0}' は、制御が呼び出し元に返される前に完全に割り当てられる必要があります。 - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. 宣言する前にローカル変数 '{0}' を使用できません。このローカル変数の宣言は、フィールド '{1}' を非表示にします。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index a68b4b29dd054..19cbba023b99d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -1347,6 +1347,16 @@ 호출 규칙으로 사용하려면 '{0}' 형식이 public이어야 합니다. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. '{0}'에는 'UnmanagedCallersOnly' 특성을 지정할 수 없으며 이 항목은 직접 호출할 수 없습니다. 이 메서드에 대한 함수 포인터를 가져오세요. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. 일반 작업과 같은 반환 유형이 예상되었지만 'AsyncMethodBuilder' 특성에 있는 '{0}' 유형이 적합하지 않습니다. 이는 인자 수가 1인 바인딩되지 않은 제네릭 유형이어야 하고, 포함하는 유형(있는 경우)은 제네릭이 아니어야 합니다. @@ -1392,6 +1417,11 @@ 비동기 메서드 빌더 재정의 + + auto default struct fields + auto default struct fields + + covariant returns 공변(covariant) 반환 @@ -3565,24 +3595,44 @@ 형식 매개 변수가 외부 메서드의 형식 매개 변수와 형식이 같습니다. - - Field '{0}' must be fully assigned before control is returned to the caller - 제어를 호출자에게 반환하려면 '{0}' 필드가 완전히 할당되어야 합니다. + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - 제어가 호출자에게 반환되기 전에 자동으로 구현된 '{0}' 속성이 완전히 할당되어야 합니다. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - 컨트롤이 호출자에게 반환되기 전에 자동 구현 속성이 완전히 할당되어야 함 + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - 컨트롤이 호출자에게 반환되기 전에 구조체의 필드를 생성자에 완전히 할당해야 함 + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3645,6 +3695,26 @@ 할당되지 않은 '{0}' 필드를 사용하고 있는 것 같습니다. + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field 할당되지 않은 필드를 사용하고 있는 것 같음 @@ -3665,19 +3735,49 @@ 할당되지 않은 자동 구현 속성 '{0}'을(를) 사용하고 있는 것 같습니다. + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property 할당되지 않은 자동 구현 속성을 사용하고 있는 것 같음 - - The 'this' object cannot be used before all of its fields have been assigned - 모든 필드가 할당되기 전에는 'this' 개체를 사용할 수 없습니다. + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - 모든 필드가 할당되기 전에 생성자에서 'this' 개체를 사용할 수 없음 + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4445,11 +4545,6 @@ 할당되지 않은 자동 구현 속성 '{0}'을(를) 사용하고 있는 것 같습니다. - - Field '{0}' must be fully assigned before control is returned to the caller - 제어를 호출자에게 반환하려면 '{0}' 필드가 완전히 할당되어야 합니다. - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another '{0}'과(와) '{1}'은(는) 서로 암시적으로 변환되므로 조건식의 형식을 확인할 수 없습니다. @@ -4550,11 +4645,6 @@ 이 컨텍스트에서는 기본 리터럴을 사용할 수 없습니다. - - The 'this' object cannot be used before all of its fields have been assigned - 모든 필드가 할당되기 전에는 'this' 개체를 사용할 수 없습니다. - - The __arglist construct is valid only within a variable argument method __arglist 구문은 가변 인수 메서드 내에서만 사용할 수 있습니다. @@ -6704,11 +6794,6 @@ If such a class is used as a base class and if the deriving class defines a dest 이니셜라이저가 직간접적으로 정의를 참조하고 있어 '{0}' 형식을 유추할 수 없습니다. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - 제어가 호출자에게 반환되기 전에 자동으로 구현된 '{0}' 속성이 완전히 할당되어야 합니다. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. '{0}' 지역 변수는 선언되지 않으면 사용할 수 없습니다. 지역 변수를 선언하면 '{1}' 필드가 숨겨집니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index e89c91e19b6f1..236d2be122cac 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -1347,6 +1347,16 @@ Typ „{0}” musi być publiczny, aby można go było używać jako konwencji wywoływania. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. Element „{0}” ma atrybut „UnmanagedCallersOnly” i nie można go wywołać bezpośrednio. Uzyskaj wskaźnik funkcji do tej metody. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Oczekiwano zwracanego typu podobnego do zadania ogólnego, ale typ "{0}" znaleziony w atrybucie "AsyncMethodBuilder" był nieodpowiedni. Musi to być niepowiązany typ ogólny jednego argumentu, a zawarty w nim typ (jeśli występuje), nie może być ogólny. @@ -1392,6 +1417,11 @@ zastąpienie konstruktora metodą asynchroniczną + + auto default struct fields + auto default struct fields + + covariant returns zwroty kowariantne @@ -3566,24 +3596,44 @@ Parametr typu ma ten sam typ co parametr typu z metody zewnętrznej. - - Field '{0}' must be fully assigned before control is returned to the caller - Pole „{0}” musi być całkowicie przypisane przed zwróceniem sterowania do elementu wywołującego + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Automatycznie implementowana właściwość „{0}” musi być całkowicie przypisana przed zwróceniem sterowania do elementu wywołującego. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - Automatycznie implementowana właściwość musi być całkowicie przypisana przed zwróceniem sterowania do elementu wywołującego. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - Pola struktury muszą być w pełni przypisane w konstruktorze, zanim sterowanie zostanie zwrócone do elementu wywołującego + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ Użycie prawdopodobnie nieprzypisanego pola „{0}” + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field Użycie prawdopodobnie nieprzypisanego pola @@ -3666,19 +3736,49 @@ Użycie prawdopodobnie nieprzypisanej automatycznie implementowanej właściwości „{0}” + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property Użycie prawdopodobnie nieprzypisanej automatycznie implementowanej właściwości - - The 'this' object cannot be used before all of its fields have been assigned - Nie można używać obiektu „this” przed przypisaniem wszystkich jego pól + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - Nie można użyć obiektu „this” w konstruktorze przed przypisaniem wszystkich jego pól + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ Użycie prawdopodobnie nieprzypisanej automatycznie implementowanej właściwości „{0}” - - Field '{0}' must be fully assigned before control is returned to the caller - Pole „{0}” musi być całkowicie przypisane przed zwróceniem sterowania do elementu wywołującego - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another Nie można określić typu wyrażenia warunkowego, ponieważ elementy „{0}” i „{1}” są wzajemnie niejawnie konwertowane @@ -4551,11 +4646,6 @@ Użycie domyślnego literału nie jest prawidłowe w tym kontekście - - The 'this' object cannot be used before all of its fields have been assigned - Nie można używać obiektu „this” przed przypisaniem wszystkich jego pól - - The __arglist construct is valid only within a variable argument method Konstrukcja __arglist jest prawidłowa tylko wewnątrz metody argumentu zmiennej @@ -6705,11 +6795,6 @@ Jeśli taka klasa zostanie użyta jako klasa bazowa i klasa pochodna definiuje d Typu elementu „{0}” nie można wywnioskować, ponieważ jego inicjator bezpośrednio lub pośrednio przywołuje definicję. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Automatycznie implementowana właściwość „{0}” musi być całkowicie przypisana przed zwróceniem sterowania do elementu wywołującego. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. Nie można użyć zmiennej lokalnej „{0}” przed jej zadeklarowaniem. Deklaracja zmiennej lokalnej powoduje ukrycie pola „{1}”. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index eb0d1b399b650..2a86279dbf5fc 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -1347,6 +1347,16 @@ O tipo '{0}' precisa ser público para ser usado como uma convenção de chamada. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. '{0}' foi atribuído com 'UnmanagedCallersOnly' e não pode ser chamado diretamente. Obtenha um ponteiro de função para esse método. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Um tipo de retorno semelhante à tarefa genérica era esperado, mas o tipo '{0}' encontrado no atributo 'AsyncMethodBuilder' não era adequado. Ele deve ser um tipo genérico não associado de arity um e seu tipo recipiente (se houver) deve ser não genérico. @@ -1392,6 +1417,11 @@ substituição do construtor de método assíncrono + + auto default struct fields + auto default struct fields + + covariant returns retornos de covariante @@ -3566,24 +3596,44 @@ O parâmetro de tipo tem o mesmo tipo que o parâmetro de tipo do método externo. - - Field '{0}' must be fully assigned before control is returned to the caller - Campo "{0}" deve ser totalmente atribuído antes que o controle seja retornado ao chamador + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - A propriedade '{0}' autoimplementada deve ser totalmente atribuída antes de o controle ser retornado ao chamador. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - A propriedade autoimplementada precisa ser totalmente atribuída antes que o controle seja retornado ao chamador. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - Os campos de um struct precisam ser totalmente atribuídos em um construtor antes que o controle seja retornado ao chamador + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ Uso de campo possivelmente não atribuído "{0}" + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field Uso de campo possivelmente não atribuído @@ -3666,19 +3736,49 @@ Uso de propriedades autoimplementadas possivelmente não atribuídas '{0}' + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property Uso de propriedade autoimplementada possivelmente não atribuída - - The 'this' object cannot be used before all of its fields have been assigned - O objeto 'this' não pode ser usado antes que todos os seus campos tenham sido atribuídos + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - O objeto 'this' não pode ser usado em um construtor antes que todos os seus campos sejam atribuídos + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ Uso de propriedades autoimplementadas possivelmente não atribuídas '{0}' - - Field '{0}' must be fully assigned before control is returned to the caller - Campo "{0}" deve ser totalmente atribuído antes que o controle seja retornado ao chamador - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another Tipo de expressão condicional não pode ser determinado porque "{0}" e "{1}" se convertem implicitamente um no outro @@ -4551,11 +4646,6 @@ O uso do literal padrão não é válido neste contexto - - The 'this' object cannot be used before all of its fields have been assigned - O objeto 'this' não pode ser usado antes que todos os seus campos tenham sido atribuídos - - The __arglist construct is valid only within a variable argument method O construtor __arglist só é válido dentro de um método de argumento variável @@ -6705,11 +6795,6 @@ Se tal classe for usada como uma classe base e se a classe derivada definir um d Tipo de "{0}" não pode ser inferido porque seu inicializador direta ou indiretamente refere-se à definição. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - A propriedade '{0}' autoimplementada deve ser totalmente atribuída antes de o controle ser retornado ao chamador. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. Não é possível usar a variável local "{0}" antes de declará-la. A declaração da variável local oculta o campo "{1}". diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 939a47dc9ca93..f431c894a5413 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -1347,6 +1347,16 @@ Тип "{0}" должен быть открытым для использования в качестве соглашения о вызовах. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. "{0}" имеет атрибут "UnmanagedCallersOnly" и не может вызываться напрямую. Получите указатель на функцию для этого метода. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Ожидался универсальный возвращаемый тип, схожий с задачей, но тип "{0}", обнаруженный в атрибуте "AsyncMethodBuilder", не подходит. Требуется неограниченный универсальный тип c арностью 1, а его содержащий тип (если есть) не должен быть универсальным @@ -1392,6 +1417,11 @@ переопределение построителя методов async + + auto default struct fields + auto default struct fields + + covariant returns ковариантные возвращаемые значения @@ -3566,24 +3596,44 @@ Параметр типа имеет то же имя, что и параметр типа во внешнем методе. - - Field '{0}' must be fully assigned before control is returned to the caller - Поле "{0}" должно быть полностью определено до возврата управления в вызывающий метод. + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Автоматически реализованное свойство "{0}" должно быть полностью определено до возврата управления в вызывающий метод. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - Необходимо полностью присвоить значение автоматически реализованному свойству до того, как управление будет возвращено в вызывающий метод + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - Необходимо полностью присвоить значения полям структуры в конструкторе до того, как управление будет возвращено в вызывающий метод + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ Использование поля "{0}", которому, возможно, не присвоено значение. + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field Использование поля, которому, возможно, не присвоено значение @@ -3666,19 +3736,49 @@ Использование автоматически реализованного свойства "{0}", которому, возможно, не присвоено значение + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property Использование автоматически реализованного свойства, которому, возможно, не присвоено значение - - The 'this' object cannot be used before all of its fields have been assigned - Невозможно использовать объект this, пока не будут назначены все поля этого объекта. + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - Невозможно использовать объект this в конструкторе, пока не будут назначены все поля этого объекта + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ Использование автоматически реализованного свойства "{0}", которому, возможно, не присвоено значение - - Field '{0}' must be fully assigned before control is returned to the caller - Поле "{0}" должно быть полностью определено до возврата управления в вызывающий метод. - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another Невозможно определить тип условного выражения, так как "{0}" и "{1}" неявно преобразовываются друг в друга. @@ -4551,11 +4646,6 @@ Использование литерала по умолчанию недопустимо в этом контексте. - - The 'this' object cannot be used before all of its fields have been assigned - Невозможно использовать объект this, пока не будут назначены все поля этого объекта. - - The __arglist construct is valid only within a variable argument method Конструкция __arglist допускается только в методе с переменным числом аргументов. @@ -6705,11 +6795,6 @@ If such a class is used as a base class and if the deriving class defines a dest Не удается получить тип "{0}", так как инициализатор прямо или косвенно ссылается на определение. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Автоматически реализованное свойство "{0}" должно быть полностью определено до возврата управления в вызывающий метод. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. Невозможно использовать локальную переменную "{0}" перед ее объявлением. Объявление данной локальной переменной скрыто в поле "{1}". diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 70669a45d5230..eeeadd38ed5ec 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -1347,6 +1347,16 @@ '{0}' türünün bir çağırma kuralı olarak kullanılabilmesi için genel olması gerekir. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. '{0}', 'UnmanagedCallersOnly' ile ilişkilendirilmiş ve doğrudan çağrılamaz. Bu yöntem için bir işlev işaretçisi edinin. @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Genel bir görev benzeri dönüş türü bekleniyordu, ancak ' AsyncMethodBuilder ' özniteliğinde bulunan '{0}' türü uygun değildi. İlişkisiz bir genel tür olması ve içeren türü (varsa) genel olmayan olması gerekir. @@ -1392,6 +1417,11 @@ zaman uyumsuz yöntem oluşturucusunu geçersiz kılma + + auto default struct fields + auto default struct fields + + covariant returns birlikte değişken dönüşler @@ -3566,24 +3596,44 @@ Tür parametresi dış metottaki tür parametresi ile aynı türe sahip - - Field '{0}' must be fully assigned before control is returned to the caller - '{0}' alanı denetim çağrı yapana döndürülmeden önce tamamen atanmalıdır + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Denetimin çağırana dönmesi için otomatik uygulanan '{0}' özelliğine tam atama yapılmış olması gerekir. + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - Denetimin çağırana dönmesi için otomatik uygulanan bir özelliğe tam olarak atama yapılmış olması gerekir. + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - Bir yapının alanları, denetim çağırana döndürülmeden önce bir oluşturucuda tam olarak atanmalıdır + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ Atanmamış olabilen '{0}' alanının kullanımı + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field Atanmamış olabilecek alanın kullanımı @@ -3666,19 +3736,49 @@ Atanmamış olabilecek otomatik uygulanmış '{0}' özelliğinin kullanımı + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property Atanmamış olabilecek otomatik uygulanmış özelliğin kullanımı - - The 'this' object cannot be used before all of its fields have been assigned - 'this' nesnesi, tüm alanları atanmadan kullanılamaz + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - 'this' nesnesi, tüm alanları atanmadan bir oluşturucuda kullanılamaz + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ Atanmamış olabilecek otomatik uygulanmış '{0}' özelliğinin kullanımı - - Field '{0}' must be fully assigned before control is returned to the caller - '{0}' alanı denetim çağrı yapana döndürülmeden önce tamamen atanmalıdır - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another '{0}' ve '{1}' örtülü olarak birbirine dönüştüğünden koşullu ifadenin türü belirlenemiyor @@ -4551,11 +4646,6 @@ Default sabit değerinin kullanımı bu bağlamda geçerli değil - - The 'this' object cannot be used before all of its fields have been assigned - 'this' nesnesi, tüm alanları atanmadan kullanılamaz - - The __arglist construct is valid only within a variable argument method __arglist oluşturucusu yalnızca değişken sayıda bağımsız değişkenli bir yöntem içinde geçerlidir @@ -6705,11 +6795,6 @@ Bu sınıf temel sınıf olarak kullanılırsa ve türetilen sınıf bir yıkıc '{0}' öğesinin türü başlatıcısı doğrudan veya dolaylı olarak tanıma başvurduğundan gösterilemiyor. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - Denetimin çağırana dönmesi için otomatik uygulanan '{0}' özelliğine tam atama yapılmış olması gerekir. - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. İfade edilmeden önce '{0}' yerel değişkeni kullanılamıyor. Yerel değişkenin bildirimi '{1}' alanını gizler. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 89cac2179aad2..81025b43d6d31 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -1347,6 +1347,16 @@ 类型“{0}”必须是公共的,才能用作调用约定。 + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. “{0}”使用 "UnmanagedCallersOnly" 进行特性化,无法直接调用。请获取指向此方法的函数指针。 @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. 应为泛用类任务返回类型,但在“AsyncMethodBuilder”属性中发现的类型“{0}”不合适。它必须是 arity one 的未绑定泛型类型,并且其包含类型(如果有)必须为非泛用。 @@ -1392,6 +1417,11 @@ 异步方法生成器替代 + + auto default struct fields + auto default struct fields + + covariant returns 协变返回 @@ -3571,24 +3601,44 @@ 类型参数与外部方法中的类型参数有相同的类型。 - - Field '{0}' must be fully assigned before control is returned to the caller - 在控制返回调用方之前,字段“{0}”必须完全赋值 + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - 在控制返回调用方之前,自动实现的属性“{0}”必须完全赋值。 + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - 在控制返回调用方之前,自动实现的属性必须完全赋值。 + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - 在控制返回调用方之前,必须在构造函数中对结构的字段完全赋值 + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3651,6 +3701,26 @@ 使用了可能未赋值的字段“{0}” + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field 使用可能未赋值的字段 @@ -3671,19 +3741,49 @@ 使用可能未赋值的自动实现的属性“{0}” + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property 使用可能未赋值的自动实现的属性 - - The 'this' object cannot be used before all of its fields have been assigned - 在给 "this" 对象的所有字段赋值之前,无法使用该对象 + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - 在对 "this" 对象的所有字段赋值之前,不能在构造函数中使用 "this" 对象 + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4451,11 +4551,6 @@ 使用可能未赋值的自动实现的属性“{0}” - - Field '{0}' must be fully assigned before control is returned to the caller - 在控制返回调用方之前,字段“{0}”必须完全赋值 - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another 无法确定条件表达式的类型,因为“{0}”和“{1}”可相互隐式转换 @@ -4556,11 +4651,6 @@ 在此上下文中不可使用 default 字面量 - - The 'this' object cannot be used before all of its fields have been assigned - 在给 "this" 对象的所有字段赋值之前,无法使用该对象 - - The __arglist construct is valid only within a variable argument method __arglist 构造只在变量参数方法中有效 @@ -6710,11 +6800,6 @@ If such a class is used as a base class and if the deriving class defines a dest 无法推理“{0}”类型,因为其初始值设定项直接或间接地引用定义。 - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - 在控制返回调用方之前,自动实现的属性“{0}”必须完全赋值。 - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. 本地变量“{0}”在声明之前无法使用。声明该本地变量将隐藏字段“{1}”。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index f68841ac8b573..ed37f1e0c832e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -1347,6 +1347,16 @@ 類型 '{0}' 必須是公用,才能用為呼叫慣例。 + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + '{0}' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. '{0}' 使用 'UnmanagedCallersOnly' 屬性化,因此無法直接呼叫。取得此方法的函式指標。 @@ -1372,6 +1382,21 @@ Unterminated raw string literal. + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. 應存在類似泛型工作的傳回型別,但在 'AsyncMethodBuilder' 屬性中找到的類型 '{0}' 不適用。它必須是 arity one 的未綁定泛型型別,並且其包含類型 (如果有) 必須是非泛型。 @@ -1392,6 +1417,11 @@ 非同步方法建立器覆寫 + + auto default struct fields + auto default struct fields + + covariant returns Covariant 傳回 @@ -3566,24 +3596,44 @@ 類型參數與外部方法的類型參數,類型相同。 - - Field '{0}' must be fully assigned before control is returned to the caller - 在程式控制權回到呼叫端之前,必須完整指派欄位 '{0}' + + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - 在控制權回到呼叫端之前,必須完整指派自動實作的屬性 '{0}'。 + + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before auto-implemented property is explicitly assigned, causing a preceding implicit assignment of 'default'. - - An auto-implemented property must be fully assigned before control is returned to the caller. - 在控制權傳回給呼叫端之前,必須完整指派自動實作屬性。 + + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. + Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the property. - - Fields of a struct must be fully assigned in a constructor before control is returned to the caller - 在控制權傳回給呼叫端之前,必須在建構函式中完全指派結構的欄位 + + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + An auto-implemented property must be fully assigned before control is returned to the caller. Consider updating the language version to auto-default the property. + + + + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field '{0}' is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + Control is returned to caller before field is explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + Field '{0}' must be fully assigned before control is returned to the caller. Consider updating to language version '{1}' to auto-default the field. + + + + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. + Fields of a struct must be fully assigned in a constructor before control is returned to the caller. Consider updating the language version to auto-default the field. @@ -3646,6 +3696,26 @@ 使用可能未指派的欄位 '{0}' + + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Field is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + Use of possibly unassigned field '{0}'. Consider updating to language version '{1}' to auto-default the field. + + + + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + Use of possibly unassigned field. Consider updating the language version to auto-default the field. + + Use of possibly unassigned field 使用可能未指派的欄位 @@ -3666,19 +3736,49 @@ 可能使用了未指派的自動實作屬性 '{0}' + + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + Auto-implemented property is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + + + + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + Use of possibly unassigned auto-implemented property '{0}'. Consider updating to language version '{1}' to auto-default the property. + + + + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + Use of possibly unassigned auto-implemented property. Consider updating the language version to auto-default the property. + + Use of possibly unassigned auto-implemented property 使用可能未指派的自動實作屬性 - - The 'this' object cannot be used before all of its fields have been assigned - 在指派 'this' 物件的所有欄位前,無法加以使用 + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + + + + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + The 'this' object is read before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. - - The 'this' object cannot be used in a constructor before all of its fields have been assigned - 在指派 'this' 物件的所有欄位前,無法在建構函式中加以使用 + + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version '{0}' to auto-default the unassigned fields. + + + + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. + The 'this' object cannot be used in a constructor before all of its fields have been assigned. Consider updating the language version to auto-default the unassigned fields. @@ -4446,11 +4546,6 @@ 可能使用了未指派的自動實作屬性 '{0}' - - Field '{0}' must be fully assigned before control is returned to the caller - 在程式控制權回到呼叫端之前,必須完整指派欄位 '{0}' - - Type of conditional expression cannot be determined because '{0}' and '{1}' implicitly convert to one another 無法判斷條件運算式的類型,因為 '{0}' 和 '{1}' 會互相隱含轉換 @@ -4551,11 +4646,6 @@ 在此內容中使用預設常值無效 - - The 'this' object cannot be used before all of its fields have been assigned - 在指派 'this' 物件的所有欄位前,無法加以使用 - - The __arglist construct is valid only within a variable argument method __arglist 建構函式只有在變數引數方法中才有效 @@ -6705,11 +6795,6 @@ If such a class is used as a base class and if the deriving class defines a dest 無法推斷 '{0}' 的類型,因為其初始設定式會直接或間接參考定義。 - - Auto-implemented property '{0}' must be fully assigned before control is returned to the caller. - 在控制權回到呼叫端之前,必須完整指派自動實作的屬性 '{0}'。 - - Cannot use local variable '{0}' before it is declared. The declaration of the local variable hides the field '{1}'. 在宣告區域變數 '{0}' 之前,無法使用此變數。區域變數的宣告會隱藏欄位 '{1}'。 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs index b465d43b10ca1..180bd46bbf673 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs @@ -8900,12 +8900,12 @@ public ValueTuple(T1 item1, T2 item2) // (13,20): warning CS0169: The field '(T1, T2).Item2' is never used // private T2 Item2; Diagnostic(ErrorCode.WRN_UnreferencedField, "Item2").WithArguments("(T1, T2).Item2").WithLocation(13, 20), - // (14,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller + // (14,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(14, 16), - // (14,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "ValueTuple").WithArguments("(T1, T2).Item2", "preview").WithLocation(14, 16), + // (14,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(14, 16), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "ValueTuple").WithArguments("(T1, T2).Item2", "preview").WithLocation(14, 16), // (17,13): error CS0229: Ambiguity between '(T1, T2).Item2' and '(T1, T2).Item2' // Item2 = item2; Diagnostic(ErrorCode.ERR_AmbigMember, "Item2").WithArguments("(T1, T2).Item2", "(T1, T2).Item2").WithLocation(17, 13) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs index 5a917ac1e7161..3e96547f61c4e 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs @@ -232,12 +232,12 @@ public ValueTuple(T1 item1, T2 item2) // (7,20): warning CS0169: The field '(T1, T2).Item2' is never used // private T2 Item2; Diagnostic(ErrorCode.WRN_UnreferencedField, "Item2").WithArguments("(T1, T2).Item2").WithLocation(7, 20), - // (8,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller + // (8,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(8, 16), - // (8,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "ValueTuple").WithArguments("(T1, T2).Item2", "preview").WithLocation(8, 16), + // (8,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(8, 16), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "ValueTuple").WithArguments("(T1, T2).Item2", "preview").WithLocation(8, 16), // (11,18): error CS0229: Ambiguity between '(T1, T2).Item2' and '(T1, T2).Item2' // this.Item2 = item2; Diagnostic(ErrorCode.ERR_AmbigMember, "Item2").WithArguments("(T1, T2).Item2", "(T1, T2).Item2").WithLocation(11, 18) @@ -4461,18 +4461,6 @@ public ValueTuple(T1 item1, T2 item2) // (21,18): error CS0229: Ambiguity between '(T1, T2).Item2' and '(T1, T2).Item2' // this.Item2 = 2; Diagnostic(ErrorCode.ERR_AmbigMember, "Item2").WithArguments("(T1, T2).Item2", "(T1, T2).Item2").WithLocation(21, 18), - // (18,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(18, 16), - // (18,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(18, 16), - // (18,16): error CS0171: Field '(T1, T2).Item1' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item1").WithLocation(18, 16), - // (18,16): error CS0171: Field '(T1, T2).Item1' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item1").WithLocation(18, 16), // (7,39): error CS0229: Ambiguity between '(string, string).Item1' and '(string, string).Item1' // System.Console.WriteLine($"{x.Item1}"); Diagnostic(ErrorCode.ERR_AmbigMember, "Item1").WithArguments("(string, string).Item1", "(string, string).Item1").WithLocation(7, 39), @@ -4581,15 +4569,6 @@ public ValueTuple(T1 item1, T2 item2) // (28,18): error CS0229: Ambiguity between '(T1, T2).Item2' and '(T1, T2).Item2' // this.Item2 = 2; Diagnostic(ErrorCode.ERR_AmbigMember, "Item2").WithArguments("(T1, T2).Item2", "(T1, T2).Item2").WithLocation(28, 18), - // (26,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(26, 16), - // (26,16): error CS0171: Field '(T1, T2).Item1' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item1").WithLocation(26, 16), - // (26,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(26, 16), // (7,39): error CS8128: Member 'Item1' was not found on type '(T1, T2)' from assembly 'comp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. // System.Console.WriteLine($"{x.Item1}"); Diagnostic(ErrorCode.ERR_PredefinedTypeMemberNotFoundInAssembly, "Item1").WithArguments("Item1", "(T1, T2)", "comp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(7, 39), @@ -4681,15 +4660,6 @@ public ValueTuple(T1 item1, T2 item2) // (7,39): error CS8128: Member 'Item1' was not found on type '(T1, T2)' from assembly 'comp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. // System.Console.WriteLine($"{x.a}"); Diagnostic(ErrorCode.ERR_PredefinedTypeMemberNotFoundInAssembly, "a").WithArguments("Item1", "(T1, T2)", "comp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(7, 39), - // (17,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(17, 16), - // (17,16): error CS0171: Field '(T1, T2).Item1' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item1").WithLocation(17, 16), - // (17,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(17, 16), // (19,18): error CS0229: Ambiguity between '(T1, T2).Item2' and '(T1, T2).Item2' // this.Item2 = 2; Diagnostic(ErrorCode.ERR_AmbigMember, "Item2").WithArguments("(T1, T2).Item2", "(T1, T2).Item2").WithLocation(19, 18) @@ -13208,15 +13178,6 @@ static void Test03() // (25,16): warning CS0612: '(T1, T2)' is obsolete // return (1, 1); Diagnostic(ErrorCode.WRN_DeprecatedSymbol, "(1, 1)").WithArguments("(T1, T2)").WithLocation(25, 16), - // (58,16): error CS0843: Auto-implemented property '(T1, T2).I1.P1' must be fully assigned before control is returned to the caller. - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "ValueTuple").WithArguments("(T1, T2).I1.P1").WithLocation(58, 16), - // (58,16): error CS0843: Auto-implemented property '(T1, T2).P2' must be fully assigned before control is returned to the caller. - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "ValueTuple").WithArguments("(T1, T2).P2").WithLocation(58, 16), - // (58,16): error CS0171: Field '(T1, T2).E2' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).E2").WithLocation(58, 16), // (30,34): warning CS0612: '(int, int).Item1' is obsolete // System.Console.WriteLine(M10().Item1); Diagnostic(ErrorCode.WRN_DeprecatedSymbol, "M10().Item1").WithArguments("(int, int).Item1").WithLocation(30, 34), @@ -13400,14 +13361,10 @@ public ValueTuple(string s) { } } " + tupleattributes_cs; - var comp = CreateCompilationWithMscorlib40(source); + var comp = CreateCompilationWithMscorlib40(source, assemblyName: "test"); comp.VerifyEmitDiagnostics( - // (7,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(string s) { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(7, 16), - // (7,16): error CS0171: Field '(T1, T2).Item1' must be fully assigned before control is returned to the caller - // public ValueTuple(string s) { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item1").WithLocation(7, 16) + // error CS7038: Failed to emit module 'test': Unable to determine specific cause of the failure. + Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("test", "Unable to determine specific cause of the failure.").WithLocation(1, 1) ); } @@ -13425,14 +13382,10 @@ public ValueTuple(string s) { } } " + tupleattributes_cs; - var comp = CreateCompilationWithMscorlib40(source); + var comp = CreateCompilationWithMscorlib40(source, assemblyName: "test"); comp.VerifyEmitDiagnostics( - // (7,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(string s) { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(7, 16), - // (7,16): error CS0171: Field '(T1, T2).Item1' must be fully assigned before control is returned to the caller - // public ValueTuple(string s) { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item1").WithLocation(7, 16) + // error CS7038: Failed to emit module 'test': Unable to determine specific cause of the failure. + Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("test", "Unable to determine specific cause of the failure.").WithLocation(1, 1) ); } diff --git a/src/Compilers/CSharp/Test/Emit2/Diagnostics/DiagnosticAnalyzerTests.cs b/src/Compilers/CSharp/Test/Emit2/Diagnostics/DiagnosticAnalyzerTests.cs index f8dde5edc9765..9b61d8c724784 100644 --- a/src/Compilers/CSharp/Test/Emit2/Diagnostics/DiagnosticAnalyzerTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/Diagnostics/DiagnosticAnalyzerTests.cs @@ -715,8 +715,6 @@ public void TestDescriptorForConfigurableCompilerDiagnostics() var analyzer = new CSharpCompilerDiagnosticAnalyzer(); foreach (var descriptor in analyzer.SupportedDiagnostics) { - Assert.True(descriptor.IsEnabledByDefault); - if (descriptor.IsNotConfigurable()) { continue; diff --git a/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/FlowDiagnosticTests.cs b/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/FlowDiagnosticTests.cs index ce5a3b5caa5f1..0937cf58b53d4 100644 --- a/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/FlowDiagnosticTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/FlowDiagnosticTests.cs @@ -1207,15 +1207,34 @@ struct S int x, y; S(int x) { this.x = x; } }"; - CreateCompilation(program) + CreateCompilation(program, parseOptions: TestOptions.Regular10) .VerifyDiagnostics( - // (5,5): error CS0171: Field 'S.y' must be fully assigned before control is returned to the caller + // (5,5): error CS0171: Field 'S.y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // S(int x) { this.x = x; } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("S.y"), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.y", "preview").WithLocation(5, 5), // (4,12): warning CS0169: The field 'S.y' is never used // int x, y; - Diagnostic(ErrorCode.WRN_UnreferencedField, "y").WithArguments("S.y") + Diagnostic(ErrorCode.WRN_UnreferencedField, "y").WithArguments("S.y").WithLocation(4, 12) ); + + var verifier = CompileAndVerify(program, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics( + // (4,12): warning CS0169: The field 'S.y' is never used + // int x, y; + Diagnostic(ErrorCode.WRN_UnreferencedField, "y").WithArguments("S.y").WithLocation(4, 12)); + verifier.VerifyIL("S..ctor", @" +{ + // Code size 15 (0xf) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int S.y"" + IL_0007: ldarg.0 + IL_0008: ldarg.1 + IL_0009: stfld ""int S.x"" + IL_000e: ret +} +"); } [WorkItem(543429, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543429")] @@ -1252,10 +1271,23 @@ public static void Main(string[] args) { } }"; - CreateCompilation(program) + CreateCompilation(program, parseOptions: TestOptions.Regular10) .VerifyDiagnostics( - // (5,12): error CS0843: Backing field for automatically implemented property 'Program.X' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer. - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "Program").WithArguments("Program.X")); + // (5,12): error CS0843: Auto-implemented property 'Program.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. + // public Program(int x) + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "Program").WithArguments("Program.X", "preview").WithLocation(5, 12)); + + var verifier = CompileAndVerify(program, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", @" +{ + // Code size 8 (0x8) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int Program.k__BackingField"" + IL_0007: ret +}"); } [Fact] @@ -1340,23 +1372,29 @@ static void Main(string[] args) } }"; - var comp = CreateCompilation(text); + var comp = CreateCompilation(text, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( // (16,9): error CS1612: Cannot modify the return value of 'Program.x' because it is not a variable // x.i = 1; Diagnostic(ErrorCode.ERR_ReturnNotLValue, "x").WithArguments("Program.x").WithLocation(16, 9), - // (16,9): error CS0170: Use of possibly unassigned field 'i' + // (16,9): error CS9014: Use of possibly unassigned field 'i'. Consider updating to language version 'preview' to auto-default the field. // x.i = 1; - Diagnostic(ErrorCode.ERR_UseDefViolationField, "x.i").WithArguments("i").WithLocation(16, 9), - // (17,34): error CS8079: Use of possibly unassigned auto-implemented property 'x2' + Diagnostic(ErrorCode.ERR_UseDefViolationFieldUnsupportedVersion, "x.i").WithArguments("i", "preview").WithLocation(16, 9), + // (17,34): error CS9013: Use of possibly unassigned auto-implemented property 'x2'. Consider updating to language version 'preview' to auto-default the property. // System.Console.WriteLine(x2.ii); - Diagnostic(ErrorCode.ERR_UseDefViolationProperty, "x2").WithArguments("x2").WithLocation(17, 34), - // (14,12): error CS0843: Auto-implemented property 'Program.x' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.ERR_UseDefViolationPropertyUnsupportedVersion, "x2").WithArguments("x2", "preview").WithLocation(17, 34), + // (14,12): error CS0843: Auto-implemented property 'Program.x' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public Program(int dummy) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "Program").WithArguments("Program.x").WithLocation(14, 12), - // (14,12): error CS0843: Auto-implemented property 'Program.x2' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "Program").WithArguments("Program.x", "preview").WithLocation(14, 12), + // (14,12): error CS0843: Auto-implemented property 'Program.x2' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public Program(int dummy) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "Program").WithArguments("Program.x2").WithLocation(14, 12)); + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "Program").WithArguments("Program.x2", "preview").WithLocation(14, 12)); + + comp = CreateCompilation(text, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (16,9): error CS1612: Cannot modify the return value of 'Program.x' because it is not a variable + // x.i = 1; + Diagnostic(ErrorCode.ERR_ReturnNotLValue, "x").WithArguments("Program.x").WithLocation(16, 9)); } [Fact] @@ -1391,23 +1429,47 @@ static void Main(string[] args) } }"; - var comp = CreateCompilation(text); + var comp = CreateCompilation(text, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( // (16,9): error CS1612: Cannot modify the return value of 'Program.x' because it is not a variable // x.i = 1; Diagnostic(ErrorCode.ERR_ReturnNotLValue, "x").WithArguments("Program.x").WithLocation(16, 9), - // (16,9): error CS0170: Use of possibly unassigned field 'i' + // (16,9): error CS9014: Use of possibly unassigned field 'i'. Consider updating to language version 'preview' to auto-default the field. // x.i = 1; - Diagnostic(ErrorCode.ERR_UseDefViolationField, "x.i").WithArguments("i").WithLocation(16, 9), - // (17,34): error CS8079: Use of possibly unassigned auto-implemented property 'x2' + Diagnostic(ErrorCode.ERR_UseDefViolationFieldUnsupportedVersion, "x.i").WithArguments("i", "preview").WithLocation(16, 9), + // (17,34): error CS9013: Use of possibly unassigned auto-implemented property 'x2'. Consider updating to language version 'preview' to auto-default the property. // System.Console.WriteLine(x2.ii); - Diagnostic(ErrorCode.ERR_UseDefViolationProperty, "x2").WithArguments("x2").WithLocation(17, 34), - // (14,12): error CS0843: Auto-implemented property 'Program.x' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.ERR_UseDefViolationPropertyUnsupportedVersion, "x2").WithArguments("x2", "preview").WithLocation(17, 34), + // (14,12): error CS0843: Auto-implemented property 'Program.x' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public Program(int dummy) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "Program").WithArguments("Program.x").WithLocation(14, 12), - // (14,12): error CS0843: Auto-implemented property 'Program.x2' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "Program").WithArguments("Program.x", "preview").WithLocation(14, 12), + // (14,12): error CS0843: Auto-implemented property 'Program.x2' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public Program(int dummy) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "Program").WithArguments("Program.x2").WithLocation(14, 12)); + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "Program").WithArguments("Program.x2", "preview").WithLocation(14, 12)); + + comp = CreateCompilation(text, options: TestOptions.DebugDll.WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (14,12): warning CS9020: Control is returned to caller before auto-implemented property 'Program.x' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // public Program(int dummy) + Diagnostic(ErrorCode.WRN_UnassignedThisAutoPropertySupportedVersion, "Program").WithArguments("Program.x").WithLocation(14, 12), + // (14,12): warning CS9020: Control is returned to caller before auto-implemented property 'Program.x2' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // public Program(int dummy) + Diagnostic(ErrorCode.WRN_UnassignedThisAutoPropertySupportedVersion, "Program").WithArguments("Program.x2").WithLocation(14, 12), + // (16,9): error CS1612: Cannot modify the return value of 'Program.x' because it is not a variable + // x.i = 1; + Diagnostic(ErrorCode.ERR_ReturnNotLValue, "x").WithArguments("Program.x").WithLocation(16, 9), + // (16,9): warning CS9018: Field 'i' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + // x.i = 1; + Diagnostic(ErrorCode.WRN_UseDefViolationFieldSupportedVersion, "x.i").WithArguments("i").WithLocation(16, 9), + // (17,34): warning CS9017: Auto-implemented property 'x2' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + // System.Console.WriteLine(x2.ii); + Diagnostic(ErrorCode.WRN_UseDefViolationPropertySupportedVersion, "x2").WithArguments("x2").WithLocation(17, 34)); + + comp = CreateCompilation(text, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (16,9): error CS1612: Cannot modify the return value of 'Program.x' because it is not a variable + // x.i = 1; + Diagnostic(ErrorCode.ERR_ReturnNotLValue, "x").WithArguments("Program.x").WithLocation(16, 9)); } [Fact] @@ -1675,8 +1737,7 @@ static void Main(string[] args) } }"; - var comp = CreateCompilation(text); - // no errors since S1 is empty + var comp = CreateCompilation(text, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( // (15,17): error CS0206: A property or indexer may not be passed as an out or ref parameter // Goo(out x1); @@ -1693,15 +1754,37 @@ static void Main(string[] args) // (20,17): error CS1620: Argument 1 must be passed with the 'out' keyword // Goo(ref x3); Diagnostic(ErrorCode.ERR_BadArgRef, "x3").WithArguments("1", "out").WithLocation(20, 17), - // (15,17): error CS8079: Use of automatically implemented property 'x1' whose backing field is possibly unassigned + // (15,17): error CS9013: Use of possibly unassigned auto-implemented property 'x1'. Consider updating to language version 'preview' to auto-default the property. + // Goo(out x1); + Diagnostic(ErrorCode.ERR_UseDefViolationPropertyUnsupportedVersion, "x1").WithArguments("x1", "preview").WithLocation(15, 17), + // (16,9): error CS0188: The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version 'this' to auto-default the unassigned fields. + // Goo(ref x1); + Diagnostic(ErrorCode.ERR_UseDefViolationThisUnsupportedVersion, "Goo").WithArguments("this", "preview").WithLocation(16, 9), + // (17,17): error CS9013: Use of possibly unassigned auto-implemented property 'x2'. Consider updating to language version 'preview' to auto-default the property. + // Goo(out x2); + Diagnostic(ErrorCode.ERR_UseDefViolationPropertyUnsupportedVersion, "x2").WithArguments("x2", "preview").WithLocation(17, 17), + // (6,20): warning CS0649: Field 'Program.S1.x' is never assigned to, and will always have its default value 0 + // public int x; + Diagnostic(ErrorCode.WRN_UnassignedInternalField, "x").WithArguments("Program.S1.x", "0").WithLocation(6, 20) + ); + + comp = CreateCompilation(text, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (15,17): error CS0206: A property or indexer may not be passed as an out or ref parameter // Goo(out x1); - Diagnostic(ErrorCode.ERR_UseDefViolationProperty, "x1").WithArguments("x1").WithLocation(15, 17), - // (16,9): error CS0188: The 'this' object cannot be used before all of its fields are assigned to + Diagnostic(ErrorCode.ERR_RefProperty, "x1").WithArguments("Program.x1").WithLocation(15, 17), + // (16,17): error CS0206: A property or indexer may not be passed as an out or ref parameter // Goo(ref x1); - Diagnostic(ErrorCode.ERR_UseDefViolationThis, "Goo").WithArguments("this").WithLocation(16, 9), - // (17,17): error CS8079: Use of automatically implemented property 'x2' whose backing field is possibly unassigned + Diagnostic(ErrorCode.ERR_RefProperty, "x1").WithArguments("Program.x1").WithLocation(16, 17), + // (17,17): error CS0206: A property or indexer may not be passed as an out or ref parameter // Goo(out x2); - Diagnostic(ErrorCode.ERR_UseDefViolationProperty, "x2").WithArguments("x2").WithLocation(17, 17), + Diagnostic(ErrorCode.ERR_RefProperty, "x2").WithArguments("Program.x2").WithLocation(17, 17), + // (18,17): error CS0206: A property or indexer may not be passed as an out or ref parameter + // Goo(ref x2); + Diagnostic(ErrorCode.ERR_RefProperty, "x2").WithArguments("Program.x2").WithLocation(18, 17), + // (20,17): error CS1620: Argument 1 must be passed with the 'out' keyword + // Goo(ref x3); + Diagnostic(ErrorCode.ERR_BadArgRef, "x3").WithArguments("1", "out").WithLocation(20, 17), // (6,20): warning CS0649: Field 'Program.S1.x' is never assigned to, and will always have its default value 0 // public int x; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "x").WithArguments("Program.S1.x", "0").WithLocation(6, 20) @@ -2311,17 +2394,27 @@ static void Goo(int y) { } }"; - CSharpCompilation comp = CreateCompilationWithMscorlib40AndSystemCore(source); + CSharpCompilation comp = CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( // (8,13): error CS1501: No overload for method 'Goo' takes 2 arguments // Goo(y, null); - Diagnostic(ErrorCode.ERR_BadArgCount, "Goo").WithArguments("Goo", "2"), - // (6,9): error CS0171: Field 'C.S.x' must be fully assigned before control is returned to the caller + Diagnostic(ErrorCode.ERR_BadArgCount, "Goo").WithArguments("Goo", "2").WithLocation(8, 13), + // (6,9): error CS0171: Field 'C.S.x' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // S(dynamic y) - Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("C.S.x"), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("C.S.x", "preview").WithLocation(6, 9), // (5,13): warning CS0169: The field 'C.S.x' is never used // int x; - Diagnostic(ErrorCode.WRN_UnreferencedField, "x").WithArguments("C.S.x") + Diagnostic(ErrorCode.WRN_UnreferencedField, "x").WithArguments("C.S.x").WithLocation(5, 13) + ); + + comp = CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (8,13): error CS1501: No overload for method 'Goo' takes 2 arguments + // Goo(y, null); + Diagnostic(ErrorCode.ERR_BadArgCount, "Goo").WithArguments("Goo", "2").WithLocation(8, 13), + // (5,13): warning CS0169: The field 'C.S.x' is never used + // int x; + Diagnostic(ErrorCode.WRN_UnreferencedField, "x").WithArguments("C.S.x").WithLocation(5, 13) ); } @@ -2458,11 +2551,21 @@ public void RegressionTest949324() } private int x; }"; - CSharpCompilation comp = CreateCompilationWithMscorlib40AndSystemCore(source); + CSharpCompilation comp = CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (3,5): error CS0171: Field 'Derived.x' must be fully assigned before control is returned to the caller + // (3,5): error CS0171: Field 'Derived.x' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // Derived(int x) { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "Derived").WithArguments("Derived.x").WithLocation(3, 5), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "Derived").WithArguments("Derived.x", "preview").WithLocation(3, 5), + // (4,28): error CS0103: The name 'p2' does not exist in the current context + // Derived(long x) : this(p2) // error CS0188: The 'this' object cannot be used before all of its fields are assigned to + Diagnostic(ErrorCode.ERR_NameNotInContext, "p2").WithArguments("p2").WithLocation(4, 28), + // (8,17): warning CS0169: The field 'Derived.x' is never used + // private int x; + Diagnostic(ErrorCode.WRN_UnreferencedField, "x").WithArguments("Derived.x").WithLocation(8, 17) + ); + + comp = CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( // (4,28): error CS0103: The name 'p2' does not exist in the current context // Derived(long x) : this(p2) // error CS0188: The 'this' object cannot be used before all of its fields are assigned to Diagnostic(ErrorCode.ERR_NameNotInContext, "p2").WithArguments("p2").WithLocation(4, 28), @@ -2579,11 +2682,17 @@ public S(object x, object y) G = y; } }"; - var comp = CreateCompilation(source); + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (6,12): error CS0171: Field 'S.F' must be fully assigned before control is returned to the caller + // (6,12): error CS0171: Field 'S.F' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S(object x, object y) - Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("S.F").WithLocation(6, 12), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.F", "preview").WithLocation(6, 12), + // (8,28): error CS1673: Anonymous methods, lambda expressions, query expressions, and local functions inside structs cannot access instance members of 'this'. Consider copying 'this' to a local variable outside the anonymous method, lambda expression, query expression, or local function and using the local instead. + // Action a = () => { F = x; }; + Diagnostic(ErrorCode.ERR_ThisStructNotInAnonMeth, "F").WithLocation(8, 28)); + + comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( // (8,28): error CS1673: Anonymous methods, lambda expressions, query expressions, and local functions inside structs cannot access instance members of 'this'. Consider copying 'this' to a local variable outside the anonymous method, lambda expression, query expression, or local function and using the local instead. // Action a = () => { F = x; }; Diagnostic(ErrorCode.ERR_ThisStructNotInAnonMeth, "F").WithLocation(8, 28)); @@ -2603,11 +2712,20 @@ public S(object x, object y) G = y; } }"; - var comp = CreateCompilation(source); + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (5,12): error CS0171: Field 'S.F' must be fully assigned before control is returned to the caller + // (5,12): error CS0171: Field 'S.F' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S(object x, object y) - Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("S.F").WithLocation(5, 12), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.F", "preview").WithLocation(5, 12), + // (7,14): warning CS8321: The local function 'f' is declared but never used + // void f() { F = x; } + Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "f").WithArguments("f").WithLocation(7, 14), + // (7,20): error CS1673: Anonymous methods, lambda expressions, query expressions, and local functions inside structs cannot access instance members of 'this'. Consider copying 'this' to a local variable outside the anonymous method, lambda expression, query expression, or local function and using the local instead. + // void f() { F = x; } + Diagnostic(ErrorCode.ERR_ThisStructNotInAnonMeth, "F").WithLocation(7, 20)); + + comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( // (7,14): warning CS8321: The local function 'f' is declared but never used // void f() { F = x; } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "f").WithArguments("f").WithLocation(7, 14), diff --git a/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/FlowTestBase.cs b/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/FlowTestBase.cs index 264196dd4d224..36de006b6e532 100644 --- a/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/FlowTestBase.cs +++ b/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/FlowTestBase.cs @@ -19,7 +19,7 @@ public abstract class FlowTestBase : SemanticModelTestBase { internal ImmutableArray FlowDiagnostics(CSharpCompilation compilation) { - var flowDiagnostics = DiagnosticBag.GetInstance(); + var flowDiagnostics = BindingDiagnosticBag.GetInstance(); foreach (var method in AllMethods(compilation.SourceModule.GlobalNamespace)) { var sourceSymbol = method as SourceMemberMethodSymbol; @@ -28,14 +28,15 @@ internal ImmutableArray FlowDiagnostics(CSharpCompilation compilatio continue; } - var boundBody = MethodCompiler.BindMethodBody(sourceSymbol, new TypeCompilationState(sourceSymbol.ContainingType, compilation, null), new BindingDiagnosticBag(new DiagnosticBag())); + var compilationState = new TypeCompilationState(sourceSymbol.ContainingType, compilation, null); + var boundBody = MethodCompiler.BindMethodBody(sourceSymbol, compilationState, new BindingDiagnosticBag(new DiagnosticBag())); if (boundBody != null) { - FlowAnalysisPass.Rewrite(sourceSymbol, boundBody, flowDiagnostics, hasTrailingExpression: false, originalBodyNested: false); + FlowAnalysisPass.Rewrite(sourceSymbol, boundBody, compilationState, flowDiagnostics, hasTrailingExpression: false, originalBodyNested: false); } } - return flowDiagnostics.ToReadOnlyAndFree(); + return flowDiagnostics.ToReadOnlyAndFree().Diagnostics; } private IEnumerable AllMethods(Symbol symbol) diff --git a/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/LocalFunctions.cs b/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/LocalFunctions.cs index 637a6a0a59359..89041688b71f8 100644 --- a/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/LocalFunctions.cs +++ b/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/LocalFunctions.cs @@ -4,6 +4,7 @@ #nullable disable +using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Xunit; @@ -704,7 +705,7 @@ public static void Main() [Fact] public void UnassignedInStruct() { - var comp = CreateCompilation(@" + var source = @" struct S { int _x; @@ -717,20 +718,27 @@ void Local() } Local(); } -}"); +}"; + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( // (10,20): error CS1673: Anonymous methods, lambda expressions, query expressions, and local functions inside structs cannot access instance members of 'this'. Consider copying 'this' to a local variable outside the anonymous method, lambda expression, query expression, or local function and using the local instead. // s._x = _x; Diagnostic(ErrorCode.ERR_ThisStructNotInAnonMeth, "_x").WithLocation(10, 20), - // (7,17): error CS0188: The 'this' object cannot be used before all of its fields are assigned to + // (7,17): error CS0188: The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version 'this' to auto-default the unassigned fields. // var s = this; - Diagnostic(ErrorCode.ERR_UseDefViolationThis, "this").WithArguments("this").WithLocation(7, 17), - // (12,9): error CS0170: Use of possibly unassigned field '_x' + Diagnostic(ErrorCode.ERR_UseDefViolationThisUnsupportedVersion, "this").WithArguments("this", "preview").WithLocation(7, 17), + // (12,9): error CS9014: Use of possibly unassigned field '_x'. Consider updating to language version 'preview' to auto-default the field. // Local(); - Diagnostic(ErrorCode.ERR_UseDefViolationField, "Local()").WithArguments("_x").WithLocation(12, 9), - // (5,12): error CS0171: Field 'S._x' must be fully assigned before control is returned to the caller + Diagnostic(ErrorCode.ERR_UseDefViolationFieldUnsupportedVersion, "Local()").WithArguments("_x", "preview").WithLocation(12, 9), + // (5,12): error CS0171: Field 'S._x' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S(int x) - Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("S._x").WithLocation(5, 12)); + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S._x", "preview").WithLocation(5, 12)); + + comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (10,20): error CS1673: Anonymous methods, lambda expressions, query expressions, and local functions inside structs cannot access instance members of 'this'. Consider copying 'this' to a local variable outside the anonymous method, lambda expression, query expression, or local function and using the local instead. + // s._x = _x; + Diagnostic(ErrorCode.ERR_ThisStructNotInAnonMeth, "_x").WithLocation(10, 20)); } [Fact] @@ -1470,7 +1478,7 @@ void Local() [WorkItem(14097, "https://github.com/dotnet/roslyn/issues/14097")] public void PiecewiseStructAssignmentInConstructor2() { - var comp = CreateCompilation(@" + var source = @" struct S { public int _x; @@ -1486,14 +1494,21 @@ void Local() Local(); _x = 0; } -}"); +}"; + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( // (12,20): error CS1673: Anonymous methods, lambda expressions, query expressions, and local functions inside structs cannot access instance members of 'this'. Consider copying 'this' to a local variable outside the anonymous method, lambda expression, query expression, or local function and using the local instead. // S s2 = this; Diagnostic(ErrorCode.ERR_ThisStructNotInAnonMeth, "this").WithLocation(12, 20), - // (14,9): error CS0170: Use of possibly unassigned field '_x' + // (14,9): error CS9014: Use of possibly unassigned field '_x'. Consider updating to language version 'preview' to auto-default the field. // Local(); - Diagnostic(ErrorCode.ERR_UseDefViolationField, "Local()").WithArguments("_x").WithLocation(14, 9)); + Diagnostic(ErrorCode.ERR_UseDefViolationFieldUnsupportedVersion, "Local()").WithArguments("_x", "preview").WithLocation(14, 9)); + + comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (12,20): error CS1673: Anonymous methods, lambda expressions, query expressions, and local functions inside structs cannot access instance members of 'this'. Consider copying 'this' to a local variable outside the anonymous method, lambda expression, query expression, or local function and using the local instead. + // S s2 = this; + Diagnostic(ErrorCode.ERR_ThisStructNotInAnonMeth, "this").WithLocation(12, 20)); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/RegionAnalysisTests.cs b/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/RegionAnalysisTests.cs index 39405f7261a96..128f14009c14a 100644 --- a/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/RegionAnalysisTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/FlowAnalysis/RegionAnalysisTests.cs @@ -6427,19 +6427,28 @@ public void FieldBeforeAssignedInStructCtor() this.value = null; } }"; - var compilation = CreateCompilation(source); + var compilation = CreateCompilation(source, parseOptions: TestOptions.Regular10); compilation.VerifyDiagnostics( - // (6,18): error CS0170: Use of possibly unassigned field 'value' + // (6,18): error CS9014: Use of possibly unassigned field 'value'. Consider updating to language version 'preview' to auto-default the field. // S.Equals(value , value); - Diagnostic(ErrorCode.ERR_UseDefViolationField, "value").WithArguments("value") + Diagnostic(ErrorCode.ERR_UseDefViolationFieldUnsupportedVersion, "value").WithArguments("value", "preview").WithLocation(6, 18) ); - var tree = compilation.SyntaxTrees[0]; - var model = compilation.GetSemanticModel(tree); - var root = tree.GetRoot(); - var expression = GetLastNode(tree, root.ToFullString().IndexOf("value ", StringComparison.Ordinal)); - var analysis = model.AnalyzeDataFlow(expression); - Assert.True(analysis.Succeeded); - Assert.Null(GetSymbolNamesJoined(analysis.DataFlowsOut)); + verify(); + + compilation = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + compilation.VerifyDiagnostics(); + verify(); + + void verify() + { + var tree = compilation.SyntaxTrees[0]; + var model = compilation.GetSemanticModel(tree); + var root = tree.GetRoot(); + var expression = GetLastNode(tree, root.ToFullString().IndexOf("value ", StringComparison.Ordinal)); + var analysis = model.AnalyzeDataFlow(expression); + Assert.True(analysis.Succeeded); + Assert.Null(GetSymbolNamesJoined(analysis.DataFlowsOut)); + } } [Fact, WorkItem(14110, "https://github.com/dotnet/roslyn/issues/14110")] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index e3152edfd8706..caaadc4583465 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -60385,7 +60385,7 @@ struct C2 public C2(C0 x2) { - x2 = P2; // 3, 4 + x2 = P2; // 3 P2 = null; } } @@ -60397,7 +60397,7 @@ struct C3 public C3(C0 x3, C0? y3) { P3 = y3; - x3 = P3; // 5 + x3 = P3; // 4 } } @@ -60440,13 +60440,10 @@ struct S1 // public C1(C0? x1) // 1 Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "C1").WithArguments("property", "P1").WithLocation(10, 12), // (34,14): warning CS8600: Converting null literal or possible null value to non-nullable type. - // x3 = P3; // 5 + // x3 = P3; // 4 Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "P3").WithLocation(34, 14), - // (22,14): error CS8079: Use of possibly unassigned auto-implemented property 'P2' - // x2 = P2; // 3, 4 - Diagnostic(ErrorCode.ERR_UseDefViolationProperty, "P2").WithArguments("P2").WithLocation(22, 14), // (22,14): warning CS8600: Converting null literal or possible null value to non-nullable type. - // x2 = P2; // 3, 4 + // x2 = P2; // 3 Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "P2").WithLocation(22, 14) ); } @@ -79061,13 +79058,15 @@ void M(out object o) Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "P").WithLocation(7, 9)); } - [Fact] - public void UnassignedStructAutoProperty_Constructor() + [Theory] + [InlineData("object")] + [InlineData("object?")] + public void UnassignedStructAutoProperty_Constructor(string propertyType) { var source = @"struct S { - object? P { get; } + " + propertyType + @" P { get; } S(out object o) { o = P; @@ -79076,12 +79075,6 @@ public void UnassignedStructAutoProperty_Constructor() }"; var comp = CreateCompilation(new[] { source }, options: WithNullableEnable()); comp.VerifyDiagnostics( - // (6,13): error CS8079: Use of possibly unassigned auto-implemented property 'P' - // o = P; - Diagnostic(ErrorCode.ERR_UseDefViolationProperty, "P").WithArguments("P").WithLocation(6, 13), - // (4,5): error CS0843: Auto-implemented property 'S.P' must be fully assigned before control is returned to the caller. - // S(out object o) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S").WithArguments("S.P").WithLocation(4, 5), // (6,13): warning CS8601: Possible null reference assignment. // o = P; Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "P").WithLocation(6, 13), diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordStructTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordStructTests.cs index 4b10177ed3557..1ebcc7e418621 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordStructTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordStructTests.cs @@ -1945,15 +1945,35 @@ public static void Main() Console.WriteLine(c.Y); } }"; - var comp = CreateCompilation(src); + var comp = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); comp.VerifyEmitDiagnostics( - // (3,15): error CS0843: Auto-implemented property 'C.X' must be fully assigned before control is returned to the caller. + // (3,15): error CS0843: Auto-implemented property 'C.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. + // record struct C(int X, int Y) + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "C").WithArguments("C.X", "preview").WithLocation(3, 15), + // (3,21): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? // record struct C(int X, int Y) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "C").WithArguments("C.X").WithLocation(3, 15), + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(3, 21) + ); + + var verifier = CompileAndVerify(src, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics( // (3,21): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? // record struct C(int X, int Y) Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(3, 21) ); + verifier.VerifyIL("C..ctor(int, int)", @" +{ + // Code size 15 (0xf) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int C.k__BackingField"" + IL_0007: ldarg.0 + IL_0008: ldarg.2 + IL_0009: stfld ""int C.k__BackingField"" + IL_000e: ret +} +"); } [Fact] @@ -2180,7 +2200,7 @@ record struct C(object P) [Fact] public void RecordProperties_11_UnreadPositionalParameter() { - var comp = CreateCompilation(@" + var source = @" record struct C1(object O1, object O2, object O3) // 1, 2 { public object O1 { get; init; } @@ -2188,11 +2208,12 @@ record struct C1(object O1, object O2, object O3) // 1, 2 public object O3 { get; init; } = M(O3 = null); private static object M(object o) => o; } -"); +"; + var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (2,15): error CS0843: Auto-implemented property 'C1.O1' must be fully assigned before control is returned to the caller. + // (2,15): error CS0843: Auto-implemented property 'C1.O1' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // record struct C1(object O1, object O2, object O3) // 1, 2 - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "C1").WithArguments("C1.O1").WithLocation(2, 15), + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "C1").WithArguments("C1.O1", "preview").WithLocation(2, 15), // (2,25): warning CS8907: Parameter 'O1' is unread. Did you forget to use it to initialize the property with that name? // record struct C1(object O1, object O2, object O3) // 1, 2 Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "O1").WithArguments("O1").WithLocation(2, 25), @@ -2200,6 +2221,35 @@ record struct C1(object O1, object O2, object O3) // 1, 2 // record struct C1(object O1, object O2, object O3) // 1, 2 Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "O3").WithArguments("O3").WithLocation(2, 47) ); + + var verifier = CompileAndVerify(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularNext, verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (2,25): warning CS8907: Parameter 'O1' is unread. Did you forget to use it to initialize the property with that name? + // record struct C1(object O1, object O2, object O3) // 1, 2 + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "O1").WithArguments("O1").WithLocation(2, 25), + // (2,47): warning CS8907: Parameter 'O3' is unread. Did you forget to use it to initialize the property with that name? + // record struct C1(object O1, object O2, object O3) // 1, 2 + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "O3").WithArguments("O3").WithLocation(2, 47)); + verifier.VerifyIL("C1..ctor(object, object, object)", @" +{ + // Code size 35 (0x23) + .maxstack 3 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""object C1.k__BackingField"" + IL_0007: ldarg.0 + IL_0008: ldarg.2 + IL_0009: call ""object C1.M(object)"" + IL_000e: stfld ""object C1.k__BackingField"" + IL_0013: ldarg.0 + IL_0014: ldnull + IL_0015: dup + IL_0016: starg.s V_3 + IL_0018: call ""object C1.M(object)"" + IL_001d: stfld ""object C1.k__BackingField"" + IL_0022: ret +} +"); } [Fact] @@ -2841,15 +2891,32 @@ public static void Main() } } "; - var comp = CreateCompilation(src); + var comp = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (2,15): error CS0843: Auto-implemented property 'R.P' must be fully assigned before control is returned to the caller. + // (2,15): error CS0843: Auto-implemented property 'R.P' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // record struct R(int P = 42) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "R").WithArguments("R.P").WithLocation(2, 15), + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "R").WithArguments("R.P", "preview").WithLocation(2, 15), // (2,21): warning CS8907: Parameter 'P' is unread. Did you forget to use it to initialize the property with that name? // record struct R(int P = 42) Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "P").WithArguments("P").WithLocation(2, 21) ); + + var verifier = CompileAndVerify(new[] { src, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularNext, verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (2,21): warning CS8907: Parameter 'P' is unread. Did you forget to use it to initialize the property with that name? + // record struct R(int P = 42) + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "P").WithArguments("P").WithLocation(2, 21) + ); + verifier.VerifyIL("R..ctor(int)", @" +{ + // Code size 8 (0x8) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int R.

k__BackingField"" + IL_0007: ret +} +"); } [Fact] @@ -3932,11 +3999,18 @@ record struct Pos2(int X) public int X { get { return x; } set { x = value; } } } "; - var comp = CreateCompilation(source); + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); comp.VerifyEmitDiagnostics( - // (2,15): error CS0171: Field 'Pos.x' must be fully assigned before control is returned to the caller + // (2,15): error CS0171: Field 'Pos.x' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // record struct Pos(int X) - Diagnostic(ErrorCode.ERR_UnassignedThis, "Pos").WithArguments("Pos.x").WithLocation(2, 15), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "Pos").WithArguments("Pos.x", "preview").WithLocation(2, 15), + // (5,16): error CS8050: Only auto-implemented properties can have initializers. + // public int X { get { return x; } set { x = value; } } = X; + Diagnostic(ErrorCode.ERR_InitializerOnNonAutoProperty, "X").WithArguments("Pos.X").WithLocation(5, 16) + ); + + comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyEmitDiagnostics( // (5,16): error CS8050: Only auto-implemented properties can have initializers. // public int X { get { return x; } set { x = value; } } = X; Diagnostic(ErrorCode.ERR_InitializerOnNonAutoProperty, "X").WithArguments("Pos.X").WithLocation(5, 16) @@ -7451,12 +7525,34 @@ record struct C } "; - var comp = CreateCompilation(src); + var comp = CreateCompilation(src, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (8,13): error CS0188: The 'this' object cannot be used before all of its fields have been assigned + // (8,13): error CS0188: The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version 'this' to auto-default the unassigned fields. // _ = this with { X = 42 }; // 1 - Diagnostic(ErrorCode.ERR_UseDefViolationThis, "this").WithArguments("this").WithLocation(8, 13) + Diagnostic(ErrorCode.ERR_UseDefViolationThisUnsupportedVersion, "this").WithArguments("this", "preview").WithLocation(8, 13) ); + + var verifier = CompileAndVerify(src, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("C..ctor(string)", @" +{ + // Code size 31 (0x1f) + .maxstack 2 + .locals init (C V_0) + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int C.k__BackingField"" + IL_0007: ldarg.0 + IL_0008: ldobj ""C"" + IL_000d: stloc.0 + IL_000e: ldloca.s V_0 + IL_0010: ldc.i4.s 42 + IL_0012: call ""void C.X.set"" + IL_0017: ldarg.0 + IL_0018: initobj ""C"" + IL_001e: ret +} +"); } [Fact] @@ -11131,11 +11227,20 @@ public void ExplicitConstructors_10() public object F; public S(int i) : this() { F = i; } }"; - var comp = CreateCompilation(source); + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (1,15): error CS0171: Field 'S.F' must be fully assigned before control is returned to the caller + // (1,15): error CS0171: Field 'S.F' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. + // record struct S(object F) + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.F", "preview").WithLocation(1, 15), + // (1,24): warning CS8907: Parameter 'F' is unread. Did you forget to use it to initialize the property with that name? // record struct S(object F) - Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("S.F").WithLocation(1, 15), + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "F").WithArguments("F").WithLocation(1, 24), + // (4,23): error CS8982: A constructor declared in a 'record struct' with parameter list must have a 'this' initializer that calls the primary constructor or an explicitly declared constructor. + // public S(int i) : this() { F = i; } + Diagnostic(ErrorCode.ERR_RecordStructConstructorCallsDefaultConstructor, "this").WithLocation(4, 23)); + + comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( // (1,24): warning CS8907: Parameter 'F' is unread. Did you forget to use it to initialize the property with that name? // record struct S(object F) Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "F").WithArguments("F").WithLocation(1, 24), diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index 19e90100b283e..9412dcf3b0640 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -6464,11 +6464,21 @@ public static void Main() MyStruct aStruct = new MyStruct(); } }"; - var comp = CreateCompilation(text); + var comp = CreateCompilation(text, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (4,4): error CS0171: Field 'MyStruct.i' must be fully assigned before control is returned to the caller + // (4,4): error CS0171: Field 'MyStruct.i' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // MyStruct(int initField) // CS0171 - Diagnostic(ErrorCode.ERR_UnassignedThis, "MyStruct").WithArguments("MyStruct.i"), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "MyStruct").WithArguments("MyStruct.i", "preview").WithLocation(4, 4), + // (15,16): warning CS0219: The variable 'aStruct' is assigned but its value is never used + // MyStruct aStruct = new MyStruct(); + Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "aStruct").WithArguments("aStruct").WithLocation(15, 16), + // (8,15): warning CS0649: Field 'MyStruct.i' is never assigned to, and will always have its default value 0 + // public int i; + Diagnostic(ErrorCode.WRN_UnassignedInternalField, "i").WithArguments("MyStruct.i", "0").WithLocation(8, 15) + ); + + var verifier = CompileAndVerify(text, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics( // (15,16): warning CS0219: The variable 'aStruct' is assigned but its value is never used // MyStruct aStruct = new MyStruct(); Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "aStruct").WithArguments("aStruct"), @@ -6476,6 +6486,15 @@ public static void Main() // public int i; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "i").WithArguments("MyStruct.i", "0") ); + verifier.VerifyIL("MyStruct..ctor", @" +{ + // Code size 8 (0x8) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int MyStruct.i"" + IL_0007: ret +}"); } [Fact] @@ -6961,14 +6980,31 @@ public static void Main() } }"; - CreateCompilation(text). + CreateCompilation(text, parseOptions: TestOptions.Regular10). VerifyDiagnostics( - // (17,17): error CS0188: The 'this' object cannot be used before all of its fields are assigned to + // (17,17): error CS0188: The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version 'this' to auto-default the unassigned fields. // Goo(); // CS0188 - Diagnostic(ErrorCode.ERR_UseDefViolationThis, "Goo").WithArguments("this"), + Diagnostic(ErrorCode.ERR_UseDefViolationThisUnsupportedVersion, "Goo").WithArguments("this", "preview").WithLocation(17, 17), + // (8,24): warning CS0649: Field 'MyClass.S.a' is never assigned to, and will always have its default value 0 + // public int a; + Diagnostic(ErrorCode.WRN_UnassignedInternalField, "a").WithArguments("MyNamespace.MyClass.S.a", "0").WithLocation(8, 24)); + + var verifier = CompileAndVerify(text, parseOptions: TestOptions.RegularNext). + VerifyDiagnostics( // (8,24): warning CS0649: Field 'MyNamespace.MyClass.S.a' is never assigned to, and will always have its default value 0 // public int a; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "a").WithArguments("MyNamespace.MyClass.S.a", "0")); + verifier.VerifyIL("MyNamespace.MyClass.S..ctor", @" +{ + // Code size 14 (0xe) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int MyNamespace.MyClass.S.a"" + IL_0007: ldarg.0 + IL_0008: call ""void MyNamespace.MyClass.S.Goo()"" + IL_000d: ret +}"); } [Fact, WorkItem(579533, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/579533"), WorkItem(864605, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/864605")] @@ -6992,11 +7028,17 @@ void F() } }"; - CreateCompilationWithMscorlib40AndSystemCore(source).VerifyDiagnostics( + CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (10,18): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. + // var b1 = F is Action; Diagnostic(ErrorCode.ERR_LambdaInIsAs, "F is Action").WithLocation(10, 18), - // (10,18): error CS0188: The 'this' object cannot be used before all of its fields are assigned to - Diagnostic(ErrorCode.ERR_UseDefViolationThis, "F").WithArguments("this")); + // (10,18): error CS0188: The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version 'this' to auto-default the unassigned fields. + // var b1 = F is Action; + Diagnostic(ErrorCode.ERR_UseDefViolationThisUnsupportedVersion, "F").WithArguments("this", "preview").WithLocation(10, 18)); + + CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( + // (10,18): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. + Diagnostic(ErrorCode.ERR_LambdaInIsAs, "F is Action").WithLocation(10, 18)); } [Fact, WorkItem(579533, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/579533"), WorkItem(864605, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/864605")] @@ -7020,13 +7062,18 @@ void F() } }"; - CreateCompilationWithMscorlib40AndSystemCore(source).VerifyDiagnostics( + CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (10,18): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. // var b1 = this.F is Action; Diagnostic(ErrorCode.ERR_LambdaInIsAs, "this.F is Action").WithLocation(10, 18), - // (10,18): error CS0188: The 'this' object cannot be used before all of its fields are assigned to + // (10,18): error CS0188: The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version 'this' to auto-default the unassigned fields. // var b1 = this.F is Action; - Diagnostic(ErrorCode.ERR_UseDefViolationThis, "this").WithArguments("this")); + Diagnostic(ErrorCode.ERR_UseDefViolationThisUnsupportedVersion, "this").WithArguments("this", "preview").WithLocation(10, 18)); + + CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( + // (10,18): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. + // var b1 = this.F is Action; + Diagnostic(ErrorCode.ERR_LambdaInIsAs, "this.F is Action").WithLocation(10, 18)); } [Fact, WorkItem(579533, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/579533")] @@ -7051,9 +7098,53 @@ void Add(int value) } } "; - CreateCompilationWithMscorlib40AndSystemCore(source).VerifyDiagnostics( - // (10,19): error CS0188: The 'this' object cannot be used before all of its fields are assigned to - Diagnostic(ErrorCode.ERR_UseDefViolationThis, "Add").WithArguments("this")); + CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.Regular10).VerifyDiagnostics( + // (10,19): error CS0188: The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version 'this' to auto-default the unassigned fields. + // /*this.*/ Add(d); + Diagnostic(ErrorCode.ERR_UseDefViolationThisUnsupportedVersion, "Add").WithArguments("this", "preview").WithLocation(10, 19)); + + var verifier = CompileAndVerify(source, new[] { CSharpRef }, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("S..ctor", @" +{ + // Code size 105 (0x69) + .maxstack 9 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""dynamic S.value"" + IL_0007: ldsfld ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> S.<>o__1.<>p__0"" + IL_000c: brtrue.s IL_004d + IL_000e: ldc.i4 0x102 + IL_0013: ldstr ""Add"" + IL_0018: ldnull + IL_0019: ldtoken ""S"" + IL_001e: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" + IL_0023: ldc.i4.2 + IL_0024: newarr ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo"" + IL_0029: dup + IL_002a: ldc.i4.0 + IL_002b: ldc.i4.s 9 + IL_002d: ldnull + IL_002e: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" + IL_0033: stelem.ref + IL_0034: dup + IL_0035: ldc.i4.1 + IL_0036: ldc.i4.0 + IL_0037: ldnull + IL_0038: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" + IL_003d: stelem.ref + IL_003e: call ""System.Runtime.CompilerServices.CallSiteBinder Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, string, System.Collections.Generic.IEnumerable, System.Type, System.Collections.Generic.IEnumerable)"" + IL_0043: call ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> System.Runtime.CompilerServices.CallSite<<>A{00000004}>.Create(System.Runtime.CompilerServices.CallSiteBinder)"" + IL_0048: stsfld ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> S.<>o__1.<>p__0"" + IL_004d: ldsfld ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> S.<>o__1.<>p__0"" + IL_0052: ldfld ""<>A{00000004} System.Runtime.CompilerServices.CallSite<<>A{00000004}>.Target"" + IL_0057: ldsfld ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> S.<>o__1.<>p__0"" + IL_005c: ldarg.0 + IL_005d: ldarg.1 + IL_005e: callvirt ""void <>A{00000004}.Invoke(System.Runtime.CompilerServices.CallSite, ref S, dynamic)"" + IL_0063: newobj ""System.NotImplementedException..ctor()"" + IL_0068: throw +}"); } [Fact, WorkItem(579533, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/579533")] @@ -7078,9 +7169,53 @@ void Add(int value) } } "; - CreateCompilationWithMscorlib40AndSystemCore(source).VerifyDiagnostics( - // (10,9): error CS0188: The 'this' object cannot be used before all of its fields are assigned to - Diagnostic(ErrorCode.ERR_UseDefViolationThis, "this").WithArguments("this")); + CreateCompilationWithMscorlib40AndSystemCore(source, parseOptions: TestOptions.Regular10).VerifyDiagnostics( + // (10,9): error CS0188: The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version 'this' to auto-default the unassigned fields. + // this.Add(d); + Diagnostic(ErrorCode.ERR_UseDefViolationThisUnsupportedVersion, "this").WithArguments("this", "preview").WithLocation(10, 9)); + + var verifier = CompileAndVerify(source, new[] { CSharpRef }, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("S..ctor", @" +{ + // Code size 105 (0x69) + .maxstack 9 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""dynamic S.value"" + IL_0007: ldsfld ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> S.<>o__1.<>p__0"" + IL_000c: brtrue.s IL_004d + IL_000e: ldc.i4 0x100 + IL_0013: ldstr ""Add"" + IL_0018: ldnull + IL_0019: ldtoken ""S"" + IL_001e: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" + IL_0023: ldc.i4.2 + IL_0024: newarr ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo"" + IL_0029: dup + IL_002a: ldc.i4.0 + IL_002b: ldc.i4.s 9 + IL_002d: ldnull + IL_002e: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" + IL_0033: stelem.ref + IL_0034: dup + IL_0035: ldc.i4.1 + IL_0036: ldc.i4.0 + IL_0037: ldnull + IL_0038: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" + IL_003d: stelem.ref + IL_003e: call ""System.Runtime.CompilerServices.CallSiteBinder Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, string, System.Collections.Generic.IEnumerable, System.Type, System.Collections.Generic.IEnumerable)"" + IL_0043: call ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> System.Runtime.CompilerServices.CallSite<<>A{00000004}>.Create(System.Runtime.CompilerServices.CallSiteBinder)"" + IL_0048: stsfld ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> S.<>o__1.<>p__0"" + IL_004d: ldsfld ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> S.<>o__1.<>p__0"" + IL_0052: ldfld ""<>A{00000004} System.Runtime.CompilerServices.CallSite<<>A{00000004}>.Target"" + IL_0057: ldsfld ""System.Runtime.CompilerServices.CallSite<<>A{00000004}> S.<>o__1.<>p__0"" + IL_005c: ldarg.0 + IL_005d: ldarg.1 + IL_005e: callvirt ""void <>A{00000004}.Invoke(System.Runtime.CompilerServices.CallSite, ref S, dynamic)"" + IL_0063: newobj ""System.NotImplementedException..ctor()"" + IL_0068: throw +}"); } [Fact] @@ -12781,8 +12916,23 @@ static int Main() } } "; - DiagnosticsUtils.VerifyErrorsAndGetCompilationWithMscorlib(text, - new ErrorDescription[] { new ErrorDescription { Code = (int)ErrorCode.ERR_UnassignedThisAutoProperty, Line = 5, Column = 12 } }); + CreateCompilation(text, parseOptions: TestOptions.Regular10) + .VerifyDiagnostics( + // (5,12): error CS0843: Auto-implemented property 'S.AIProp' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. + // public S(int i) { } //CS0843 + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S").WithArguments("S.AIProp", "preview").WithLocation(5, 12)); + + var verifier = CompileAndVerify(text, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("S..ctor", @" +{ + // Code size 8 (0x8) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int S.k__BackingField"" + IL_0007: ret +}"); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/StructConstructorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/StructConstructorTests.cs index fec19fb91cccc..330be3c3ed098 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/StructConstructorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/StructConstructorTests.cs @@ -876,21 +876,18 @@ static void Main() // (13,12): error CS8773: Feature 'parameterless struct constructors' is not available in C# 9.0. Please use language version 10.0 or greater. // public S1() { Y = 1; } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "S1").WithArguments("parameterless struct constructors", "10.0").WithLocation(13, 12), - // (13,12): error CS0171: Field 'S1.X' must be fully assigned before control is returned to the caller + // (13,12): error CS0171: Field 'S1.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S1() { Y = 1; } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S1").WithArguments("S1.X").WithLocation(13, 12), - // (20,12): error CS0171: Field 'S2.X' must be fully assigned before control is returned to the caller + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S1").WithArguments("S1.X", "preview").WithLocation(13, 12), + // (20,12): error CS0171: Field 'S2.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S2(object y) { Y = y; } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S2").WithArguments("S2.X").WithLocation(20, 12)); + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S2").WithArguments("S2.X", "preview").WithLocation(20, 12)); - comp = CreateCompilation(source, options: TestOptions.ReleaseExe); - comp.VerifyDiagnostics( - // (13,12): error CS0171: Field 'S1.X' must be fully assigned before control is returned to the caller - // public S1() { Y = 1; } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S1").WithArguments("S1.X").WithLocation(13, 12), - // (20,12): error CS0171: Field 'S2.X' must be fully assigned before control is returned to the caller - // public S2(object y) { Y = y; } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S2").WithArguments("S2.X").WithLocation(20, 12)); + var verifier = CompileAndVerify(source, parseOptions: TestOptions.RegularNext, expectedOutput: +@"(, ) +(, 1) +(, )"); + verifier.VerifyDiagnostics(); } [Fact] @@ -1397,18 +1394,18 @@ struct S4 // (11,12): error CS8773: Feature 'parameterless struct constructors' is not available in C# 9.0. Please use language version 10.0 or greater. // public S2() { } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "S2").WithArguments("parameterless struct constructors", "10.0").WithLocation(11, 12), - // (11,12): error CS0171: Field 'S2.Y' must be fully assigned before control is returned to the caller + // (11,12): error CS0171: Field 'S2.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S2() { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S2").WithArguments("S2.Y").WithLocation(11, 12), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S2").WithArguments("S2.Y", "preview").WithLocation(11, 12), // (16,21): error CS8773: Feature 'struct field initializers' is not available in C# 9.0. Please use language version 10.0 or greater. // internal object Y = 3; Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "Y").WithArguments("struct field initializers", "10.0").WithLocation(16, 21), // (17,12): error CS8773: Feature 'parameterless struct constructors' is not available in C# 9.0. Please use language version 10.0 or greater. // public S3() { Y = 3; } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "S3").WithArguments("parameterless struct constructors", "10.0").WithLocation(17, 12), - // (17,12): error CS0171: Field 'S3.X' must be fully assigned before control is returned to the caller + // (17,12): error CS0171: Field 'S3.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S3() { Y = 3; } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S3").WithArguments("S3.X").WithLocation(17, 12), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S3").WithArguments("S3.X", "preview").WithLocation(17, 12), // (22,21): error CS8773: Feature 'struct field initializers' is not available in C# 9.0. Please use language version 10.0 or greater. // internal object Y = 4; Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "Y").WithArguments("struct field initializers", "10.0").WithLocation(22, 21), @@ -1416,24 +1413,23 @@ struct S4 // public S4() { X = 4; } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "S4").WithArguments("parameterless struct constructors", "10.0").WithLocation(23, 12)); - var expectedDiagnostics = new[] - { + comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( // (2,8): error CS8983: A 'struct' with field initializers must include an explicitly declared constructor. // struct S1 Diagnostic(ErrorCode.ERR_StructHasInitializersAndNoDeclaredConstructor, "S1").WithLocation(2, 8), - // (11,12): error CS0171: Field 'S2.Y' must be fully assigned before control is returned to the caller + // (11,12): error CS0171: Field 'S2.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S2() { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S2").WithArguments("S2.Y").WithLocation(11, 12), - // (17,12): error CS0171: Field 'S3.X' must be fully assigned before control is returned to the caller + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S2").WithArguments("S2.Y", "preview").WithLocation(11, 12), + // (17,12): error CS0171: Field 'S3.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S3() { Y = 3; } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S3").WithArguments("S3.X").WithLocation(17, 12), - }; + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S3").WithArguments("S3.X", "preview").WithLocation(17, 12)); - comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(expectedDiagnostics); - - comp = CreateCompilation(source); - comp.VerifyDiagnostics(expectedDiagnostics); + comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (2,8): error CS8983: A 'struct' with field initializers must include an explicitly declared constructor. + // struct S1 + Diagnostic(ErrorCode.ERR_StructHasInitializersAndNoDeclaredConstructor, "S1").WithLocation(2, 8)); } [WorkItem(57870, "https://github.com/dotnet/roslyn/issues/57870")] @@ -1480,18 +1476,18 @@ struct S4 // (11,12): error CS8773: Feature 'parameterless struct constructors' is not available in C# 9.0. Please use language version 10.0 or greater. // public S2() { } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "S2").WithArguments("parameterless struct constructors", "10.0").WithLocation(11, 12), - // (11,12): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. + // (11,12): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public S2() { } - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S2").WithArguments("S2.Y").WithLocation(11, 12), + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S2").WithArguments("S2.Y", "preview").WithLocation(11, 12), // (16,21): error CS8773: Feature 'struct field initializers' is not available in C# 9.0. Please use language version 10.0 or greater. // internal object Y { get; } = 3; Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "Y").WithArguments("struct field initializers", "10.0").WithLocation(16, 21), // (17,12): error CS8773: Feature 'parameterless struct constructors' is not available in C# 9.0. Please use language version 10.0 or greater. // public S3() { Y = 3; } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "S3").WithArguments("parameterless struct constructors", "10.0").WithLocation(17, 12), - // (17,12): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. + // (17,12): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public S3() { Y = 3; } - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S3").WithArguments("S3.X").WithLocation(17, 12), + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S3").WithArguments("S3.X", "preview").WithLocation(17, 12), // (22,21): error CS8773: Feature 'struct field initializers' is not available in C# 9.0. Please use language version 10.0 or greater. // internal object Y { get; } = 4; Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "Y").WithArguments("struct field initializers", "10.0").WithLocation(22, 21), @@ -1499,24 +1495,23 @@ struct S4 // public S4() { X = 4; } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "S4").WithArguments("parameterless struct constructors", "10.0").WithLocation(23, 12)); - var expectedDiagnostics = new[] - { + comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( // (2,8): error CS8983: A 'struct' with field initializers must include an explicitly declared constructor. // struct S1 Diagnostic(ErrorCode.ERR_StructHasInitializersAndNoDeclaredConstructor, "S1").WithLocation(2, 8), - // (11,12): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. + // (11,12): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public S2() { } - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S2").WithArguments("S2.Y").WithLocation(11, 12), - // (17,12): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S2").WithArguments("S2.Y", "preview").WithLocation(11, 12), + // (17,12): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public S3() { Y = 3; } - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S3").WithArguments("S3.X").WithLocation(17, 12), - }; - - comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(expectedDiagnostics); + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S3").WithArguments("S3.X", "preview").WithLocation(17, 12)); - comp = CreateCompilation(source); - comp.VerifyDiagnostics(expectedDiagnostics); + comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (2,8): error CS8983: A 'struct' with field initializers must include an explicitly declared constructor. + // struct S1 + Diagnostic(ErrorCode.ERR_StructHasInitializersAndNoDeclaredConstructor, "S1").WithLocation(2, 8)); } [WorkItem(57870, "https://github.com/dotnet/roslyn/issues/57870")] @@ -1550,168 +1545,261 @@ record struct S4 } "; - var expectedDiagnostics = new[] - { + var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( // (2,15): error CS8983: A 'struct' with field initializers must include an explicitly declared constructor. // record struct S1 Diagnostic(ErrorCode.ERR_StructHasInitializersAndNoDeclaredConstructor, "S1").WithLocation(2, 15), - // (11,12): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. + // (11,12): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public S2() { } - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S2").WithArguments("S2.Y").WithLocation(11, 12), - // (17,12): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S2").WithArguments("S2.Y", "preview").WithLocation(11, 12), + // (17,12): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public S3() { Y = 3; } - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S3").WithArguments("S3.X").WithLocation(17, 12) - }; + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S3").WithArguments("S3.X", "preview").WithLocation(17, 12)); - var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(expectedDiagnostics); - - comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }); - comp.VerifyDiagnostics(expectedDiagnostics); + comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (2,15): error CS8983: A 'struct' with field initializers must include an explicitly declared constructor. + // record struct S1 + Diagnostic(ErrorCode.ERR_StructHasInitializersAndNoDeclaredConstructor, "S1").WithLocation(2, 15)); } [Fact] public void FieldInitializers_09() { - var source = -@"#pragma warning disable 649 + var source = @" +using System; + +#pragma warning disable 649 record struct S1() { - internal object X = 1; - internal object Y; + public object X = 1; + public object Y; } record struct S2() { - internal object X { get; } = 2; - internal object Y { get; } + public object X { get; } = 2; + public object Y { get; } } record struct S3() { - internal object X { get; init; } - internal object Y { get; init; } = 3; + public object X { get; init; } + public object Y { get; init; } = 3; +} + +class Program +{ + static void Main() + { + Console.WriteLine(new S1()); + Console.WriteLine(new S2()); + Console.WriteLine(new S3()); + } } "; - var expectedDiagnostics = new[] - { - // (2,15): error CS0171: Field 'S1.Y' must be fully assigned before control is returned to the caller + var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (5,15): error CS0171: Field 'S1.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // record struct S1() - Diagnostic(ErrorCode.ERR_UnassignedThis, "S1").WithArguments("S1.Y").WithLocation(2, 15), - // (7,15): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S1").WithArguments("S1.Y", "preview").WithLocation(5, 15), + // (10,15): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // record struct S2() - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S2").WithArguments("S2.Y").WithLocation(7, 15), - // (12,15): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S2").WithArguments("S2.Y", "preview").WithLocation(10, 15), + // (15,15): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // record struct S3() - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S3").WithArguments("S3.X").WithLocation(12, 15) - }; + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S3").WithArguments("S3.X", "preview").WithLocation(15, 15)); - var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(expectedDiagnostics); + var verifier = CompileAndVerify(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularNext, expectedOutput: +@" +S1 { X = 1, Y = } +S2 { X = 2, Y = } +S3 { X = , Y = 3 } +", verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("S1..ctor", @" +{ + // Code size 20 (0x14) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""object S1.Y"" + IL_0007: ldarg.0 + IL_0008: ldc.i4.1 + IL_0009: box ""int"" + IL_000e: stfld ""object S1.X"" + IL_0013: ret +}"); - comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }); - comp.VerifyDiagnostics(expectedDiagnostics); + verifier.VerifyIL("S2..ctor", @" +{ + // Code size 20 (0x14) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""object S2.k__BackingField"" + IL_0007: ldarg.0 + IL_0008: ldc.i4.2 + IL_0009: box ""int"" + IL_000e: stfld ""object S2.k__BackingField"" + IL_0013: ret +}"); + + verifier.VerifyIL("S3..ctor", @" +{ + // Code size 20 (0x14) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""object S3.k__BackingField"" + IL_0007: ldarg.0 + IL_0008: ldc.i4.3 + IL_0009: box ""int"" + IL_000e: stfld ""object S3.k__BackingField"" + IL_0013: ret +}"); } [Fact] public void FieldInitializers_10() { - var source = -@"#pragma warning disable 649 + var source = @" +using System; + +#pragma warning disable 649 record struct S1(object X) { - internal object X = 1; - internal object Y; + public object X = 1; + public object Y; } record struct S2(object X) { - internal object X { get; } = 2; - internal object Y { get; } + public object X { get; } = 2; + public object Y { get; } } record struct S3(object Y) { - internal object X { get; init; } - internal object Y { get; init; } = 3; + public object X { get; init; } + public object Y { get; init; } = 3; +} + +class Program +{ + static void Main() + { + Console.WriteLine(new S1(""a"")); + Console.WriteLine(new S2(""b"")); + Console.WriteLine(new S3(""c"")); + } } "; - var expectedDiagnostics = new[] - { - // (2,15): error CS0171: Field 'S1.Y' must be fully assigned before control is returned to the caller + var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (5,15): error CS0171: Field 'S1.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // record struct S1(object X) - Diagnostic(ErrorCode.ERR_UnassignedThis, "S1").WithArguments("S1.Y").WithLocation(2, 15), - // (2,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S1").WithArguments("S1.Y", "preview").WithLocation(5, 15), + // (5,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? // record struct S1(object X) - Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(2, 25), - // (7,15): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(5, 25), + // (10,15): error CS0843: Auto-implemented property 'S2.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // record struct S2(object X) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S2").WithArguments("S2.Y").WithLocation(7, 15), - // (7,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S2").WithArguments("S2.Y", "preview").WithLocation(10, 15), + // (10,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? // record struct S2(object X) - Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(7, 25), - // (12,15): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(10, 25), + // (15,15): error CS0843: Auto-implemented property 'S3.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // record struct S3(object Y) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S3").WithArguments("S3.X").WithLocation(12, 15), - // (12,25): warning CS8907: Parameter 'Y' is unread. Did you forget to use it to initialize the property with that name? + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S3").WithArguments("S3.X", "preview").WithLocation(15, 15), + // (15,25): warning CS8907: Parameter 'Y' is unread. Did you forget to use it to initialize the property with that name? // record struct S3(object Y) - Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "Y").WithArguments("Y").WithLocation(12, 25) - }; - - var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(expectedDiagnostics); - - comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }); - comp.VerifyDiagnostics(expectedDiagnostics); + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "Y").WithArguments("Y").WithLocation(15, 25)); + + var verifier = CompileAndVerify(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularNext, expectedOutput: +@"S1 { X = 1, Y = } +S2 { X = 2, Y = } +S3 { X = , Y = 3 } +", verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (5,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? + // record struct S1(object X) + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(5, 25), + // (10,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? + // record struct S2(object X) + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(10, 25), + // (15,25): warning CS8907: Parameter 'Y' is unread. Did you forget to use it to initialize the property with that name? + // record struct S3(object Y) + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "Y").WithArguments("Y").WithLocation(15, 25)); } [Fact] public void FieldInitializers_11() { - var source = -@"#pragma warning disable 649 + var source = @" +using System; + +#pragma warning disable 649 record struct S1(object X) { - internal object X; - internal object Y = 1; + public object X; + public object Y = 1; } record struct S2(object X) { - internal object X { get; } - internal object Y { get; } = 2; + public object X { get; } + public object Y { get; } = 2; } record struct S3(object Y) { - internal object X { get; init; } = 3; - internal object Y { get; init; } + public object X { get; init; } = 3; + public object Y { get; init; } } -"; - var expectedDiagnostics = new[] - { - // (2,15): error CS0171: Field 'S1.X' must be fully assigned before control is returned to the caller +class Program +{ + static void Main() + { + Console.WriteLine(new S1(""a"")); + Console.WriteLine(new S2(""b"")); + Console.WriteLine(new S3(""c"")); + } +} +"; + var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (5,15): error CS0171: Field 'S1.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // record struct S1(object X) - Diagnostic(ErrorCode.ERR_UnassignedThis, "S1").WithArguments("S1.X").WithLocation(2, 15), - // (2,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S1").WithArguments("S1.X", "preview").WithLocation(5, 15), + // (5,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? // record struct S1(object X) - Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(2, 25), - // (7,15): error CS0843: Auto-implemented property 'S2.X' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(5, 25), + // (10,15): error CS0843: Auto-implemented property 'S2.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // record struct S2(object X) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S2").WithArguments("S2.X").WithLocation(7, 15), - // (7,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S2").WithArguments("S2.X", "preview").WithLocation(10, 15), + // (10,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? // record struct S2(object X) - Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(7, 25), - // (12,15): error CS0843: Auto-implemented property 'S3.Y' must be fully assigned before control is returned to the caller. + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(10, 25), + // (15,15): error CS0843: Auto-implemented property 'S3.Y' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // record struct S3(object Y) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S3").WithArguments("S3.Y").WithLocation(12, 15), - // (12,25): warning CS8907: Parameter 'Y' is unread. Did you forget to use it to initialize the property with that name? + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S3").WithArguments("S3.Y", "preview").WithLocation(15, 15), + // (15,25): warning CS8907: Parameter 'Y' is unread. Did you forget to use it to initialize the property with that name? // record struct S3(object Y) - Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "Y").WithArguments("Y").WithLocation(12, 25) - }; - - var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(expectedDiagnostics); - - comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }); - comp.VerifyDiagnostics(expectedDiagnostics); + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "Y").WithArguments("Y").WithLocation(15, 25)); + + var verifier = CompileAndVerify(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularNext, expectedOutput: +@"S1 { X = , Y = 1 } +S2 { X = , Y = 2 } +S3 { X = 3, Y = }", verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (5,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? + // record struct S1(object X) + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(5, 25), + // (10,25): warning CS8907: Parameter 'X' is unread. Did you forget to use it to initialize the property with that name? + // record struct S2(object X) + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "X").WithArguments("X").WithLocation(10, 25), + // (15,25): warning CS8907: Parameter 'Y' is unread. Did you forget to use it to initialize the property with that name? + // record struct S3(object Y) + Diagnostic(ErrorCode.WRN_UnreadRecordParameter, "Y").WithArguments("Y").WithLocation(15, 25)); } [Fact] @@ -2027,20 +2115,35 @@ struct S3 public S3() { F3 = GetValue(); } static object? GetValue() => null; }"; - var comp = CreateCompilation(source); + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( // (10,12): warning CS8618: Non-nullable field 'F1' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. // public S1() { } Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S1").WithArguments("field", "F1").WithLocation(10, 12), - // (10,12): error CS0171: Field 'S1.F1' must be fully assigned before control is returned to the caller + // (10,12): error CS0171: Field 'S1.F1' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S1() { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S1").WithArguments("S1.F1").WithLocation(10, 12), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S1").WithArguments("S1.F1", "preview").WithLocation(10, 12), // (16,5): warning CS8618: Non-nullable field 'F2' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. // S2(object? obj) { } Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S2").WithArguments("field", "F2").WithLocation(16, 5), - // (16,5): error CS0171: Field 'S2.F2' must be fully assigned before control is returned to the caller + // (16,5): error CS0171: Field 'S2.F2' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // S2(object? obj) { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S2").WithArguments("S2.F2").WithLocation(16, 5), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S2").WithArguments("S2.F2", "preview").WithLocation(16, 5), + // (21,12): warning CS8618: Non-nullable field 'F3' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. + // public S3() { F3 = GetValue(); } + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S3").WithArguments("field", "F3").WithLocation(21, 12), + // (21,24): warning CS8601: Possible null reference assignment. + // public S3() { F3 = GetValue(); } + Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "GetValue()").WithLocation(21, 24)); + + comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (10,12): warning CS8618: Non-nullable field 'F1' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. + // public S1() { } + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S1").WithArguments("field", "F1").WithLocation(10, 12), + // (16,5): warning CS8618: Non-nullable field 'F2' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. + // S2(object? obj) { } + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S2").WithArguments("field", "F2").WithLocation(16, 5), // (21,12): warning CS8618: Non-nullable field 'F3' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. // public S3() { F3 = GetValue(); } Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S3").WithArguments("field", "F3").WithLocation(21, 12), @@ -2142,17 +2245,27 @@ unsafe struct S5 public S5() { X = 5; } }"; - var comp = CreateCompilation(source, options: TestOptions.UnsafeReleaseDll); + var comp = CreateCompilation(source, options: TestOptions.UnsafeReleaseDll, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (20,12): error CS0171: Field 'S3.X' must be fully assigned before control is returned to the caller + // (20,12): error CS0171: Field 'S3.X' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S3() { } - Diagnostic(ErrorCode.ERR_UnassignedThis, "S3").WithArguments("S3.X").WithLocation(20, 12), + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S3").WithArguments("S3.X", "preview").WithLocation(20, 12), // (22,15): error CS8983: A 'struct' with field initializers must include an explicitly declared constructor. // unsafe struct S4 Diagnostic(ErrorCode.ERR_StructHasInitializersAndNoDeclaredConstructor, "S4").WithLocation(22, 15), // (29,9): warning CS0414: The field 'S5.X' is assigned but its value is never used // int X; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "X").WithArguments("S5.X").WithLocation(29, 9)); + + comp = CreateCompilation(source, options: TestOptions.UnsafeReleaseDll, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (22,15): error CS8983: A 'struct' with field initializers must include an explicitly declared constructor. + // unsafe struct S4 + Diagnostic(ErrorCode.ERR_StructHasInitializersAndNoDeclaredConstructor, "S4").WithLocation(22, 15), + // (29,9): warning CS0414: The field 'S5.X' is assigned but its value is never used + // int X; + Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "X").WithArguments("S5.X").WithLocation(29, 9) + ); } [Fact] @@ -2408,5 +2521,287 @@ static void M(I i) // var s1 = i.F1(); Diagnostic(ErrorCode.ERR_InteropStructContainsMethods, "i.F1()").WithArguments("S1").WithLocation(6, 18)); } + + [Fact] + public void ImplicitlyInitializedField_Simple() + { + var source = @" +public struct S +{ + public int x; + public S() { } +}"; + CreateCompilation(source, parseOptions: TestOptions.Regular10) + .VerifyDiagnostics( + // (5,12): error CS0171: Field 'S.x' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. + // public S() { } + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.x", "preview").WithLocation(5, 12)); + + CreateCompilation(source, options: TestOptions.DebugDll.WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), parseOptions: TestOptions.RegularNext) + .VerifyDiagnostics( + // (5,12): warning CS9021: Control is returned to caller before field 'S.x' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // public S() { } + Diagnostic(ErrorCode.WRN_UnassignedThisSupportedVersion, "S").WithArguments("S.x").WithLocation(5, 12)); + + CreateCompilation(source, options: TestOptions.DebugDll.WithSpecificDiagnosticOptions(GetIdForErrorCode(ErrorCode.WRN_UnassignedThisSupportedVersion), ReportDiagnostic.Error), parseOptions: TestOptions.RegularNext) + .VerifyDiagnostics( + // (5,12): error CS9021: Control is returned to caller before field 'S.x' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // public S() { } + Diagnostic(ErrorCode.WRN_UnassignedThisSupportedVersion, "S").WithArguments("S.x").WithLocation(5, 12).WithWarningAsError(true)); + + var verifier = CompileAndVerify(source, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("S..ctor()", @" +{ + // Code size 8 (0x8) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int S.x"" + IL_0007: ret +} +"); + } + + [Fact] + public void ImplicitlyInitializedField_NotOtherStruct() + { + var source = @" +public struct S +{ + public int x; + public S() // 1 + { + S other; + other.x.ToString(); // 2 + + S other2; + other2.ToString(); // 3 + } +}"; + CreateCompilation(source, parseOptions: TestOptions.Regular10) + .VerifyDiagnostics( + // (5,12): error CS0171: Field 'S.x' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. + // public S() // 1 + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.x", "preview").WithLocation(5, 12), + // (8,9): error CS0170: Use of possibly unassigned field 'x' + // other.x.ToString(); // 2 + Diagnostic(ErrorCode.ERR_UseDefViolationField, "other.x").WithArguments("x").WithLocation(8, 9), + // (11,9): error CS0165: Use of unassigned local variable 'other2' + // other2.ToString(); // 3 + Diagnostic(ErrorCode.ERR_UseDefViolation, "other2").WithArguments("other2").WithLocation(11, 9)); + + CreateCompilation(source, options: TestOptions.DebugDll.WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), parseOptions: TestOptions.RegularNext) + .VerifyDiagnostics( + // (5,12): warning CS9021: Control is returned to caller before field 'S.x' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // public S() // 1 + Diagnostic(ErrorCode.WRN_UnassignedThisSupportedVersion, "S").WithArguments("S.x").WithLocation(5, 12), + // (8,9): error CS0170: Use of possibly unassigned field 'x' + // other.x.ToString(); // 2 + Diagnostic(ErrorCode.ERR_UseDefViolationField, "other.x").WithArguments("x").WithLocation(8, 9), + // (11,9): error CS0165: Use of unassigned local variable 'other2' + // other2.ToString(); // 3 + Diagnostic(ErrorCode.ERR_UseDefViolation, "other2").WithArguments("other2").WithLocation(11, 9)); + } + + [Fact] + public void ImplicitlyInitializedField_ExplicitReturn() + { + var source = @" +public struct S +{ + public int x; + public S() + { + return; + } +}"; + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (7,9): error CS0171: Field 'S.x' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. + // return; + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "return;").WithArguments("S.x", "preview").WithLocation(7, 9)); + + var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics( + // (7,9): warning CS9021: Control is returned to caller before field 'S.x' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // return; + Diagnostic(ErrorCode.WRN_UnassignedThisSupportedVersion, "return;").WithArguments("S.x").WithLocation(7, 9)); + + verifier.VerifyIL("S..ctor", @" +{ + // Code size 11 (0xb) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stfld ""int S.x"" + IL_0007: nop + IL_0008: br.s IL_000a + IL_000a: ret +} +"); + } + + [Fact] + public void ImplicitlyInitializedField_FieldLikeEvent() + { + var source = @" +using System; + +public struct S +{ + public event Action E; + public S() + { + E?.Invoke(); + } +}"; + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (7,12): error CS0171: Field 'S.E' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. + // public S() + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.E", "preview").WithLocation(7, 12), + // (9,9): error CS9014: Use of possibly unassigned field 'E'. Consider updating to language version 'preview' to auto-default the field. + // E?.Invoke(); + Diagnostic(ErrorCode.ERR_UseDefViolationFieldUnsupportedVersion, "E").WithArguments("E", "preview").WithLocation(9, 9)); + + var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics( + // (7,12): warning CS9021: Control is returned to caller before field 'S.E' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // public S() + Diagnostic(ErrorCode.WRN_UnassignedThisSupportedVersion, "S").WithArguments("S.E").WithLocation(7, 12), + // (9,9): warning CS9018: Field 'E' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. + // E?.Invoke(); + Diagnostic(ErrorCode.WRN_UseDefViolationFieldSupportedVersion, "E").WithArguments("E").WithLocation(9, 9)); + + verifier.VerifyIL("S..ctor", @" +{ + // Code size 27 (0x1b) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""System.Action S.E"" + IL_0007: nop + IL_0008: ldarg.0 + IL_0009: ldfld ""System.Action S.E"" + IL_000e: dup + IL_000f: brtrue.s IL_0014 + IL_0011: pop + IL_0012: br.s IL_001a + IL_0014: callvirt ""void System.Action.Invoke()"" + IL_0019: nop + IL_001a: ret +} +"); + } + + [Fact] + public void NonNullableReferenceTypeField() + { + var source = +@"public struct S +{ + public string Item; + public S(bool unused) + { + } +}"; + var comp = CreateCompilation(new[] { source }, options: WithNullableEnable(), parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (4,12): warning CS8618: Non-nullable field 'Item' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. + // public S(bool unused) + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S").WithArguments("field", "Item").WithLocation(4, 12), + // (4,12): error CS0171: Field 'S.Item' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. + // public S(bool unused) + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.Item", "preview").WithLocation(4, 12) + ); + + var verifier = CompileAndVerify(new[] { source }, options: WithNullableEnable(), parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics( + // (4,12): warning CS8618: Non-nullable field 'Item' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. + // public S(bool unused) + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S").WithArguments("field", "Item").WithLocation(4, 12)); + verifier.VerifyIL("S..ctor", @" +{ + // Code size 8 (0x8) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""string S.Item"" + IL_0007: ret +} +"); + } + + [Theory] + [InlineData(LanguageVersion.CSharp10)] + [InlineData(LanguageVersionFacts.CSharpNext)] + public void Struct_ExplicitThisConstructorInitializer_01(LanguageVersion languageVersion) + { + var source = +@"public struct S +{ + public string Item; + public S(bool unused) : this() + { + } +}"; + var verifier = CompileAndVerify(new[] { source }, options: WithNullableEnable(), parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion)); + verifier.VerifyDiagnostics( + // (4,12): warning CS8618: Non-nullable field 'Item' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. + // public S(bool unused) + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S").WithArguments("field", "Item").WithLocation(4, 12) + ); + + verifier.VerifyIL("S..ctor", @" +{ + // Code size 8 (0x8) + .maxstack 1 + IL_0000: ldarg.0 + IL_0001: initobj ""S"" + IL_0007: ret +} +"); + } + + [Theory] + [InlineData(LanguageVersion.CSharp10)] + [InlineData(LanguageVersionFacts.CSharpNext)] + public void Struct_ExplicitThisConstructorInitializer_02(LanguageVersion languageVersion) + { + var source = +@"public struct S +{ + public string Item; + public S(bool unused) : this() + { + } + public S() { Item = ""a""; } +}"; + var verifier = CompileAndVerify(new[] { source }, options: WithNullableEnable(), parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion)); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("S..ctor(bool)", @" +{ + // Code size 7 (0x7) + .maxstack 1 + IL_0000: ldarg.0 + IL_0001: call ""S..ctor()"" + IL_0006: ret +} +"); + + verifier.VerifyIL("S..ctor()", @" +{ + // Code size 12 (0xc) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldstr ""a"" + IL_0006: stfld ""string S.Item"" + IL_000b: ret +} +"); + } } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/UninitializedNonNullableFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/UninitializedNonNullableFieldTests.cs index de70e1f4ea21f..6d5516d56cb9e 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/UninitializedNonNullableFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/UninitializedNonNullableFieldTests.cs @@ -853,23 +853,75 @@ public S1(string s1, string s2) : this(s1) } "; - var comp = CreateCompilation(source, options: WithNullableEnable()); + var comp = CreateCompilation(source, options: WithNullableEnable(), parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( - // (5,12): error CS0843: Auto-implemented property 'S1.Prop' must be fully assigned before control is returned to the caller. + // (5,12): error CS0843: Auto-implemented property 'S1.Prop' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public S1(string s) // 1 - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S1").WithArguments("S1.Prop").WithLocation(5, 12), + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S1").WithArguments("S1.Prop", "preview").WithLocation(5, 12), // (7,9): warning CS8602: Dereference of a possibly null reference. // Prop.ToString(); // 2 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "Prop").WithLocation(7, 9), - // (7,9): error CS8079: Use of possibly unassigned auto-implemented property 'Prop' + // (7,9): error CS9013: Use of possibly unassigned auto-implemented property 'Prop'. Consider updating to language version 'preview' to auto-default the property. + // Prop.ToString(); // 2 + Diagnostic(ErrorCode.ERR_UseDefViolationPropertyUnsupportedVersion, "Prop").WithArguments("Prop", "preview").WithLocation(7, 9), + // (12,9): warning CS8602: Dereference of a possibly null reference. + // Prop.ToString(); // 3 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "Prop").WithLocation(12, 9), + // (15,12): warning CS8618: Non-nullable property 'Prop' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. + // public S1(object obj1, object obj2) : this() // 4 + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S1").WithArguments("property", "Prop").WithLocation(15, 12)); + + var verifier = CompileAndVerify(source, options: WithNullableEnable(), parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics( + // (7,9): warning CS8602: Dereference of a possibly null reference. // Prop.ToString(); // 2 - Diagnostic(ErrorCode.ERR_UseDefViolationProperty, "Prop").WithArguments("Prop").WithLocation(7, 9), + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "Prop").WithLocation(7, 9), // (12,9): warning CS8602: Dereference of a possibly null reference. // Prop.ToString(); // 3 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "Prop").WithLocation(12, 9), // (15,12): warning CS8618: Non-nullable property 'Prop' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. // public S1(object obj1, object obj2) : this() // 4 Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S1").WithArguments("property", "Prop").WithLocation(15, 12)); + + verifier.VerifyIL("S1..ctor(string)", @" +{ + // Code size 20 (0x14) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""string S1.k__BackingField"" + IL_0007: ldarg.0 + IL_0008: call ""readonly string S1.Prop.get"" + IL_000d: callvirt ""string object.ToString()"" + IL_0012: pop + IL_0013: ret +} +"); + + verifier.VerifyIL("S1..ctor(object, object)", @" +{ + // Code size 8 (0x8) + .maxstack 1 + IL_0000: ldarg.0 + IL_0001: initobj ""S1"" + IL_0007: ret +} +"); + + verifier.VerifyIL("S1..ctor(string, string)", @" +{ + // Code size 20 (0x14) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call ""S1..ctor(string)"" + IL_0007: ldarg.0 + IL_0008: call ""readonly string S1.Prop.get"" + IL_000d: callvirt ""string object.ToString()"" + IL_0012: pop + IL_0013: ret +} +"); } [Fact, WorkItem(48574, "https://github.com/dotnet/roslyn/issues/48574")] @@ -907,6 +959,34 @@ public S1(string s1, string s2) : this(s1) Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S1").WithArguments("field", "field").WithLocation(13, 12)); } + [Fact, WorkItem(48574, "https://github.com/dotnet/roslyn/issues/48574")] + public void StructConstructorInitializer_NestedUninitializedField() + { + var source = @" +#nullable enable +public struct S1 +{ + public object F1; + public S2 S2; + + public S1() + { + F1.ToString(); // 1 + S2.F2.ToString(); // missing warning: https://github.com/dotnet/roslyn/issues/60038 + } +} +public struct S2 +{ + public object F2; +} +"; + var comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + comp.VerifyDiagnostics( + // (10,9): warning CS8602: Dereference of a possibly null reference. + // F1.ToString(); // 1 + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F1").WithLocation(10, 9)); + } + [Fact, WorkItem(48574, "https://github.com/dotnet/roslyn/issues/48574")] public void StructConstructorInitializer_InitializedFieldViaParameterlessConstructor() { @@ -969,18 +1049,50 @@ public S1(string s) // 1, 2 } } "; - var comp = CreateCompilation(source); + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); comp.VerifyDiagnostics( // (13,12): warning CS8618: Non-nullable field 'field' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. // public S1(string s) // 1, 2 Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S1").WithArguments("field", "field").WithLocation(13, 12), - // (13,12): error CS0171: Field 'S1.field' must be fully assigned before control is returned to the caller + // (13,12): error CS0171: Field 'S1.field' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public S1(string s) // 1, 2 - Diagnostic(ErrorCode.ERR_UnassignedThis, "S1").WithArguments("S1.field").WithLocation(13, 12), - // (15,30): error CS0170: Use of possibly unassigned field 'field' + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S1").WithArguments("S1.field", "preview").WithLocation(13, 12), + // (15,30): error CS9014: Use of possibly unassigned field 'field'. Consider updating to language version 'preview' to auto-default the field. // System.Console.Write(field); // 3 - Diagnostic(ErrorCode.ERR_UseDefViolationField, "field").WithArguments("field").WithLocation(15, 30) + Diagnostic(ErrorCode.ERR_UseDefViolationFieldUnsupportedVersion, "field").WithArguments("field", "preview").WithLocation(15, 30) ); + + var verifier = CompileAndVerify(source, parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics( + // (13,12): warning CS8618: Non-nullable field 'field' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. + // public S1(string s) // 1, 2 + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S1").WithArguments("field", "field").WithLocation(13, 12) + ); + + verifier.VerifyIL("S1..ctor()", @" +{ + // Code size 12 (0xc) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldstr ""ok "" + IL_0006: stfld ""string S1.field"" + IL_000b: ret +} +"); + + verifier.VerifyIL("S1..ctor(string)", @" +{ + // Code size 19 (0x13) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""string S1.field"" + IL_0007: ldarg.0 + IL_0008: ldfld ""string S1.field"" + IL_000d: call ""void System.Console.Write(string)"" + IL_0012: ret +} +"); } [Fact, WorkItem(48574, "https://github.com/dotnet/roslyn/issues/48574")] @@ -1675,12 +1787,50 @@ internal S(string s) // (6,14): warning CS8618: Non-nullable field 'F' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. // internal S(string s) Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S").WithArguments("field", "F").WithLocation(6, 14), - // (6,14): error CS0843: Auto-implemented property 'S.P' must be fully assigned before control is returned to the caller. + // (6,14): error CS0843: Auto-implemented property 'S.P' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // internal S(string s) - Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S").WithArguments("S.P").WithLocation(6, 14), - // (6,14): error CS0171: Field 'S.F' must be fully assigned before control is returned to the caller + Diagnostic(ErrorCode.ERR_UnassignedThisAutoPropertyUnsupportedVersion, "S").WithArguments("S.P", "preview").WithLocation(6, 14), + // (6,14): error CS0171: Field 'S.F' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // internal S(string s) - Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("S.F").WithLocation(6, 14)); + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.F", "preview").WithLocation(6, 14)); + + var verifier = CompileAndVerify(new[] { source }, options: WithNullableEnable(), parseOptions: TestOptions.RegularNext); + verifier.VerifyDiagnostics( + // (6,14): warning CS8618: Non-nullable property 'P' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. + // internal S(string s) + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S").WithArguments("property", "P").WithLocation(6, 14), + // (6,14): warning CS8618: Non-nullable field 'F' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. + // internal S(string s) + Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S").WithArguments("field", "F").WithLocation(6, 14)); + verifier.VerifyIL("S..ctor", @" +{ + // Code size 48 (0x30) + .maxstack 5 + IL_0000: ldarg.0 + IL_0001: ldnull + IL_0002: stfld ""string S.F"" + IL_0007: ldarg.0 + IL_0008: ldnull + IL_0009: stfld ""string[] S.

k__BackingField"" + IL_000e: ldarg.1 + IL_000f: callvirt ""int string.Length.get"" + IL_0014: ldc.i4.0 + IL_0015: ble.s IL_001f + IL_0017: ldarg.0 + IL_0018: ldarg.1 + IL_0019: stfld ""string S.F"" + IL_001e: ret + IL_001f: ldarg.0 + IL_0020: ldc.i4.1 + IL_0021: newarr ""string"" + IL_0026: dup + IL_0027: ldc.i4.0 + IL_0028: ldarg.1 + IL_0029: stelem.ref + IL_002a: call ""void S.P.set"" + IL_002f: ret +} +"); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/WarningVersionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/WarningVersionTests.cs index 9a0a81a379c1b..cc9d27ebaf279 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/WarningVersionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/WarningVersionTests.cs @@ -129,7 +129,7 @@ public struct Struct } "; var comp1 = CreateCompilation(source, options: TestOptions.DebugModule); - var moduleReference = comp1.EmitToImageReference(); + var moduleReference = new[] { comp1.EmitToImageReference() }; var source2 = @"public struct Program @@ -139,13 +139,62 @@ public Program(int dummy) { } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( - ); - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( - // (4,12): warning CS8822: Auto-implemented property 'Program.Property' must be fully assigned before control is returned to the caller. + var expectedIL = @" +{ + // Code size 14 (0xe) + .maxstack 1 + IL_0000: ldarg.0 + IL_0001: ldflda ""Struct Program.k__BackingField"" + IL_0006: initobj ""Struct"" + IL_000c: nop + IL_000d: ret +} +"; + // C# 10 + var verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (4,12): warning CS8880: Auto-implemented property 'Program.Property' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the property. // public Program(int dummy) - Diagnostic(ErrorCode.WRN_UnassignedThisAutoProperty, "Program").WithArguments("Program.Property").WithLocation(4, 12) - ); + Diagnostic(ErrorCode.WRN_UnassignedThisAutoPropertyUnsupportedVersion, "Program").WithArguments("Program.Property", "preview").WithLocation(4, 12)); + verifier.VerifyIL("Program..ctor", expectedIL); + + // C# 11+ + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll + .WithWarningLevel(5) + .WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (4,12): warning CS9020: Control is returned to caller before auto-implemented property 'Program.Property' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // public Program(int dummy) + Diagnostic(ErrorCode.WRN_UnassignedThisAutoPropertySupportedVersion, "Program").WithArguments("Program.Property").WithLocation(4, 12)); + verifier.VerifyIL("Program..ctor", expectedIL); } [Fact] @@ -158,7 +207,7 @@ public struct Struct } "; var comp1 = CreateCompilation(source, options: TestOptions.DebugModule); - var moduleReference = comp1.EmitToImageReference(); + var moduleReference = new[] { comp1.EmitToImageReference() }; var source2 = @"public struct Program @@ -168,13 +217,157 @@ public Program(int dummy) { } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( - ); - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( - // (4,12): warning CS8823: Field 'Program.Field' must be fully assigned before control is returned to the caller + var expectedIL = @" +{ + // Code size 14 (0xe) + .maxstack 1 + IL_0000: ldarg.0 + IL_0001: ldflda ""Struct Program.Field"" + IL_0006: initobj ""Struct"" + IL_000c: nop + IL_000d: ret +} +"; + // C# 10 + var verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (4,12): warning CS8881: Field 'Program.Field' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // public Program(int dummy) - Diagnostic(ErrorCode.WRN_UnassignedThis, "Program").WithArguments("Program.Field").WithLocation(4, 12) - ); + Diagnostic(ErrorCode.WRN_UnassignedThisUnsupportedVersion, "Program").WithArguments("Program.Field", "preview").WithLocation(4, 12)); + verifier.VerifyIL("Program..ctor", expectedIL); + + // C# 11+ + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll + .WithWarningLevel(5), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll + .WithWarningLevel(5) + .WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (4,12): warning CS9021: Control is returned to caller before field 'Program.Field' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // public Program(int dummy) + Diagnostic(ErrorCode.WRN_UnassignedThisSupportedVersion, "Program").WithArguments("Program.Field").WithLocation(4, 12)); + verifier.VerifyIL("Program..ctor", expectedIL); + } + + [Fact] + public void UnassignedThisField_And_UnassignedLocal() + { + var source = @" +public struct Struct +{ + private string data; +} +"; + var comp1 = CreateCompilation(source, options: TestOptions.DebugModule); + var moduleReference = new[] { comp1.EmitToImageReference() }; + + var source2 = +@"public struct Program +{ + public Struct Field; + public Program(int dummy) + { + Struct s; + s.ToString(); + } +}"; + var expectedIL = @" +{ + // Code size 28 (0x1c) + .maxstack 1 + .locals init (Struct V_0) //s + IL_0000: ldarg.0 + IL_0001: ldflda ""Struct Program.Field"" + IL_0006: initobj ""Struct"" + IL_000c: nop + IL_000d: ldloca.s V_0 + IL_000f: constrained. ""Struct"" + IL_0015: callvirt ""string object.ToString()"" + IL_001a: pop + IL_001b: ret +} +"; + // C# 10 + var verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (4,12): warning CS8881: Field 'Program.Field' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. + // public Program(int dummy) + Diagnostic(ErrorCode.WRN_UnassignedThisUnsupportedVersion, "Program").WithArguments("Program.Field", "preview").WithLocation(4, 12), + // (7,9): warning CS8887: Use of unassigned local variable 's' + // s.ToString(); + Diagnostic(ErrorCode.WRN_UseDefViolation, "s").WithArguments("s").WithLocation(7, 9)); + verifier.VerifyIL("Program..ctor", expectedIL); + + // C# 11+ + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (7,9): warning CS8887: Use of unassigned local variable 's' + // s.ToString(); + Diagnostic(ErrorCode.WRN_UseDefViolation, "s").WithArguments("s").WithLocation(7, 9)); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll + .WithWarningLevel(5) + .WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (4,12): warning CS9021: Control is returned to caller before field 'Program.Field' is explicitly assigned, causing a preceding implicit assignment of 'default'. + // public Program(int dummy) + Diagnostic(ErrorCode.WRN_UnassignedThisSupportedVersion, "Program").WithArguments("Program.Field").WithLocation(4, 12), + // (7,9): warning CS8887: Use of unassigned local variable 's' + // s.ToString(); + Diagnostic(ErrorCode.WRN_UseDefViolation, "s").WithArguments("s").WithLocation(7, 9)); + verifier.VerifyIL("Program..ctor", expectedIL); } [Fact] @@ -215,7 +408,7 @@ public struct Struct } "; var comp1 = CreateCompilation(source, options: TestOptions.DebugModule); - var moduleReference = comp1.EmitToImageReference(); + var moduleReference = new[] { comp1.EmitToImageReference() }; var source2 = @"public struct Program @@ -227,13 +420,69 @@ public struct Struct Property = default; } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( - ); - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( - // (6,21): warning CS8825: Use of possibly unassigned auto-implemented property 'Property' + var expectedIL = @" +{ + // Code size 33 (0x21) + .maxstack 1 + .locals init (Struct V_0) //v2 + IL_0000: ldarg.0 + IL_0001: ldflda ""Struct Program.k__BackingField"" + IL_0006: initobj ""Struct"" + IL_000c: nop + IL_000d: ldarg.0 + IL_000e: call ""readonly Struct Program.Property.get"" + IL_0013: stloc.0 + IL_0014: ldarg.0 + IL_0015: ldflda ""Struct Program.k__BackingField"" + IL_001a: initobj ""Struct"" + IL_0020: ret +} +"; + // C# 10 + var verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (6,21): warning CS9015: Use of possibly unassigned auto-implemented property 'Property'. Consider updating to language version 'preview' to auto-default the property. // Struct v2 = Property; - Diagnostic(ErrorCode.WRN_UseDefViolationProperty, "Property").WithArguments("Property").WithLocation(6, 21) - ); + Diagnostic(ErrorCode.WRN_UseDefViolationPropertyUnsupportedVersion, "Property").WithArguments("Property", "preview").WithLocation(6, 21)); + verifier.VerifyIL("Program..ctor", expectedIL); + + // C# 11+ + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll + .WithWarningLevel(5) + .WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (6,21): warning CS9014: Use of possibly unassigned auto-implemented property 'Property' + // Struct v2 = Property; + Diagnostic(ErrorCode.WRN_UseDefViolationPropertySupportedVersion, "Property").WithArguments("Property").WithLocation(6, 21)); + verifier.VerifyIL("Program..ctor", expectedIL); } [Fact] @@ -246,7 +495,7 @@ public struct Struct } "; var comp1 = CreateCompilation(source, options: TestOptions.DebugModule); - var moduleReference = comp1.EmitToImageReference(); + var moduleReference = new[] { comp1.EmitToImageReference() }; var source2 = @"public struct Program @@ -258,13 +507,69 @@ public struct Struct Field = default; } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( - ); - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( - // (6,21): warning CS8826: Use of possibly unassigned field 'Field' + var expectedIL = @" +{ + // Code size 33 (0x21) + .maxstack 1 + .locals init (Struct V_0) //v2 + IL_0000: ldarg.0 + IL_0001: ldflda ""Struct Program.Field"" + IL_0006: initobj ""Struct"" + IL_000c: nop + IL_000d: ldarg.0 + IL_000e: ldfld ""Struct Program.Field"" + IL_0013: stloc.0 + IL_0014: ldarg.0 + IL_0015: ldflda ""Struct Program.Field"" + IL_001a: initobj ""Struct"" + IL_0020: ret +} +"; + // C# 10 + var verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (6,21): warning CS9016: Use of possibly unassigned field 'Field'. Consider updating to language version 'preview' to auto-default the field. // Struct v2 = Field; - Diagnostic(ErrorCode.WRN_UseDefViolationField, "Field").WithArguments("Field").WithLocation(6, 21) - ); + Diagnostic(ErrorCode.WRN_UseDefViolationFieldUnsupportedVersion, "Field").WithArguments("Field", "preview").WithLocation(6, 21)); + verifier.VerifyIL("Program..ctor", expectedIL); + + // C# 11+ + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("Program..ctor", expectedIL); + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll + .WithWarningLevel(5) + .WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (6,21): warning CS9014: Use of possibly unassigned field 'Field' + // Struct v2 = Field; + Diagnostic(ErrorCode.WRN_UseDefViolationFieldSupportedVersion, "Field").WithArguments("Field").WithLocation(6, 21)); + verifier.VerifyIL("Program..ctor", expectedIL); } [Fact] @@ -277,7 +582,7 @@ public struct Struct } "; var comp1 = CreateCompilation(source, options: TestOptions.DebugModule); - var moduleReference = comp1.EmitToImageReference(); + var moduleReference = new[] { comp1.EmitToImageReference() }; var source2 = @"public struct Program @@ -289,13 +594,69 @@ public struct Struct this.Field = default; } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( - ); - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( - // (6,22): warning CS8827: The 'this' object cannot be used before all of its fields have been assigned + var expectedIL = @" +{ + // Code size 33 (0x21) + .maxstack 1 + .locals init (Program V_0) //p2 + IL_0000: ldarg.0 + IL_0001: ldflda ""Struct Program.Field"" + IL_0006: initobj ""Struct"" + IL_000c: nop + IL_000d: ldarg.0 + IL_000e: ldobj ""Program"" + IL_0013: stloc.0 + IL_0014: ldarg.0 + IL_0015: ldflda ""Struct Program.Field"" + IL_001a: initobj ""Struct"" + IL_0020: ret +} +"; + // C# 10 + var verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.Regular10, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (6,22): warning CS8885: The 'this' object cannot be used before all of its fields have been assigned. Consider updating to language version 'this' to auto-default the unassigned fields. // Program p2 = this; - Diagnostic(ErrorCode.WRN_UseDefViolationThis, "this").WithArguments("this").WithLocation(6, 22) - ); + Diagnostic(ErrorCode.WRN_UseDefViolationThisUnsupportedVersion, "this").WithArguments("this", "preview").WithLocation(6, 22)); + verifier.VerifyIL("Program..ctor", expectedIL); + + // C# 11+ + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll.WithWarningLevel(5), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program..ctor", expectedIL); + + verifier = CompileAndVerify( + source2, + references: moduleReference, + options: TestOptions.DebugDll + .WithWarningLevel(5) + .WithSpecificDiagnosticOptions(ReportStructInitializationWarnings), + parseOptions: TestOptions.RegularNext, + verify: Verification.Skipped); + verifier.VerifyDiagnostics( + // (6,22): warning CS9019: The 'this' object cannot be used before all of its fields have been assigned, causing preceding implicit assignments of 'default' to non-explicitly assigned fields. + // Program p2 = this; + Diagnostic(ErrorCode.WRN_UseDefViolationThisSupportedVersion, "this").WithArguments("this").WithLocation(6, 22)); + verifier.VerifyIL("Program..ctor", expectedIL); } [Fact] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/EventTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/EventTests.cs index 4c6b66371c085..d7fdef0e1feef 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/EventTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/EventTests.cs @@ -1333,7 +1333,7 @@ event System.Action F { add { } remove { } } S(int unused1, int unused2) { - // CS0171: E not initialized + // CS0171: E not initialized before C# 11 // No error for F } @@ -1346,13 +1346,18 @@ void Method(S s) } } "; - CreateCompilation(text).VerifyDiagnostics( - // (11,5): error CS0171: Field 'S.E' must be fully assigned before control is returned to the caller + CreateCompilation(text, parseOptions: TestOptions.Regular10).VerifyDiagnostics( + // (11,5): error CS0171: Field 'S.E' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. // S(int unused1, int unused2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("S.E"), - // (21,9): error CS1612: Cannot modify the return value of 'S.This' because it is not a variable + Diagnostic(ErrorCode.ERR_UnassignedThisUnsupportedVersion, "S").WithArguments("S.E", "preview").WithLocation(11, 5), + // (22,9): error CS1612: Cannot modify the return value of 'S.This' because it is not a variable + // This.E = null; //CS1612: receiver is not a variable + Diagnostic(ErrorCode.ERR_ReturnNotLValue, "This").WithArguments("S.This").WithLocation(22, 9)); + + CreateCompilation(text, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( + // (22,9): error CS1612: Cannot modify the return value of 'S.This' because it is not a variable // This.E = null; //CS1612: receiver is not a variable - Diagnostic(ErrorCode.ERR_ReturnNotLValue, "This").WithArguments("S.This")); + Diagnostic(ErrorCode.ERR_ReturnNotLValue, "This").WithArguments("S.This").WithLocation(22, 9)); } [WorkItem(546356, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546356")] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/NullablePublicAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/NullablePublicAPITests.cs index fe4dd2aabd837..43002d02ece83 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/NullablePublicAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/NullablePublicAPITests.cs @@ -4971,15 +4971,6 @@ public ValueTuple(T1 item1, T2 item2) // (7,39): error CS8128: Member 'Item1' was not found on type '(T1, T2)' from assembly 'comp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. // System.Console.WriteLine($"{x.a}"); Diagnostic(ErrorCode.ERR_PredefinedTypeMemberNotFoundInAssembly, "a").WithArguments("Item1", "(T1, T2)", "comp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(7, 39), - // (17,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(17, 16), - // (17,16): error CS0171: Field '(T1, T2).Item1' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item1").WithLocation(17, 16), - // (17,16): error CS0171: Field '(T1, T2).Item2' must be fully assigned before control is returned to the caller - // public ValueTuple(T1 item1, T2 item2) - Diagnostic(ErrorCode.ERR_UnassignedThis, "ValueTuple").WithArguments("(T1, T2).Item2").WithLocation(17, 16), // (19,18): error CS0229: Ambiguity between '(T1, T2).Item2' and '(T1, T2).Item2' // this.Item2 = 2; Diagnostic(ErrorCode.ERR_AmbigMember, "Item2").WithArguments("(T1, T2).Item2", "(T1, T2).Item2").WithLocation(19, 18) diff --git a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs index ffc6e4ad098c9..fa8c75eb718a3 100644 --- a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs +++ b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs @@ -349,6 +349,11 @@ public void WarningLevel_2() case ErrorCode.WRN_InterpolatedStringHandlerArgumentAttributeIgnoredOnLambdaParameters: case ErrorCode.WRN_CompileTimeCheckedOverflow: case ErrorCode.WRN_MethGrpToNonDel: + case ErrorCode.WRN_UnassignedThisAutoPropertySupportedVersion: + case ErrorCode.WRN_UnassignedThisSupportedVersion: + case ErrorCode.WRN_UseDefViolationPropertySupportedVersion: + case ErrorCode.WRN_UseDefViolationFieldSupportedVersion: + case ErrorCode.WRN_UseDefViolationThisSupportedVersion: Assert.Equal(1, ErrorFacts.GetWarningLevel(errorCode)); break; case ErrorCode.WRN_InvalidVersionFormat: @@ -357,12 +362,14 @@ public void WarningLevel_2() case ErrorCode.WRN_NubExprIsConstBool2: case ErrorCode.WRN_StaticInAsOrIs: case ErrorCode.WRN_PrecedenceInversion: - case ErrorCode.WRN_UnassignedThisAutoProperty: - case ErrorCode.WRN_UnassignedThis: + case ErrorCode.WRN_UnassignedThisAutoPropertyUnsupportedVersion: + case ErrorCode.WRN_UnassignedThisUnsupportedVersion: case ErrorCode.WRN_ParamUnassigned: case ErrorCode.WRN_UseDefViolationProperty: case ErrorCode.WRN_UseDefViolationField: - case ErrorCode.WRN_UseDefViolationThis: + case ErrorCode.WRN_UseDefViolationPropertyUnsupportedVersion: + case ErrorCode.WRN_UseDefViolationFieldUnsupportedVersion: + case ErrorCode.WRN_UseDefViolationThisUnsupportedVersion: case ErrorCode.WRN_UseDefViolationOut: case ErrorCode.WRN_UseDefViolation: case ErrorCode.WRN_SyncAndAsyncEntryPoints: @@ -425,12 +432,12 @@ public void NullableWarnings() ErrorCode.WRN_ConstOutOfRangeChecked, ErrorCode.WRN_SwitchExpressionNotExhaustiveWithWhen, ErrorCode.WRN_PrecedenceInversion, - ErrorCode.WRN_UnassignedThisAutoProperty, - ErrorCode.WRN_UnassignedThis, + ErrorCode.WRN_UnassignedThisAutoPropertyUnsupportedVersion, + ErrorCode.WRN_UnassignedThisUnsupportedVersion, ErrorCode.WRN_ParamUnassigned, ErrorCode.WRN_UseDefViolationProperty, ErrorCode.WRN_UseDefViolationField, - ErrorCode.WRN_UseDefViolationThis, + ErrorCode.WRN_UseDefViolationThisUnsupportedVersion, ErrorCode.WRN_UseDefViolationOut, ErrorCode.WRN_UseDefViolation, ErrorCode.WRN_SyncAndAsyncEntryPoints, @@ -2756,6 +2763,11 @@ public override string GetErrorDisplayString(ISymbol symbol) { return MessageProvider.Instance.GetErrorDisplayString(symbol); } + + public override bool GetIsEnabledByDefault(int code) + { + return true; + } } #endregion diff --git a/src/Compilers/Core/Portable/Diagnostic/CommonMessageProvider.cs b/src/Compilers/Core/Portable/Diagnostic/CommonMessageProvider.cs index 732780f5d5c7e..8a49a6741599d 100644 --- a/src/Compilers/Core/Portable/Diagnostic/CommonMessageProvider.cs +++ b/src/Compilers/Core/Portable/Diagnostic/CommonMessageProvider.cs @@ -103,6 +103,8 @@ public Diagnostic CreateDiagnostic(int code, Location location) /// public abstract string GetErrorDisplayString(ISymbol symbol); + public abstract bool GetIsEnabledByDefault(int code); + ///

/// Given an error code (like 1234) return the identifier (CS1234 or BC1234). /// diff --git a/src/Compilers/Core/Portable/Diagnostic/DiagnosticInfo.cs b/src/Compilers/Core/Portable/Diagnostic/DiagnosticInfo.cs index 0f271f2372989..433e23d507e5b 100644 --- a/src/Compilers/Core/Portable/Diagnostic/DiagnosticInfo.cs +++ b/src/Compilers/Core/Portable/Diagnostic/DiagnosticInfo.cs @@ -91,7 +91,7 @@ private static DiagnosticDescriptor CreateDescriptor(int errorCode, DiagnosticSe var category = messageProvider.GetCategory(errorCode); var customTags = GetCustomTags(defaultSeverity); return new DiagnosticDescriptor(id, title, messageFormat, category, defaultSeverity, - isEnabledByDefault: true, description: description, helpLinkUri: helpLink, customTags: customTags); + isEnabledByDefault: messageProvider.GetIsEnabledByDefault(errorCode), description: description, helpLinkUri: helpLink, customTags: customTags); } [Conditional("DEBUG")] diff --git a/src/Compilers/Core/Portable/Diagnostic/DiagnosticWithInfo.cs b/src/Compilers/Core/Portable/Diagnostic/DiagnosticWithInfo.cs index f7de304d402de..9c9a13b31efe8 100644 --- a/src/Compilers/Core/Portable/Diagnostic/DiagnosticWithInfo.cs +++ b/src/Compilers/Core/Portable/Diagnostic/DiagnosticWithInfo.cs @@ -84,8 +84,7 @@ public sealed override DiagnosticSeverity DefaultSeverity internal sealed override bool IsEnabledByDefault { - // All compiler errors and warnings are enabled by default. - get { return true; } + get { return this.Info.Descriptor.IsEnabledByDefault; } } public override bool IsSuppressed diff --git a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs index f0d111f21babb..98db689e6d490 100644 --- a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs +++ b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs @@ -2411,6 +2411,22 @@ protected static CSharpCompilation CreateCompilationWithSpanAndMemoryExtensions( parseOptions: parseOptions); } } + + internal static string GetIdForErrorCode(ErrorCode code) + { + return MessageProvider.Instance.GetIdForErrorCode((int)code); + } + + internal static ImmutableDictionary ReportStructInitializationWarnings { get; } = ImmutableDictionary.CreateRange( + new[] + { + KeyValuePairUtil.Create(GetIdForErrorCode(ErrorCode.WRN_UseDefViolationPropertySupportedVersion), ReportDiagnostic.Warn), + KeyValuePairUtil.Create(GetIdForErrorCode(ErrorCode.WRN_UseDefViolationFieldSupportedVersion), ReportDiagnostic.Warn), + KeyValuePairUtil.Create(GetIdForErrorCode(ErrorCode.WRN_UseDefViolationThisSupportedVersion), ReportDiagnostic.Warn), + KeyValuePairUtil.Create(GetIdForErrorCode(ErrorCode.WRN_UnassignedThisAutoPropertySupportedVersion), ReportDiagnostic.Warn), + KeyValuePairUtil.Create(GetIdForErrorCode(ErrorCode.WRN_UnassignedThisSupportedVersion), ReportDiagnostic.Warn), + }); + #endregion #region Interpolated string handlers diff --git a/src/Compilers/VisualBasic/Portable/Errors/MessageProvider.vb b/src/Compilers/VisualBasic/Portable/Errors/MessageProvider.vb index 28685c2fc9496..be62b4a41e8e6 100644 --- a/src/Compilers/VisualBasic/Portable/Errors/MessageProvider.vb +++ b/src/Compilers/VisualBasic/Portable/Errors/MessageProvider.vb @@ -117,6 +117,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Return SymbolDisplay.ToDisplayString(symbol, SymbolDisplayFormat.VisualBasicShortErrorMessageFormat) End Function + Public Overrides Function GetIsEnabledByDefault(code As Integer) As Boolean + Return True + End Function + ' Given a message identifier (e.g., CS0219), severity, warning as error and a culture, ' get the entire prefix (e.g., "error BC42024:" for VB) used on error messages. Public Overrides Function GetMessagePrefix(id As String, severity As DiagnosticSeverity, isWarningAsError As Boolean, culture As CultureInfo) As String diff --git a/src/Compilers/VisualBasic/Test/Syntax/Syntax/GeneratedTests.vb b/src/Compilers/VisualBasic/Test/Syntax/Syntax/GeneratedTests.vb index 1a089907f6e1b..e8ff76e2f4a47 100644 --- a/src/Compilers/VisualBasic/Test/Syntax/Syntax/GeneratedTests.vb +++ b/src/Compilers/VisualBasic/Test/Syntax/Syntax/GeneratedTests.vb @@ -86,6 +86,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests Public Overrides Function GetErrorDisplayString(symbol As ISymbol) As String Return MessageProvider.Instance.GetErrorDisplayString(symbol) End Function + + Public Overrides Function GetIsEnabledByDefault(code As Integer) As Boolean + Return True + End Function End Class Friend Class RedIdentityRewriter diff --git a/src/Compilers/VisualBasic/Test/Syntax/TestSyntaxNodes.vb b/src/Compilers/VisualBasic/Test/Syntax/TestSyntaxNodes.vb index 397672b35ad93..585ebc41b336a 100644 --- a/src/Compilers/VisualBasic/Test/Syntax/TestSyntaxNodes.vb +++ b/src/Compilers/VisualBasic/Test/Syntax/TestSyntaxNodes.vb @@ -1105,6 +1105,10 @@ End Class Public Overrides Function GetErrorDisplayString(symbol As ISymbol) As String Return MessageProvider.Instance.GetErrorDisplayString(symbol) End Function + + Public Overrides Function GetIsEnabledByDefault(code As Integer) As Boolean + Return True + End Function End Class ' A test rewriting visitor diff --git a/src/EditorFeatures/CSharpTest/ConvertTupleToStruct/ConvertTupleToStructTests.cs b/src/EditorFeatures/CSharpTest/ConvertTupleToStruct/ConvertTupleToStructTests.cs index b00df5aa1aadd..9ad2925b2719e 100644 --- a/src/EditorFeatures/CSharpTest/ConvertTupleToStruct/ConvertTupleToStructTests.cs +++ b/src/EditorFeatures/CSharpTest/ConvertTupleToStruct/ConvertTupleToStructTests.cs @@ -2321,10 +2321,10 @@ public static implicit operator NewStruct((int a, int a) value) DiagnosticResult.CompilerError("CS7036").WithSpan(6, 22, 6, 31).WithArguments("a", "NewStruct.NewStruct(int, int)"), // /0/Test0.cs(13,16): error CS0102: The type 'NewStruct' already contains a definition for 'a' DiagnosticResult.CompilerError("CS0102").WithSpan(13, 16, 13, 17).WithArguments("NewStruct", "a"), - // /0/Test0.cs(15,12): error CS0171: Field 'NewStruct.a' must be fully assigned before control is returned to the caller - DiagnosticResult.CompilerError("CS0171").WithSpan(15, 12, 15, 21).WithArguments("NewStruct.a"), - // /0/Test0.cs(15,12): error CS0171: Field 'NewStruct.a' must be fully assigned before control is returned to the caller - DiagnosticResult.CompilerError("CS0171").WithSpan(15, 12, 15, 21).WithArguments("NewStruct.a"), + // /0/Test0.cs(15,12): error CS0171: Field 'NewStruct.a' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. + DiagnosticResult.CompilerError("CS0171").WithSpan(15, 12, 15, 21).WithArguments("NewStruct.a", "preview"), + // /0/Test0.cs(15,12): error CS0171: Field 'NewStruct.a' must be fully assigned before control is returned to the caller. Consider updating to language version 'preview' to auto-default the field. + DiagnosticResult.CompilerError("CS0171").WithSpan(15, 12, 15, 21).WithArguments("NewStruct.a", "preview"), // /0/Test0.cs(15,33): error CS0100: The parameter name 'a' is a duplicate DiagnosticResult.CompilerError("CS0100").WithSpan(15, 33, 15, 34).WithArguments("a"), // /0/Test0.cs(17,14): error CS0229: Ambiguity between 'NewStruct.a' and 'NewStruct.a'