diff --git a/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md b/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md index 744e788b4c100..85417b7843492 100644 --- a/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md +++ b/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md @@ -89,6 +89,71 @@ Note: The break will also apply to C# 10 and earlier when .NET 7 ships, but is currently scoped down to users of LangVer=preview. Tracked by https://github.com/dotnet/roslyn/issues/60640 +## Cannot return an out parameter by reference + +***Introduced in .NET SDK 7.0.100, Visual Studio 2022 version 17.3.*** + +With language version C# 11 or later, or with .NET 7.0 or later, an `out` parameter cannot be returned by reference. + +```csharp +static ref T ReturnOutParamByRef(out T t) +{ + t = default; + return ref t; // error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter +} +``` + +A possible workaround is to change the method signature to pass the parameter by `ref` instead. + +```csharp +static ref T ReturnRefParamByRef(ref T t) +{ + t = default; + return ref t; // ok +} +``` + +## Method ref struct return escape analysis depends on ref escape of ref arguments + +***Introduced in .NET SDK 7.0.100, Visual Studio 2022 version 17.3.*** + +With language version C# 11 or later, or with .NET 7.0 or later, the return value of a method invocation that returns a `ref struct` is only _safe-to-escape_ if all the `ref` and `in` arguments to the method invocation are _ref-safe-to-escape_. _The `in` arguments may include implicit default parameter values._ + +```csharp +ref struct R { } + +static R MayCaptureArg(ref int i) => new R(); + +static R MayCaptureDefaultArg(in int i = 0) => new R(); + +static R Create() +{ + int i = 0; + // error CS8347: Cannot use a result of 'MayCaptureArg(ref int)' because it may expose + // variables referenced by parameter 'i' outside of their declaration scope + return MayCaptureArg(ref i); +} + +static R CreateDefault() +{ + // error CS8347: Cannot use a result of 'MayCaptureDefaultArg(in int)' because it may expose + // variables referenced by parameter 'i' outside of their declaration scope + return MayCaptureDefaultArg(); +} +``` + +A possible workaround, if the `ref` or `in` argument is not captured in the `ref struct` return value, is to declare the parameter as `scoped ref` or `scoped in`. + +```csharp +static R CannotCaptureArg(scoped ref int i) => new R(); + +static R Create() +{ + int i = 0; + return CannotCaptureArg(ref i); // ok +} +``` + ## Unsigned right shift operator ***Introduced in .NET SDK 6.0.400, Visual Studio 2022 version 17.3.*** diff --git a/src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs b/src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs index deb3b840729f1..244c52f94f097 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs @@ -744,7 +744,7 @@ private static bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, uint return false; } - Error(diagnostics, ErrorCode.ERR_EscapeLocal, node, localSymbol); + Error(diagnostics, ErrorCode.ERR_EscapeVariable, node, localSymbol); return false; } @@ -813,8 +813,7 @@ private bool CheckParameterValEscape(SyntaxNode node, BoundParameter parameter, var parameterSymbol = parameter.ParameterSymbol; if (GetParameterValEscape(parameterSymbol) > escapeTo) { - // PROTOTYPE: Add specific error. - Error(diagnostics, ErrorCode.ERR_EscapeLocal, node, parameterSymbol); + Error(diagnostics, ErrorCode.ERR_EscapeVariable, node, parameterSymbol); return false; } return true; @@ -3232,7 +3231,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF case BoundKind.DeconstructValuePlaceholder: if (((BoundDeconstructValuePlaceholder)expr).ValEscape > escapeTo) { - Error(diagnostics, ErrorCode.ERR_EscapeLocal, node, expr.Syntax); + Error(diagnostics, ErrorCode.ERR_EscapeVariable, node, expr.Syntax); return false; } return true; @@ -3240,7 +3239,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF case BoundKind.AwaitableValuePlaceholder: if (((BoundAwaitableValuePlaceholder)expr).ValEscape > escapeTo) { - Error(diagnostics, ErrorCode.ERR_EscapeLocal, node, expr.Syntax); + Error(diagnostics, ErrorCode.ERR_EscapeVariable, node, expr.Syntax); return false; } return true; @@ -3248,7 +3247,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF case BoundKind.InterpolatedStringArgumentPlaceholder: if (((BoundInterpolatedStringArgumentPlaceholder)expr).ValSafeToEscape > escapeTo) { - Error(diagnostics, ErrorCode.ERR_EscapeLocal, node, expr.Syntax); + Error(diagnostics, ErrorCode.ERR_EscapeVariable, node, expr.Syntax); return false; } return true; @@ -3257,7 +3256,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF var localSymbol = ((BoundLocal)expr).LocalSymbol; if (localSymbol.ValEscapeScope > escapeTo) { - Error(diagnostics, ErrorCode.ERR_EscapeLocal, node, localSymbol); + Error(diagnostics, ErrorCode.ERR_EscapeVariable, node, localSymbol); return false; } return true; @@ -3374,7 +3373,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF case BoundKind.ImplicitIndexerReceiverPlaceholder: if (((BoundImplicitIndexerReceiverPlaceholder)expr).ValEscape > escapeTo) { - Error(diagnostics, ErrorCode.ERR_EscapeLocal, node, expr.Syntax); + Error(diagnostics, ErrorCode.ERR_EscapeVariable, node, expr.Syntax); return false; } return true; @@ -3382,7 +3381,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF case BoundKind.ListPatternReceiverPlaceholder: if (((BoundListPatternReceiverPlaceholder)expr).ValEscape > escapeTo) { - Error(diagnostics, ErrorCode.ERR_EscapeLocal, node, expr.Syntax); + Error(diagnostics, ErrorCode.ERR_EscapeVariable, node, expr.Syntax); return false; } return true; @@ -3390,7 +3389,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF case BoundKind.SlicePatternReceiverPlaceholder: if (((BoundSlicePatternReceiverPlaceholder)expr).ValEscape > escapeTo) { - Error(diagnostics, ErrorCode.ERR_EscapeLocal, node, expr.Syntax); + Error(diagnostics, ErrorCode.ERR_EscapeVariable, node, expr.Syntax); return false; } return true; diff --git a/src/Compilers/CSharp/Portable/Binder/Binder.cs b/src/Compilers/CSharp/Portable/Binder/Binder.cs index 52f20c35e9721..f69aadb415905 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder.cs @@ -156,8 +156,10 @@ internal bool CheckOverflowAtCompileTime } } - internal bool UseUpdatedEscapeRules => Compilation.IsFeatureEnabled(MessageID.IDS_FeatureRefFields) || - Compilation.Assembly.RuntimeSupportsByRefFields; + // https://github.com/dotnet/roslyn/issues/62131: Enable updated escape rules if + // System.Runtime.CompilerServices.RuntimeFeature.ByRefFields exists. + internal bool UseUpdatedEscapeRules => Compilation.IsFeatureEnabled(MessageID.IDS_FeatureRefFields) /*|| + Compilation.Assembly.RuntimeSupportsByRefFields*/; /// /// Some nodes have special binders for their contents (like Blocks) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 05bb9f65cee3c..c8fbd43e9143b 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -2814,7 +2814,6 @@ private BoundExpression BindOutVariableDeclarationArgument( CheckFeatureAvailability(declarationExpression, MessageID.IDS_FeatureExpressionVariablesInQueriesAndInitializers, diagnostics); } - // PROTOTYPE: Test with 'out scoped R' and 'out scoped var', with -langversion:10 and -langversion:11. bool isConst = false; AliasSymbol alias; var declType = BindVariableTypeWithAnnotations(declarationExpression, diagnostics, typeSyntax, ref isConst, out isVar, out alias); diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs index e0f78b674b1b6..95c2db4891d8e 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs @@ -141,57 +141,9 @@ private UnboundLambda AnalyzeAnonymousFunction( } else { - bool scopedBeforeRef = false; - bool scopedAfterRef = false; type = BindType(typeSyntax, diagnostics); - foreach (var modifier in p.Modifiers) - { - switch (modifier.Kind()) - { - case SyntaxKind.RefKeyword: - refKind = RefKind.Ref; - break; - - case SyntaxKind.OutKeyword: - refKind = RefKind.Out; - break; - - case SyntaxKind.InKeyword: - refKind = RefKind.In; - break; - - case SyntaxKind.ParamsKeyword: - // This was a parse error in the native compiler; - // it is a semantic analysis error in Roslyn. See comments to - // changeset 1674 for details. - Error(diagnostics, ErrorCode.ERR_IllegalParams, p); - break; - - case SyntaxKind.ThisKeyword: - Error(diagnostics, ErrorCode.ERR_ThisInBadContext, modifier); - break; - - case SyntaxKind.ScopedKeyword: - ModifierUtils.CheckScopedModifierAvailability(p, modifier, diagnostics); - if (refKind == RefKind.None) - { - scopedBeforeRef = true; - } - else - { - scopedAfterRef = true; - } - break; - } - } - if (scopedAfterRef) - { - scope = DeclarationScope.ValueScoped; - } - else if (scopedBeforeRef) - { - scope = (refKind == RefKind.None) ? DeclarationScope.ValueScoped : DeclarationScope.RefScoped; - } + ParameterHelpers.CheckParameterModifiers(p, diagnostics, parsingFunctionPointerParams: false, parsingLambdaParams: true); + refKind = ParameterHelpers.GetModifiers(p.Modifiers, out _, out _, out _, out scope); } namesBuilder.Add(p.Identifier.ValueText); diff --git a/src/Compilers/CSharp/Portable/Binder/FixedStatementBinder.cs b/src/Compilers/CSharp/Portable/Binder/FixedStatementBinder.cs index b01e852cff875..f80197f1bb94b 100644 --- a/src/Compilers/CSharp/Portable/Binder/FixedStatementBinder.cs +++ b/src/Compilers/CSharp/Portable/Binder/FixedStatementBinder.cs @@ -45,7 +45,7 @@ protected override ImmutableArray BuildLocals() foreach (VariableDeclaratorSyntax declarator in _syntax.Declaration.Variables) { - locals.Add(MakeLocal(_syntax.Declaration, declarator, LocalDeclarationKind.FixedVariable, hasScopedModifier: false)); // PROTOTYPE: Handle 'scoped' modifier. + locals.Add(MakeLocal(_syntax.Declaration, declarator, LocalDeclarationKind.FixedVariable, hasScopedModifier: false)); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, declarator); diff --git a/src/Compilers/CSharp/Portable/Binder/ForLoopBinder.cs b/src/Compilers/CSharp/Portable/Binder/ForLoopBinder.cs index a3ac6aeeb183f..49c6f1136f24b 100644 --- a/src/Compilers/CSharp/Portable/Binder/ForLoopBinder.cs +++ b/src/Compilers/CSharp/Portable/Binder/ForLoopBinder.cs @@ -45,7 +45,7 @@ protected override ImmutableArray BuildLocals() foreach (var vdecl in _syntax.Declaration.Variables) { - var localSymbol = MakeLocal(_syntax.Declaration, vdecl, LocalDeclarationKind.RegularVariable, hasScopedModifier: false); // PROTOTYPE: Handle 'scoped' modifier. + var localSymbol = MakeLocal(_syntax.Declaration, vdecl, LocalDeclarationKind.RegularVariable, hasScopedModifier: false); // https://github.com/dotnet/roslyn/issues/62039: Allow 'scoped' modifier. locals.Add(localSymbol); // also gather expression-declared variables from the bracketed argument lists and the initializers diff --git a/src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs b/src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs index d052d7ef14caa..03259666c6269 100644 --- a/src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs +++ b/src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs @@ -55,7 +55,7 @@ protected override ImmutableArray BuildLocals() foreach (VariableDeclaratorSyntax declarator in declarationSyntax.Variables) { - locals.Add(MakeLocal(declarationSyntax, declarator, LocalDeclarationKind.UsingVariable, hasScopedModifier: false)); // PROTOTYPE: Handle 'scoped' modifier. + locals.Add(MakeLocal(declarationSyntax, declarator, LocalDeclarationKind.UsingVariable, hasScopedModifier: false)); // https://github.com/dotnet/roslyn/issues/62039: Allow 'scoped' modifier. // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, declarator); diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 2a85146431f72..13da821d8b2c6 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -5069,7 +5069,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Fields of static readonly field '{0}' cannot be returned by writable reference - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter + Cannot return a parameter by reference '{0}' because it is not a ref parameter Cannot return by reference a member of parameter '{0}' because it is not a ref or out parameter @@ -5086,8 +5086,8 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Expression cannot be used in this context because it may indirectly expose variables outside of their declaration scope - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope @@ -6763,6 +6763,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ The 'scoped' modifier of parameter '{0}' doesn't match partial method declaration. + + A fixed field must not be a ref field. + Auto-implemented property '{0}' is read before being explicitly assigned, causing a preceding implicit assignment of 'default'. diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 81682de02a770..52ce9a5a148d6 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1538,7 +1538,7 @@ internal enum ErrorCode ERR_EscapeOther = 8349, ERR_CallArgMixing = 8350, ERR_MismatchedRefEscapeInTernary = 8351, - ERR_EscapeLocal = 8352, + ERR_EscapeVariable = 8352, ERR_EscapeStackAlloc = 8353, ERR_RefReturnThis = 8354, ERR_OutAttrOnInParam = 8355, @@ -2095,6 +2095,7 @@ internal enum ErrorCode ERR_ScriptsAndSubmissionsCannotHaveRequiredMembers = 9045, ERR_BadAbstractEqualityOperatorSignature = 9046, ERR_ScopedRefAndRefStructOnly = 9048, + ERR_FixedFieldMustNotBeRef = 9049, #endregion diff --git a/src/Compilers/CSharp/Portable/Symbols/DeclarationScope.cs b/src/Compilers/CSharp/Portable/Symbols/DeclarationScope.cs index 9c4183b1dc5bb..1aaa271c757ce 100644 --- a/src/Compilers/CSharp/Portable/Symbols/DeclarationScope.cs +++ b/src/Compilers/CSharp/Portable/Symbols/DeclarationScope.cs @@ -4,9 +4,9 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols { - // PROTOTYPE: Internally, scope is represented with this enum, but the public API uses a - // pair of IsRefScoped and IsValueScoped bools (see ILocalSymbol, IParameterSymbol, - // and LifetimeAnnotationAttribute). We should have a common representation. + // https://github.com/dotnet/roslyn/issues/61647: Internally, scope is represented with this enum, + // but the public API uses a pair of IsRefScoped and IsValueScoped bools (see ILocalSymbol, + // IParameterSymbol, and LifetimeAnnotationAttribute). We should have a common representation. // And we should use common terms for the attribute and enum names. internal enum DeclarationScope : byte { diff --git a/src/Compilers/CSharp/Portable/Symbols/FieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/FieldSymbol.cs index 573037a39aa71..c4fb89042cd59 100644 --- a/src/Compilers/CSharp/Portable/Symbols/FieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/FieldSymbol.cs @@ -353,8 +353,7 @@ internal bool CalculateUseSiteDiagnostic(ref UseSiteInfo result) Debug.Assert(IsDefinition); // Check type, custom modifiers - // PROTOTYPE: Disallow volatile for ref fields. - if (DeriveUseSiteInfoFromType(ref result, this.TypeWithAnnotations, AllowedRequiredModifierType.System_Runtime_CompilerServices_Volatile) || + if (DeriveUseSiteInfoFromType(ref result, this.TypeWithAnnotations, RefKind == RefKind.None ? AllowedRequiredModifierType.System_Runtime_CompilerServices_Volatile : AllowedRequiredModifierType.None) || DeriveUseSiteInfoFromCustomModifiers(ref result, this.RefCustomModifiers, AllowedRequiredModifierType.None)) { return true; diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEFieldSymbol.cs index 3b2add885b5dd..07a3baea98c2e 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEFieldSymbol.cs @@ -326,7 +326,6 @@ private void EnsureSignatureIsLoaded() _packedFlags.SetRefKind(refKind); _packedFlags.SetIsVolatile(customModifiersArray.Any(static m => !m.IsOptional && ((CSharpCustomModifier)m).ModifierSymbol.SpecialType == SpecialType.System_Runtime_CompilerServices_IsVolatile)); - // PROTOTYPE: `fixed ref` field use should be disallowed. TypeSymbol fixedElementType; int fixedSize; if (customModifiersArray.IsEmpty && IsFixedBuffer(out fixedSize, out fixedElementType)) @@ -637,6 +636,10 @@ internal override UseSiteInfo GetUseSiteInfo() { UseSiteInfo result = new UseSiteInfo(primaryDependency); CalculateUseSiteDiagnostic(ref result); + if (IsFixedSizeBuffer && RefKind != RefKind.None) + { + MergeUseSiteInfo(ref result, new UseSiteInfo(new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this))); + } deriveCompilerFeatureRequiredUseSiteInfo(ref result); _lazyCachedUseSiteInfo.Initialize(primaryDependency, result); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs index 9ecd5cbb8215d..5cbab0bf56f21 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs @@ -346,7 +346,7 @@ private ImmutableArray MakeParameters( { type = parameterTypes[p]; refKind = parameterRefKinds[p]; - scope = DeclarationScope.Unscoped; // PROTOTYPE: DeclarationScope should be taken from delegate signature. + scope = DeclarationScope.Unscoped; // https://github.com/dotnet/roslyn/issues/62080: DeclarationScope should be taken from delegate signature. } else { diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs index 4fe08d2034d4c..6b8d0ab15cbaa 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs @@ -239,7 +239,7 @@ internal void ComputeReturnType() var diagnostics = BindingDiagnosticBag.GetInstance(_declarationDiagnostics); TypeSyntax returnTypeSyntax = Syntax.ReturnType; - TypeWithAnnotations returnType = WithTypeParametersBinder.BindType(returnTypeSyntax.SkipRef(), diagnostics); + TypeWithAnnotations returnType = WithTypeParametersBinder.BindType(returnTypeSyntax.SkipRef(out _, allowScoped: false, diagnostics), diagnostics); var compilation = DeclaringCompilation; diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs b/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs index 8d1376ef244b7..96f3625ab6374 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs @@ -138,7 +138,7 @@ private static ImmutableArray MakeParameters lastIndex) break; - CheckParameterModifiers(parameterSyntax, diagnostics, parsingFunctionPointer); + CheckParameterModifiers(parameterSyntax, diagnostics, parsingFunctionPointer, parsingLambdaParams: false); var refKind = GetModifiers(parameterSyntax.Modifiers, out SyntaxToken refnessKeyword, out SyntaxToken paramsKeyword, out SyntaxToken thisKeyword, out DeclarationScope scope); if (thisKeyword.Kind() != SyntaxKind.None && !allowThis) @@ -397,20 +397,26 @@ private static void EnsureNullableAttributeExists(CSharpCompilation compilation, private static Location GetParameterLocation(ParameterSymbol parameter) => parameter.GetNonNullSyntaxNode().Location; - private static void CheckParameterModifiers(BaseParameterSyntax parameter, BindingDiagnosticBag diagnostics, bool parsingFunctionPointerParams) + internal static void CheckParameterModifiers(BaseParameterSyntax parameter, BindingDiagnosticBag diagnostics, bool parsingFunctionPointerParams, bool parsingLambdaParams) { var seenThis = false; var seenRef = false; var seenOut = false; var seenParams = false; var seenIn = false; + bool scopedBeforeRef = false; + bool scopedAfterRef = false; foreach (var modifier in parameter.Modifiers) { switch (modifier.Kind()) { case SyntaxKind.ThisKeyword: - if (seenThis) + if (parsingLambdaParams) + { + diagnostics.Add(ErrorCode.ERR_ThisInBadContext, modifier.GetLocation()); + } + else if (seenThis) { addERR_DupParamMod(diagnostics, modifier); } @@ -479,7 +485,11 @@ private static void CheckParameterModifiers(BaseParameterSyntax parameter, Bindi break; case SyntaxKind.ParamsKeyword when !parsingFunctionPointerParams: - if (seenParams) + if (parsingLambdaParams) + { + diagnostics.Add(ErrorCode.ERR_IllegalParams, modifier.GetLocation()); + } + else if (seenParams) { addERR_DupParamMod(diagnostics, modifier); } @@ -530,7 +540,17 @@ private static void CheckParameterModifiers(BaseParameterSyntax parameter, Bindi case SyntaxKind.ScopedKeyword when !parsingFunctionPointerParams: ModifierUtils.CheckScopedModifierAvailability(parameter, modifier, diagnostics); - // PROTOTYPE: Check for duplicate modifiers; check ordering. + { + ref bool scopedBeforeOrAfter = ref (seenIn || seenOut || seenRef) ? ref scopedAfterRef : ref scopedBeforeRef; + if (scopedBeforeOrAfter) + { + addERR_DupParamMod(diagnostics, modifier); + } + else + { + scopedBeforeOrAfter = true; + } + } break; case SyntaxKind.ParamsKeyword when parsingFunctionPointerParams: @@ -827,7 +847,7 @@ internal static MethodSymbol FindContainingGenericMethod(Symbol symbol) return null; } - private static RefKind GetModifiers(SyntaxTokenList modifiers, out SyntaxToken refnessKeyword, out SyntaxToken paramsKeyword, out SyntaxToken thisKeyword, out DeclarationScope scope) + internal static RefKind GetModifiers(SyntaxTokenList modifiers, out SyntaxToken refnessKeyword, out SyntaxToken paramsKeyword, out SyntaxToken thisKeyword, out DeclarationScope scope) { var refKind = RefKind.None; bool scopedBeforeRef = false; diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs index 4588db690fab3..3c121938a6918 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs @@ -742,7 +742,13 @@ protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttribut ValidateCallerArgumentExpressionAttribute(arguments.AttributeSyntaxOpt, attribute, diagnostics); } else if (ReportExplicitUseOfReservedAttributes(in arguments, - ReservedAttributes.DynamicAttribute | ReservedAttributes.IsReadOnlyAttribute | ReservedAttributes.IsUnmanagedAttribute | ReservedAttributes.IsByRefLikeAttribute | ReservedAttributes.TupleElementNamesAttribute | ReservedAttributes.NullableAttribute | ReservedAttributes.NativeIntegerAttribute)) + ReservedAttributes.DynamicAttribute | + ReservedAttributes.IsReadOnlyAttribute | + ReservedAttributes.IsUnmanagedAttribute | + ReservedAttributes.IsByRefLikeAttribute | + ReservedAttributes.TupleElementNamesAttribute | + ReservedAttributes.NullableAttribute | + ReservedAttributes.NativeIntegerAttribute)) { } else if (attribute.IsTargetAttribute(this, AttributeDescription.AllowNullAttribute)) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs index 23d02a89555ae..f229cde04f7a5 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs @@ -43,10 +43,8 @@ internal static void AddDelegateMembers( DelegateDeclarationSyntax syntax, BindingDiagnosticBag diagnostics) { - var compilation = delegateType.DeclaringCompilation; Binder binder = delegateType.GetBinder(syntax.ParameterList); - RefKind refKind; - TypeSyntax returnTypeSyntax = syntax.ReturnType.SkipRef(out refKind); + TypeSyntax returnTypeSyntax = syntax.ReturnType.SkipRef(out RefKind refKind, allowScoped: false, diagnostics); var returnType = binder.BindType(returnTypeSyntax, diagnostics); // reuse types to avoid reporting duplicate errors if missing: diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs index 5ea005c31f72b..1a45e6fc83a32 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs @@ -64,9 +64,25 @@ private SourceLocalSymbol( this._scopeBinder = scopeBinder; this._containingSymbol = containingSymbol; this._identifierToken = identifierToken; - this._typeSyntax = allowRefKind ? typeSyntax?.SkipRef(out this._refKind) : typeSyntax; + + if (allowRefKind && typeSyntax is RefTypeSyntax refTypeSyntax) + { + this._typeSyntax = refTypeSyntax.Type; + this._refKind = refTypeSyntax.ReadOnlyKeyword.Kind() == SyntaxKind.ReadOnlyKeyword ? + RefKind.RefReadOnly : + RefKind.Ref; + this._scope = refTypeSyntax.ScopedKeyword.Kind() == SyntaxKind.ScopedKeyword ? + DeclarationScope.ValueScoped : + (hasScopedModifier ? DeclarationScope.RefScoped : DeclarationScope.Unscoped); + } + else + { + this._typeSyntax = typeSyntax; + this._refKind = RefKind.None; + this._scope = hasScopedModifier ? DeclarationScope.ValueScoped : DeclarationScope.Unscoped; + } + this._declarationKind = declarationKind; - this._scope = GetScope(hasScopedModifier, allowRefKind, typeSyntax); // create this eagerly as it will always be needed for the EnsureSingleDefinition _locations = ImmutableArray.Create(identifierToken.GetLocation()); @@ -80,22 +96,6 @@ private SourceLocalSymbol( _valEscapeScope = Binder.ExternalScope; } - private static DeclarationScope GetScope(bool hasScopedModifier, bool allowRefKind, TypeSyntax typeSyntax) - { - if (typeSyntax is RefTypeSyntax refTypeSyntax) - { - if (refTypeSyntax.ScopedKeyword.Kind() == SyntaxKind.ScopedKeyword) - { - return DeclarationScope.ValueScoped; - } - if (allowRefKind && hasScopedModifier) - { - return DeclarationScope.RefScoped; - } - } - return hasScopedModifier ? DeclarationScope.ValueScoped : DeclarationScope.Unscoped; - } - /// /// Binder that owns the scope for the local, the one that returns it in its array. /// @@ -206,7 +206,7 @@ public static SourceLocalSymbol MakeDeconstructionLocal( Debug.Assert(nodeBinder != null); Debug.Assert(closestTypeSyntax.Kind() != SyntaxKind.RefType); - // PROTOTYPE: Can these variables be `scoped` or `ref scoped`? + // https://github.com/dotnet/roslyn/issues/62039: Allow 'scoped' modifier. return closestTypeSyntax.IsVar ? new DeconstructionLocalSymbol(containingSymbol, scopeBinder, nodeBinder, closestTypeSyntax, identifierToken, kind, deconstruction) : new SourceLocalSymbol(containingSymbol, scopeBinder, false, closestTypeSyntax, identifierToken, kind, hasScopedModifier: false); @@ -238,7 +238,7 @@ internal static LocalSymbol MakeLocalSymbolWithEnclosingContext( Contains(nodeToBind.Ancestors().OfType().First().Kind()) || nodeToBind is ExpressionSyntax); Debug.Assert(!(nodeToBind.Kind() == SyntaxKind.SwitchExpressionArm) || nodeBinder is SwitchExpressionArmBinder); - // PROTOTYPE: Can these variables be `scoped` or `ref scoped`? + // https://github.com/dotnet/roslyn/issues/62039: Allow 'scoped' modifier. return typeSyntax?.IsVar != false && kind != LocalDeclarationKind.DeclarationExpressionVariable ? new LocalSymbolWithEnclosingContext(containingSymbol, scopeBinder, nodeBinder, typeSyntax, identifierToken, kind, nodeToBind, forbiddenZone) : new SourceLocalSymbol(containingSymbol, scopeBinder, false, typeSyntax, identifierToken, kind, hasScopedModifier: false); @@ -692,7 +692,7 @@ public ForEachLocalSymbol( SyntaxToken identifierToken, ExpressionSyntax collection, LocalDeclarationKind declarationKind) : - base(containingSymbol, scopeBinder, allowRefKind: true, typeSyntax, identifierToken, declarationKind, hasScopedModifier: false) // PROTOTYPE: Can a foreach iteration variable be `scoped` or `ref scoped`? + base(containingSymbol, scopeBinder, allowRefKind: true, typeSyntax, identifierToken, declarationKind, hasScopedModifier: false) // https://github.com/dotnet/roslyn/issues/62039: Allow 'scoped' modifier. { Debug.Assert(declarationKind == LocalDeclarationKind.ForEachIterationVariable); _collection = collection; @@ -733,7 +733,7 @@ public DeconstructionLocalSymbol( SyntaxToken identifierToken, LocalDeclarationKind declarationKind, SyntaxNode deconstruction) - : base(containingSymbol, scopeBinder, false, typeSyntax, identifierToken, declarationKind, hasScopedModifier: false) // PROTOTYPE: Can these variables be `scoped` or `ref scoped`? + : base(containingSymbol, scopeBinder, false, typeSyntax, identifierToken, declarationKind, hasScopedModifier: false) // https://github.com/dotnet/roslyn/issues/62039: Allow 'scoped' modifier. { _deconstruction = deconstruction; _nodeBinder = nodeBinder; @@ -798,7 +798,7 @@ public LocalSymbolWithEnclosingContext( LocalDeclarationKind declarationKind, SyntaxNode nodeToBind, SyntaxNode forbiddenZone) - : base(containingSymbol, scopeBinder, false, typeSyntax, identifierToken, declarationKind, hasScopedModifier: false) // PROTOTYPE: Can these variables be `scoped` or `ref scoped`? + : base(containingSymbol, scopeBinder, false, typeSyntax, identifierToken, declarationKind, hasScopedModifier: false) // https://github.com/dotnet/roslyn/issues/62039: Allow 'scoped' modifier. { Debug.Assert( nodeToBind.Kind() == SyntaxKind.CasePatternSwitchLabel || diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs index abfb109b5d4e3..6652539dc7891 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs @@ -4426,6 +4426,8 @@ private void AddNonTypeMembers( case SyntaxKind.FieldDeclaration: { var fieldSyntax = (FieldDeclarationSyntax)m; + _ = fieldSyntax.Declaration.Type.SkipRef(out RefKind refKind, allowScoped: false, diagnostics); + if (IsImplicitClass && reportMisplacedGlobalCode) { diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, @@ -4433,7 +4435,7 @@ private void AddNonTypeMembers( } bool modifierErrors; - var modifiers = SourceMemberFieldSymbol.MakeModifiers(this, fieldSyntax.Declaration.Variables[0].Identifier, fieldSyntax.Modifiers, diagnostics, out modifierErrors); + var modifiers = SourceMemberFieldSymbol.MakeModifiers(this, fieldSyntax.Declaration.Variables[0].Identifier, fieldSyntax.Modifiers, isRefField: refKind != RefKind.None, diagnostics, out modifierErrors); foreach (var variable in fieldSyntax.Declaration.Variables) { var fieldSymbol = (modifiers & DeclarationModifiers.Fixed) == 0 diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberFieldSymbol.cs index 815f4c7408aaa..516f0a5f5c413 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberFieldSymbol.cs @@ -142,7 +142,7 @@ public override int FixedSize } } - internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingType, SyntaxToken firstIdentifier, SyntaxTokenList modifiers, BindingDiagnosticBag diagnostics, out bool modifierErrors) + internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingType, SyntaxToken firstIdentifier, SyntaxTokenList modifiers, bool isRefField, BindingDiagnosticBag diagnostics, out bool modifierErrors) { bool isInterface = containingType.IsInterface; DeclarationModifiers defaultAccess = @@ -173,35 +173,11 @@ internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingTyp if ((result & DeclarationModifiers.Fixed) != 0) { - if ((result & DeclarationModifiers.Static) != 0) - { - // The modifier 'static' is not valid for this item - diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.StaticKeyword)); - } - - if ((result & DeclarationModifiers.ReadOnly) != 0) - { - // The modifier 'readonly' is not valid for this item - diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.ReadOnlyKeyword)); - } - - if ((result & DeclarationModifiers.Const) != 0) - { - // The modifier 'const' is not valid for this item - diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.ConstKeyword)); - } - - if ((result & DeclarationModifiers.Volatile) != 0) - { - // The modifier 'volatile' is not valid for this item - diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.VolatileKeyword)); - } - - if ((result & DeclarationModifiers.Required) != 0) - { - // The modifier 'required' is not valid for this item - diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.RequiredKeyword)); - } + reportBadMemberFlagIfAny(result, DeclarationModifiers.Static, diagnostics, errorLocation); + reportBadMemberFlagIfAny(result, DeclarationModifiers.ReadOnly, diagnostics, errorLocation); + reportBadMemberFlagIfAny(result, DeclarationModifiers.Const, diagnostics, errorLocation); + reportBadMemberFlagIfAny(result, DeclarationModifiers.Volatile, diagnostics, errorLocation); + reportBadMemberFlagIfAny(result, DeclarationModifiers.Required, diagnostics, errorLocation); result &= ~(DeclarationModifiers.Static | DeclarationModifiers.ReadOnly | DeclarationModifiers.Const | DeclarationModifiers.Volatile | DeclarationModifiers.Required); Debug.Assert((result & ~(DeclarationModifiers.AccessibilityMask | DeclarationModifiers.Fixed | DeclarationModifiers.Unsafe | DeclarationModifiers.New)) == 0); @@ -215,28 +191,12 @@ internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingTyp diagnostics.Add(ErrorCode.ERR_StaticConstant, errorLocation, firstIdentifier.ValueText); } - if ((result & DeclarationModifiers.ReadOnly) != 0) - { - // The modifier 'readonly' is not valid for this item - diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.ReadOnlyKeyword)); - } + reportBadMemberFlagIfAny(result, DeclarationModifiers.ReadOnly, diagnostics, errorLocation); + reportBadMemberFlagIfAny(result, DeclarationModifiers.Volatile, diagnostics, errorLocation); + reportBadMemberFlagIfAny(result, DeclarationModifiers.Unsafe, diagnostics, errorLocation); - if ((result & DeclarationModifiers.Volatile) != 0) + if (reportBadMemberFlagIfAny(result, DeclarationModifiers.Required, diagnostics, errorLocation)) { - // The modifier 'volatile' is not valid for this item - diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.VolatileKeyword)); - } - - if ((result & DeclarationModifiers.Unsafe) != 0) - { - // The modifier 'unsafe' is not valid for this item - diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.UnsafeKeyword)); - } - - if ((result & DeclarationModifiers.Required) != 0) - { - // The modifier 'required' is not valid for this item - diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.RequiredKeyword)); result &= ~DeclarationModifiers.Required; } @@ -259,7 +219,25 @@ internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingTyp containingType.CheckUnsafeModifier(result, errorLocation, diagnostics); } + if (isRefField) + { + reportBadMemberFlagIfAny(result, DeclarationModifiers.Static, diagnostics, errorLocation); + reportBadMemberFlagIfAny(result, DeclarationModifiers.Const, diagnostics, errorLocation); + reportBadMemberFlagIfAny(result, DeclarationModifiers.Volatile, diagnostics, errorLocation); + } + return result; + + static bool reportBadMemberFlagIfAny(DeclarationModifiers result, DeclarationModifiers modifier, BindingDiagnosticBag diagnostics, SourceLocation errorLocation) + { + if ((result & modifier) != 0) + { + // The modifier '{0}' is not valid for this item + diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, ModifierUtils.ConvertSingleModifierToSyntaxText(modifier)); + return true; + } + return false; + } } internal sealed override void ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken) @@ -569,6 +547,11 @@ private TypeAndRefKind GetTypeAndRefKind(ConsList fieldsBeingBound) diagnostics.Add(ErrorCode.ERR_FixedNotInStruct, ErrorLocation); } + if (refKind != RefKind.None) + { + diagnostics.Add(ErrorCode.ERR_FixedFieldMustNotBeRef, ErrorLocation); + } + var elementType = ((PointerTypeSymbol)type.Type).PointedAtType; int elementSize = elementType.FixedBufferElementSizeInBytes(); if (elementSize == 0) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs index 8f0842543ee32..020f765ada186 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs @@ -528,7 +528,11 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut { } else if (ReportExplicitUseOfReservedAttributes(in arguments, - ReservedAttributes.IsReadOnlyAttribute | ReservedAttributes.IsUnmanagedAttribute | ReservedAttributes.IsByRefLikeAttribute | ReservedAttributes.NullableContextAttribute | ReservedAttributes.CaseSensitiveExtensionAttribute)) + ReservedAttributes.IsReadOnlyAttribute | + ReservedAttributes.IsUnmanagedAttribute | + ReservedAttributes.IsByRefLikeAttribute | + ReservedAttributes.NullableContextAttribute | + ReservedAttributes.CaseSensitiveExtensionAttribute)) { } else if (attribute.IsTargetAttribute(this, AttributeDescription.SecurityCriticalAttribute) @@ -703,7 +707,13 @@ private void DecodeWellKnownAttributeAppliedToReturnValue(ref DecodeWellKnownAtt MarshalAsAttributeDecoder.Decode(ref arguments, AttributeTargets.ReturnValue, MessageProvider.Instance); } else if (ReportExplicitUseOfReservedAttributes(in arguments, - ReservedAttributes.DynamicAttribute | ReservedAttributes.IsUnmanagedAttribute | ReservedAttributes.IsReadOnlyAttribute | ReservedAttributes.IsByRefLikeAttribute | ReservedAttributes.TupleElementNamesAttribute | ReservedAttributes.NullableAttribute | ReservedAttributes.NativeIntegerAttribute)) + ReservedAttributes.DynamicAttribute | + ReservedAttributes.IsUnmanagedAttribute | + ReservedAttributes.IsReadOnlyAttribute | + ReservedAttributes.IsByRefLikeAttribute | + ReservedAttributes.TupleElementNamesAttribute | + ReservedAttributes.NullableAttribute | + ReservedAttributes.NativeIntegerAttribute)) { } else if (attribute.IsTargetAttribute(this, AttributeDescription.MaybeNullAttribute)) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index c1bb81d1244bc..73a2c91b162f0 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -140,8 +140,7 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray Pa private TypeWithAnnotations ComputeType(Binder binder, SyntaxNode syntax, BindingDiagnosticBag diagnostics) { - RefKind refKind; - var typeSyntax = GetTypeSyntax(syntax).SkipRef(out refKind); + var typeSyntax = GetTypeSyntax(syntax).SkipRef(out _, allowScoped: false, diagnostics); var type = binder.BindType(typeSyntax, diagnostics); CompoundUseSiteInfo useSiteInfo = binder.GetNewCompoundUseSiteInfo(diagnostics); diff --git a/src/Compilers/CSharp/Portable/Syntax/SyntaxNodeExtensions.cs b/src/Compilers/CSharp/Portable/Syntax/SyntaxNodeExtensions.cs index e1a32d10e1f00..fb81d2bb470b4 100644 --- a/src/Compilers/CSharp/Portable/Syntax/SyntaxNodeExtensions.cs +++ b/src/Compilers/CSharp/Portable/Syntax/SyntaxNodeExtensions.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Microsoft.CodeAnalysis.CSharp @@ -227,29 +228,31 @@ internal static RefKind GetRefKind(this TypeSyntax syntax) return refKind; } - internal static TypeSyntax SkipRef(this TypeSyntax syntax) + internal static TypeSyntax SkipRef(this TypeSyntax syntax, out RefKind refKind) { - if (syntax.Kind() == SyntaxKind.RefType) - { - syntax = ((RefTypeSyntax)syntax).Type; - } - - return syntax; + return SkipRef(syntax, out refKind, allowScoped: true, diagnostics: null); } - internal static TypeSyntax SkipRef(this TypeSyntax syntax, out RefKind refKind) + internal static TypeSyntax SkipRef(this TypeSyntax syntax, out RefKind refKind, bool allowScoped, BindingDiagnosticBag? diagnostics) { - refKind = RefKind.None; + Debug.Assert(allowScoped || diagnostics is { }); + if (syntax.Kind() == SyntaxKind.RefType) { var refType = (RefTypeSyntax)syntax; refKind = refType.ReadOnlyKeyword.Kind() == SyntaxKind.ReadOnlyKeyword ? RefKind.RefReadOnly : RefKind.Ref; - - syntax = refType.Type; + if (refType.ScopedKeyword.Kind() == SyntaxKind.ScopedKeyword && + !allowScoped && + diagnostics is { }) + { + diagnostics.Add(ErrorCode.ERR_BadMemberFlag, refType.ScopedKeyword.GetLocation(), SyntaxFacts.GetText(SyntaxKind.ScopedKeyword)); + } + return refType.Type; } + refKind = RefKind.None; return syntax; } diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index db8f3d042334b..9f9b9b4e9657b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -442,6 +442,11 @@ Vlastnost kontraktu rovnosti záznamu {0} musí mít přístupový objekt get. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static Explicitní implementace uživatelem definovaného operátoru {0} musí být deklarovaná jako statická. @@ -572,6 +577,11 @@ Obor názvů pro celý soubor musí předcházet všem ostatním členům v souboru. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? Příkaz foreach nejde použít pro proměnné typu {0}, protože {0} neobsahuje veřejnou definici instance nebo rozšíření pro {1}. Měli jste v úmyslu await foreach místo foreach? @@ -11078,8 +11088,8 @@ Pokud chcete odstranit toto varování, můžete místo toho použít /reference - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - Parametr nejde vrátit pomocí odkazu {0}, protože nejde o parametr Ref nebo Out. + Cannot return a parameter by reference '{0}' because it is not a ref parameter + Parametr nejde vrátit pomocí odkazu {0}, protože nejde o parametr Ref nebo Out. @@ -11107,11 +11117,6 @@ Pokud chcete odstranit toto varování, můžete místo toho použít /reference V tomto kontextu nejde výraz použít, protože může nepřímo vystavit proměnné mimo jejich rozsah deklarace. - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - V tomto kontextu nejde použít místní {0}, protože může vystavit odkazované proměnné mimo jejich rozsah deklarace. - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope V tomto kontextu nejde použít výsledek z {0}, protože může vystavit proměnné, na které odkazuje parametr {1}, mimo jejich rozsah deklarace. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 3536e7302b0d8..9ba4ce1a7f3d8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -442,6 +442,11 @@ Die EqualityContract-Eigenschaft "{0}" für Datensätze muss eine get-Zugriffsmethode aufweisen. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static Die explizite Implementierung eines benutzerdefinierten Operators "{0}" muss als statisch deklariert werden. @@ -572,6 +577,11 @@ Der Dateibereichsnamespace muss allen anderen Elementen in einer Datei vorangestellt sein. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? Eine foreach-Anweisung kann nicht für Variablen vom Typ "{0}" verwendet werden, weil "{0}" keine öffentliche Instanz- oder Erweiterungsdefinition für "{1}" enthält. Meinten Sie "await foreach" statt "foreach"? @@ -11078,8 +11088,8 @@ Um die Warnung zu beheben, können Sie stattdessen /reference verwenden (Einbett - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - Ein Parameter kann nicht als Verweis "{0}" zurückgegeben werden, weil es sich nicht um einen ref- oder out-Parameter handelt. + Cannot return a parameter by reference '{0}' because it is not a ref parameter + Ein Parameter kann nicht als Verweis "{0}" zurückgegeben werden, weil es sich nicht um einen ref- oder out-Parameter handelt. @@ -11107,11 +11117,6 @@ Um die Warnung zu beheben, können Sie stattdessen /reference verwenden (Einbett Der Ausdruck kann in diesem Kontext nicht verwendet werden, weil Variablen dadurch möglicherweise außerhalb ihrer Deklaration indirekt verfügbar gemacht werden. - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - "{0}" (lokal) kann in diesem Kontext nicht verwendet werden, weil referenzierte Variablen dadurch möglicherweise außerhalb ihres Deklarationsbereichs verfügbar gemacht werden. - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope Ein Ergebnis von "{0}" kann in diesem Kontext nicht verwendet werden, weil dadurch vom Parameter "{1}" referenzierte Variablen möglicherweise außerhalb ihres Deklarationsbereichs verfügbar gemacht werden. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 1d01e315c15fa..c5e470f936f5b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -442,6 +442,11 @@ La propiedad del contrato de igualdad de registros "{0}" debe tener un descriptor de acceso get. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static La implementación explícita de un operador definido por el usuario "{0}" se debe declarar como estático @@ -572,6 +577,11 @@ El espacio de nombres con ámbito de archivo debe preceder a todos los demás miembros de un archivo. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? La instrucción foreach no puede funcionar en variables de tipo "{0}" porque "{0}" no contiene ninguna definición de extensión o instancia pública para "{1}". ¿Quiso decir “await foreach” en lugar de “foreach”? @@ -11078,8 +11088,8 @@ Para eliminar la advertencia puede usar /reference (establezca la propiedad Embe - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - No se pude devolver por referencia un parámetro '{0}' porque no es de tipo ref o out. + Cannot return a parameter by reference '{0}' because it is not a ref parameter + No se pude devolver por referencia un parámetro '{0}' porque no es de tipo ref o out. @@ -11107,11 +11117,6 @@ Para eliminar la advertencia puede usar /reference (establezca la propiedad Embe No se puede usar una expresión en este contexto porque puede exponer variables indirectamente fuera de su ámbito de declaración. - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - No se puede usar un elemento "{0}" local en este contexto porque puede exponer variables a las que se hace referencia fuera de su ámbito de declaración. - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope No se puede usar un resultado de "{0}" en este contexto porque puede exponer variables a las que el parámetro "{1}" hace referencia fuera de su ámbito de declaración. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 8203a9e2dbcbb..81488fe24cfc6 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -442,6 +442,11 @@ La propriété de contrat d'égalité d'enregistrement '{0}' doit avoir un accesseur get. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static L’implémentation explicite d’un opérateur « {0} » défini par l’utilisateur doit être déclarée comme static @@ -572,6 +577,11 @@ Un espace de noms de portée de fichier doit précéder tous les autres membres d’un fichier. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? L'instruction foreach ne peut pas fonctionner sur des variables de type '{0}', car '{0}' ne contient pas de définition d'extension ou d'instance publique pour '{1}'. Vouliez-vous dire 'await foreach' plutôt que 'foreach' ? @@ -11078,8 +11088,8 @@ Pour supprimer l'avertissement, vous pouvez utiliser la commande /reference (dé - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - Impossible de retourner un paramètre '{0}' par référence, car il ne s'agit pas d'un paramètre ref ou out + Cannot return a parameter by reference '{0}' because it is not a ref parameter + Impossible de retourner un paramètre '{0}' par référence, car il ne s'agit pas d'un paramètre ref ou out @@ -11107,11 +11117,6 @@ Pour supprimer l'avertissement, vous pouvez utiliser la commande /reference (dé Impossible d'utiliser l'expression dans ce contexte, car elle peut exposer indirectement des variables en dehors de la portée de leur déclaration - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - Impossible d'utiliser un '{0}' local dans ce contexte, car il peut exposer des variables référencées en dehors de la portée de leur déclaration - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope Impossible d'utiliser un résultat de '{0}' dans ce contexte, car il peut exposer les variables référencées par le paramètre '{1}' en dehors de la portée de leur déclaration diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index fe7b8612bbce9..a943416c0c63d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -442,6 +442,11 @@ La proprietà '{0}' del contratto di uguaglianza record deve contenere una funzione di accesso get. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static L'implementazione esplicita di un operatore definito dall'utente '{0}' deve essere dichiarata come statica @@ -572,6 +577,11 @@ Lo spazio dei nomi con ambito file deve precedere tutti gli altri membri di un file. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? L'istruzione foreach non può funzionare con variabili di tipo '{0}' perché '{0}' non contiene una definizione di istanza o estensione pubblica per '{1}'. Si intendeva 'await foreach' invece di 'foreach'? @@ -11078,8 +11088,8 @@ Per rimuovere l'avviso, è invece possibile usare /reference (impostare la propr - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - Non è possibile restituire un parametro '{0}' per riferimento perché non è un parametro out o ref + Cannot return a parameter by reference '{0}' because it is not a ref parameter + Non è possibile restituire un parametro '{0}' per riferimento perché non è un parametro out o ref @@ -11107,11 +11117,6 @@ Per rimuovere l'avviso, è invece possibile usare /reference (impostare la propr Non è possibile usare l'espressione in questo contesto perché potrebbe esporre indirettamente variabili all'esterno del relativo ambito di dichiarazione - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - Non è possibile usare la variabile locale '{0}' in questo contesto perché potrebbe esporre variabili di riferimento all'esterno del relativo ambito di dichiarazione - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope Non è possibile usare un risultato di '{0}' in questo contesto perché potrebbe esporre variabili cui viene fatto riferimento dal parametro '{1}' all'esterno dell'ambito della dichiarazione diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 59f715c469c97..977bb9889ddc0 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -442,6 +442,11 @@ レコードの等値コントラクト プロパティ '{0}' には get アクセサーが必要です。 + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static ユーザー定義演算子 '{0}' の明示的な実装は静的として宣言する必要があります @@ -572,6 +577,11 @@ ファイルスコープの名前空間は、ファイル内の他のすべてのメンバーの前に指定する必要があります。 + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? '{0}' は '{1}' のパブリック インスタンスまたは拡張機能の定義を含んでいないため、型 '{0}' の変数に対して foreach ステートメントを使用することはできません。'foreach' ではなく 'await foreach' ですか? @@ -11078,8 +11088,8 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - ref パラメーターでも out パラメーターでもないため、パラメーターを参照 '{0}' 渡しで返すことはできません + Cannot return a parameter by reference '{0}' because it is not a ref parameter + ref パラメーターでも out パラメーターでもないため、パラメーターを参照 '{0}' 渡しで返すことはできません @@ -11107,11 +11117,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ 間接的に変数が宣言のスコープ外に公開される可能性があるため、このコンテキストで式は使用できません - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - 参照される変数が宣言のスコープ外に公開される可能性があるため、このコンテキストでローカル '{0}' を使用することはできません - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope パラメーター '{1}' によって参照される変数が宣言のスコープ外に公開される可能性があるため、このコンテキストで '{0}' の結果を使用することはできません diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 96527da763187..ab6187325cf3e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -442,6 +442,11 @@ 레코드 같음 계약 속성 '{0}'에는 get 접근자가 있어야 합니다. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static 사용자 정의 연산자 '{0}'의 명시적 구현은 정적으로 선언되어야 합니다. @@ -572,6 +577,11 @@ 파일 범위 네임스페이스는 파일의 다른 모든 멤버보다 앞에 와야 합니다. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? '{0}' 형식 변수에서 foreach 문을 수행할 수 없습니다. '{0}'에는 '{1}'의 공개 인스턴스 또는 확장 정의가 없기 때문입니다. 'foreach' 대신 'await foreach'를 사용하시겠습니까? @@ -11077,8 +11087,8 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - '{0}' 매개 변수는 ref 또는 out 매개 변수가 아니므로 참조로 반환할 수 없습니다. + Cannot return a parameter by reference '{0}' because it is not a ref parameter + '{0}' 매개 변수는 ref 또는 out 매개 변수가 아니므로 참조로 반환할 수 없습니다. @@ -11106,11 +11116,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ 식은 선언 범위 외부의 변수를 간접적으로 노출할 수 있으므로 이 컨텍스트에서 사용할 수 없습니다. - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - 로컬 '{0}'은(는) 선언 범위 외부의 참조 변수를 노출할 수 있으므로 이 컨텍스트에서 사용할 수 없습니다. - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope '{0}'의 결과는 선언 범위 외부의 '{1}' 매개 변수에서 참조하는 변수를 노출할 수 있으므로 이 컨텍스트에서 사용할 수 없습니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 9cd0ea394a19d..9bd742d5de3b2 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -442,6 +442,11 @@ Właściwość kontraktu równości rekordu „{0}” musi mieć metodę dostępu get. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static Jawna implementacja operatora zdefiniowanego przez użytkownika „{0}” musi być zadeklarowana jako statyczna @@ -572,6 +577,11 @@ Przestrzeń nazw z określonym zakresem plików musi poprzedzać wszystkie inne składowe w pliku. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? Instrukcja foreach nie może operować na zmiennych typu „{0}”, ponieważ typ „{0}” nie zawiera publicznego wystąpienia lub definicji rozszerzenia dla elementu „{1}”. Czy planowano użyć instrukcji „await foreach”, a nie „foreach”? @@ -11078,8 +11088,8 @@ Aby usunąć ostrzeżenie, możesz zamiast tego użyć opcji /reference (ustaw w - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - Nie można zwrócić parametru „{0}” przez referencję, ponieważ to nie jest parametr ref ani out + Cannot return a parameter by reference '{0}' because it is not a ref parameter + Nie można zwrócić parametru „{0}” przez referencję, ponieważ to nie jest parametr ref ani out @@ -11107,11 +11117,6 @@ Aby usunąć ostrzeżenie, możesz zamiast tego użyć opcji /reference (ustaw w Nie można używać wyrażenia w tym kontekście, ponieważ pośrednio może ujawniać zmienne poza ich zakresem deklaracji - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - Nie można używać lokalnego elementu „{0}” w tym kontekście, ponieważ może uwidaczniać przywoływane zmienne poza ich zakresem deklaracji - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope Nie można używać wyniku elementu „{0}” w tym kontekście, ponieważ może uwidaczniać zmienne przywoływane przez parametr „{1}” poza ich zakresem deklaracji diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 7e3734ad42e33..a5d85fa3025c6 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -442,6 +442,11 @@ A propriedade de contrato de igualdade do registro '{0}' precisa ter um acessador get. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static A implementação explícita de um operador definido pelo usuário '{0}' deve ser declarada estática @@ -572,6 +577,11 @@ O namespace de escopo de arquivo deve preceder todos os outros membros em um arquivo. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? A instrução foreach não pode operar em variáveis do tipo '{0}' porque '{0}' não contém uma definição de extensão ou de instância pública para '{1}'. Você quis dizer 'await foreach' em vez de 'foreach'? @@ -11078,8 +11088,8 @@ Para incorporar informações de tipo de interoperabilidade para os dois assembl - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - Não é possível retornar um parâmetro por referência '{0}', pois ele não é um parâmetro ref ou out + Cannot return a parameter by reference '{0}' because it is not a ref parameter + Não é possível retornar um parâmetro por referência '{0}', pois ele não é um parâmetro ref ou out @@ -11107,11 +11117,6 @@ Para incorporar informações de tipo de interoperabilidade para os dois assembl A expressão não pode ser usada neste contexto porque ela pode expor indiretamente variáveis fora do seu escopo de declaração - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - Não é possível usar o local '{0}' nesse contexto porque ele pode expor variáveis referenciadas fora do seu escopo de declaração - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope Não é possível usar um resultado '{0}' nesse contexto porque ele pode expor as variáveis referenciadas pelo parâmetro '{1}' fora do seu escopo de declaração diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index eedc67f3dd9a0..e53070aeab1eb 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -442,6 +442,11 @@ Свойство контракта на равенство записей "{0}" должно иметь метод доступа get. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static Явная реализация определяемого пользователем оператора "{0}" должна быть объявлена статической @@ -572,6 +577,11 @@ Пространство имен с файловой областью должно быть раньше всех остальных элементов в файле. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? Оператор foreach не работает с переменными типа "{0}", так как "{0}" не содержит открытое определение экземпляра или расширения для "{1}" Возможно, вы имели в виду "await foreach", а не "foreach"? @@ -11078,8 +11088,8 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - Невозможно вернуть параметр "{0}" по ссылке, так как это не параметр ref или out + Cannot return a parameter by reference '{0}' because it is not a ref parameter + Невозможно вернуть параметр "{0}" по ссылке, так как это не параметр ref или out @@ -11107,11 +11117,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Выражение нельзя использовать в этом контексте, так как из-за этого переменные могут стать косвенно доступными за пределами их области объявления. - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - Локальный "{0}" нельзя использовать в этом контексте, так как из-за этого переменные, на которые имеются ссылки, могут стать доступными за пределами их области объявления. - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope Результат "{0}" нельзя использовать в этом контексте, так как из-за этого переменные, на которые ссылается параметр "{1}", могут стать доступными за пределами их области объявления. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index e907812e936fa..6ae8a0a03c89a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -442,6 +442,11 @@ '{0}' kayıt eşitlik anlaşması özelliğinin get erişimcisine sahip olması gerekir. + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static '{0}' kullanıcı tanımlı işlecinin açık uygulaması statik olarak bildirilmelidir @@ -572,6 +577,11 @@ Dosya kapsamlı ad alanı bir dosyadaki diğer tüm üyelerin önünde olmalıdır. + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? '{0}', '{1}' için bir genel örnek veya uzantı tanımı içermediğinden foreach deyimi '{0}' türündeki değişkenler üzerinde çalışamaz. 'foreach' yerine 'await foreach' mi kullanmak istediniz? @@ -11078,8 +11088,8 @@ Uyarıyı kaldırmak için, /reference kullanabilirsiniz (Birlikte Çalışma T - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - '{0}' parametresi bir ref veya out parametresi olmadığından başvuru ile döndürülemez + Cannot return a parameter by reference '{0}' because it is not a ref parameter + '{0}' parametresi bir ref veya out parametresi olmadığından başvuru ile döndürülemez @@ -11107,11 +11117,6 @@ Uyarıyı kaldırmak için, /reference kullanabilirsiniz (Birlikte Çalışma T İfade, değişkenleri kendi bildirim kapsamı dışında dolaylı olarak kullanıma sunabileceğinden bu bağlamda kullanılamaz - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - Yerel '{0}', başvurulan değişkenleri kendi bildirim kapsamı dışında kullanıma sunabileceğinden bu bağlamda kullanılamaz - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope '{0}' sonucu, '{1}' parametresi tarafından başvurulan değişkenleri kendi bildirim kapsamı dışında kullanıma sunabileceğinden bu bağlamda kullanılamaz diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index a2bc22943740e..13a2749e8cd04 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -442,6 +442,11 @@ 记录等同性合同属性“{0}”必须具有 get 访问器。 + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static 用户定义的运算符“{0}”的显式实现必须声明为静态 @@ -572,6 +577,11 @@ 文件范围内的命名空间必须位于文件中所有其他成员之前。 + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? “{0}”不包含“{1}”的公共实例或扩展定义,因此 foreach 语句不能作用于“{0}”类型的变量。是否希望使用 "await foreach" 而非 "foreach"? @@ -11083,8 +11093,8 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - 无法通过引用“{0}”返回参数,因为它不是 ref 或 out 参数 + Cannot return a parameter by reference '{0}' because it is not a ref parameter + 无法通过引用“{0}”返回参数,因为它不是 ref 或 out 参数 @@ -11112,11 +11122,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ 不能在此上下文中使用表达式,因为它可能在其声明范围以外间接地公开变量 - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - 不能在此上下文中使用本地“{0}”,因为它可能会在其声明范围以外公开引用的变量 - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope 不能在此上下文中使用“{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 3392696f9e333..016468e1d4b9f 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -442,6 +442,11 @@ 記錄相等 contract 屬性 '{0}' 必須要有 get 存取子。 + + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + Cannot use variable '{0}' in this context because it may expose referenced variables outside of their declaration scope + + Explicit implementation of a user-defined operator '{0}' must be declared static 使用者定義的運算子 '{0}' 的明確實作必須宣告為靜態 @@ -572,6 +577,11 @@ 以檔為範圍的命名空間必須在檔案中的所有其他成員之前。 + + A fixed field must not be a ref field. + A fixed field must not be a ref field. + + foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a public instance or extension definition for '{1}'. Did you mean 'await foreach' rather than 'foreach'? 因為 '{0}' 不包含 '{1}' 的公用執行個體或延伸模組定義,所以 foreach 陳述式無法在型別 '{0}' 的變數上運作。您指的是 'await foreach' 而不是 'foreach' 嗎? @@ -11078,8 +11088,8 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ - Cannot return a parameter by reference '{0}' because it is not a ref or out parameter - 無法藉傳址方式 '{0}' 傳回參數,因為其非 ref 或 out 參數 + Cannot return a parameter by reference '{0}' because it is not a ref parameter + 無法藉傳址方式 '{0}' 傳回參數,因為其非 ref 或 out 參數 @@ -11107,11 +11117,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ 無法在此內容中使用運算式,因為它會在其宣告範圍外間接公開變數 - - Cannot use local '{0}' in this context because it may expose referenced variables outside of their declaration scope - 無法在此內容中使用本機 '{0}',因為它會將參考的變數公開在其宣告範圍外 - - Cannot use a result of '{0}' in this context because it may expose variables referenced by parameter '{1}' outside of their declaration scope 無法在此內容中使用 '{0}' 的結果,因為它會將參數 '{1}' 參考的變數公開在其宣告範圍外 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index 687eb061c4816..47e24a34c1b00 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -11242,9 +11242,9 @@ static Span ptrTest2(Span s) // (10,16): error CS8347: Cannot use a result of 'delegate*, Span>' in this context because it may expose variables referenced by parameter '0' outside of their declaration scope // return ptr(s); Diagnostic(ErrorCode.ERR_EscapeCall, "ptr(s)").WithArguments("delegate*, System.Span>", "0").WithLocation(10, 16), - // (10,20): error CS8352: Cannot use local 's' in this context because it may expose referenced variables outside of their declaration scope + // (10,20): error CS8352: Cannot use variable 's' in this context because it may expose referenced variables outside of their declaration scope // return ptr(s); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s").WithArguments("s").WithLocation(10, 20) + Diagnostic(ErrorCode.ERR_EscapeVariable, "s").WithArguments("s").WithLocation(10, 20) ); } diff --git a/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_LifetimeAnnotation.cs b/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_LifetimeAnnotation.cs index d384f3d56739b..f151d5b930a3c 100644 --- a/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_LifetimeAnnotation.cs +++ b/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_LifetimeAnnotation.cs @@ -22,7 +22,7 @@ public class AttributeTests_LifetimeAnnotation : CSharpTestBase private const string LifetimeAnnotationAttributeDefinition = @"namespace System.Runtime.CompilerServices { - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)] public sealed class LifetimeAnnotationAttribute : Attribute { public LifetimeAnnotationAttribute(bool isRefScoped, bool isValueScoped) @@ -104,20 +104,53 @@ public static void F(scoped ref int i) { } Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "scoped ref int i").WithArguments("System.Runtime.CompilerServices.LifetimeAnnotationAttribute", ".ctor").WithLocation(3, 26)); } + [WorkItem(62124, "https://github.com/dotnet/roslyn/issues/62124")] [Fact] - public void ExplicitAttribute_ReferencedInSource() + public void ExplicitAttribute_ReferencedInSource_01() { var source = @"using System.Runtime.CompilerServices; +delegate void D([LifetimeAnnotation(true, false)] ref int i); class Program { - public static void Main([LifetimeAnnotation(false, true)] string[] args) { } + public static void Main([LifetimeAnnotation(false, true)] string[] args) + { + D d = ([LifetimeAnnotation(true, false)] ref int i) => { }; + } }"; var comp = CreateCompilation(new[] { LifetimeAnnotationAttributeDefinition, source }); - // PROTOTYPE: Should report ErrorCode.ERR_ExplicitReservedAttr. + // https://github.com/dotnet/roslyn/issues/62124: Re-enable check for LifetimeAnnotationAttribute in ReportExplicitUseOfReservedAttributes. comp.VerifyDiagnostics(); } + [WorkItem(62124, "https://github.com/dotnet/roslyn/issues/62124")] + [Fact] + public void ExplicitAttribute_ReferencedInSource_02() + { + var source = +@"using System; +using System.Runtime.CompilerServices; +[module: LifetimeAnnotation(false, true)] +[LifetimeAnnotation(false, true)] class Program +{ + [LifetimeAnnotation(false, true)] object F; + [LifetimeAnnotation(false, true)] event EventHandler E; + [LifetimeAnnotation(false, true)] object P { get; } + [LifetimeAnnotation(false, true)] static object M1() => throw null; + [return: LifetimeAnnotation(false, true)] static object M2() => throw null; + static void M3<[LifetimeAnnotation(false, true)] T>() { } +}"; + var comp = CreateCompilation(new[] { LifetimeAnnotationAttributeDefinition, source }); + // https://github.com/dotnet/roslyn/issues/62124: Re-enable check for LifetimeAnnotationAttribute in ReportExplicitUseOfReservedAttributes. + comp.VerifyDiagnostics( + // (6,46): warning CS0169: The field 'Program.F' is never used + // [LifetimeAnnotation(false, true)] object F; + Diagnostic(ErrorCode.WRN_UnreferencedField, "F").WithArguments("Program.F").WithLocation(6, 46), + // (7,58): warning CS0067: The event 'Program.E' is never used + // [LifetimeAnnotation(false, true)] event EventHandler E; + Diagnostic(ErrorCode.WRN_UnreferencedEvent, "E").WithArguments("Program.E").WithLocation(7, 58)); + } + [Fact] public void ExplicitAttribute_UnexpectedParameterTargets() { @@ -236,8 +269,8 @@ static void Main() } }"; var comp = CreateCompilation(source1, references: new[] { ref0 }); - // PROTOTYPE: Should we treat methods as not supported if a parameter has - // a [LifetimeAnnotation] attribute that uses an unrecognized constructor? + // https://github.com/dotnet/roslyn/issues/61647: If the [LifetimeAnnotation] scoped value is an int + // rather than a pair of bools, the compiler should reject attribute values that it does not recognize. comp.VerifyDiagnostics(); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs index b97739e94de5e..084c9b0f393d9 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DelegateTypeTests.cs @@ -6463,22 +6463,22 @@ static void Main() // (10,13): error CS8773: Feature 'lambda return type' is not available in C# 9.0. Please use language version 10.0 or greater. // F1((ref int (i) => ref i)); Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "ref int").WithArguments("lambda return type", "10.0").WithLocation(10, 13), - // (10,32): error CS8166: Cannot return a parameter by reference 'i' because it is not a ref or out parameter + // (10,32): error CS8166: Cannot return a parameter by reference 'i' because it is not a ref parameter // F1((ref int (i) => ref i)); Diagnostic(ErrorCode.ERR_RefReturnParameter, "i").WithArguments("i").WithLocation(10, 32), // (11,13): error CS8773: Feature 'lambda return type' is not available in C# 9.0. Please use language version 10.0 or greater. // F2((ref readonly string (s) => ref s)); Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "ref readonly string").WithArguments("lambda return type", "10.0").WithLocation(11, 13), - // (11,44): error CS8166: Cannot return a parameter by reference 's' because it is not a ref or out parameter + // (11,44): error CS8166: Cannot return a parameter by reference 's' because it is not a ref parameter // F2((ref readonly string (s) => ref s)); Diagnostic(ErrorCode.ERR_RefReturnParameter, "s").WithArguments("s").WithLocation(11, 44)); var expectedDiagnostics = new[] { - // (10,32): error CS8166: Cannot return a parameter by reference 'i' because it is not a ref or out parameter + // (10,32): error CS8166: Cannot return a parameter by reference 'i' because it is not a ref parameter // F1((ref int (i) => ref i)); Diagnostic(ErrorCode.ERR_RefReturnParameter, "i").WithArguments("i").WithLocation(10, 32), - // (11,44): error CS8166: Cannot return a parameter by reference 's' because it is not a ref or out parameter + // (11,44): error CS8166: Cannot return a parameter by reference 's' because it is not a ref parameter // F2((ref readonly string (s) => ref s)); Diagnostic(ErrorCode.ERR_RefReturnParameter, "s").WithArguments("s").WithLocation(11, 44) }; diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/IndexAndRangeTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/IndexAndRangeTests.cs index beff43c54a991..601d65cdb6434 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/IndexAndRangeTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/IndexAndRangeTests.cs @@ -284,9 +284,9 @@ Span M() }"; var comp = CreateCompilationWithIndexAndRangeAndSpan(src); comp.VerifyDiagnostics( - // (9,16): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (9,16): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // return s2; - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(9, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(9, 16)); } [Fact] @@ -1908,78 +1908,78 @@ Range Test11() // (28,16): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return new Index(s1)..; Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s1)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(28, 16), - // (28,26): error CS8352: Cannot use local 's1' in this context because it may expose referenced variables outside of their declaration scope + // (28,26): error CS8352: Cannot use variable 's1' in this context because it may expose referenced variables outside of their declaration scope // return new Index(s1)..; - Diagnostic(ErrorCode.ERR_EscapeLocal, "s1").WithArguments("s1").WithLocation(28, 26), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s1").WithArguments("s1").WithLocation(28, 26), // (34,16): error CS8347: Cannot use a result of 'Range.StartAt(Index)' in this context because it may expose variables referenced by parameter 'start' outside of their declaration scope // return Range.StartAt(new Index(s2)); Diagnostic(ErrorCode.ERR_EscapeCall, "Range.StartAt(new Index(s2))").WithArguments("System.Range.StartAt(System.Index)", "start").WithLocation(34, 16), // (34,30): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return Range.StartAt(new Index(s2)); Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s2)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(34, 30), - // (34,40): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (34,40): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // return Range.StartAt(new Index(s2)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(34, 40), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(34, 40), // (40,18): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return ..new Index(s3); Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s3)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(40, 18), - // (40,28): error CS8352: Cannot use local 's3' in this context because it may expose referenced variables outside of their declaration scope + // (40,28): error CS8352: Cannot use variable 's3' in this context because it may expose referenced variables outside of their declaration scope // return ..new Index(s3); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s3").WithArguments("s3").WithLocation(40, 28), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s3").WithArguments("s3").WithLocation(40, 28), // (46,16): error CS8347: Cannot use a result of 'Range.EndAt(Index)' in this context because it may expose variables referenced by parameter 'end' outside of their declaration scope // return Range.EndAt(new Index(s4)); Diagnostic(ErrorCode.ERR_EscapeCall, "Range.EndAt(new Index(s4))").WithArguments("System.Range.EndAt(System.Index)", "end").WithLocation(46, 16), // (46,28): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return Range.EndAt(new Index(s4)); Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s4)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(46, 28), - // (46,38): error CS8352: Cannot use local 's4' in this context because it may expose referenced variables outside of their declaration scope + // (46,38): error CS8352: Cannot use variable 's4' in this context because it may expose referenced variables outside of their declaration scope // return Range.EndAt(new Index(s4)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s4").WithArguments("s4").WithLocation(46, 38), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s4").WithArguments("s4").WithLocation(46, 38), // (52,34): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return new Index(s51) .. new Index(s52); Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s52)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(52, 34), - // (52,44): error CS8352: Cannot use local 's52' in this context because it may expose referenced variables outside of their declaration scope + // (52,44): error CS8352: Cannot use variable 's52' in this context because it may expose referenced variables outside of their declaration scope // return new Index(s51) .. new Index(s52); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s52").WithArguments("s52").WithLocation(52, 44), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s52").WithArguments("s52").WithLocation(52, 44), // (58,16): error CS8347: Cannot use a result of 'Range.Range(Index, Index)' in this context because it may expose variables referenced by parameter 'end' outside of their declaration scope // return new Range(new Index(s61), new Index(s62)); Diagnostic(ErrorCode.ERR_EscapeCall, "new Range(new Index(s61), new Index(s62))").WithArguments("System.Range.Range(System.Index, System.Index)", "end").WithLocation(58, 16), // (58,42): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return new Range(new Index(s61), new Index(s62)); Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s62)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(58, 42), - // (58,52): error CS8352: Cannot use local 's62' in this context because it may expose referenced variables outside of their declaration scope + // (58,52): error CS8352: Cannot use variable 's62' in this context because it may expose referenced variables outside of their declaration scope // return new Range(new Index(s61), new Index(s62)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s62").WithArguments("s62").WithLocation(58, 52), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s62").WithArguments("s62").WithLocation(58, 52), // (64,16): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return new Index(s71) .. new Index(s72); Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s71)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(64, 16), - // (64,26): error CS8352: Cannot use local 's71' in this context because it may expose referenced variables outside of their declaration scope + // (64,26): error CS8352: Cannot use variable 's71' in this context because it may expose referenced variables outside of their declaration scope // return new Index(s71) .. new Index(s72); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s71").WithArguments("s71").WithLocation(64, 26), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s71").WithArguments("s71").WithLocation(64, 26), // (70,16): error CS8347: Cannot use a result of 'Range.Range(Index, Index)' in this context because it may expose variables referenced by parameter 'start' outside of their declaration scope // return new Range(new Index(s81), new Index(s82)); Diagnostic(ErrorCode.ERR_EscapeCall, "new Range(new Index(s81), new Index(s82))").WithArguments("System.Range.Range(System.Index, System.Index)", "start").WithLocation(70, 16), // (70,26): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return new Range(new Index(s81), new Index(s82)); Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s81)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(70, 26), - // (70,36): error CS8352: Cannot use local 's81' in this context because it may expose referenced variables outside of their declaration scope + // (70,36): error CS8352: Cannot use variable 's81' in this context because it may expose referenced variables outside of their declaration scope // return new Range(new Index(s81), new Index(s82)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s81").WithArguments("s81").WithLocation(70, 36), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s81").WithArguments("s81").WithLocation(70, 36), // (77,16): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return new Index(s91) .. new Index(s92); Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s91)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(77, 16), - // (77,26): error CS8352: Cannot use local 's91' in this context because it may expose referenced variables outside of their declaration scope + // (77,26): error CS8352: Cannot use variable 's91' in this context because it may expose referenced variables outside of their declaration scope // return new Index(s91) .. new Index(s92); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s91").WithArguments("s91").WithLocation(77, 26), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s91").WithArguments("s91").WithLocation(77, 26), // (84,16): error CS8347: Cannot use a result of 'Range.Range(Index, Index)' in this context because it may expose variables referenced by parameter 'start' outside of their declaration scope // return new Range(new Index(s101), new Index(s102)); Diagnostic(ErrorCode.ERR_EscapeCall, "new Range(new Index(s101), new Index(s102))").WithArguments("System.Range.Range(System.Index, System.Index)", "start").WithLocation(84, 16), // (84,26): error CS8347: Cannot use a result of 'Index.Index(Span)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return new Range(new Index(s101), new Index(s102)); Diagnostic(ErrorCode.ERR_EscapeCall, "new Index(s101)").WithArguments("System.Index.Index(System.Span)", "x").WithLocation(84, 26), - // (84,36): error CS8352: Cannot use local 's101' in this context because it may expose referenced variables outside of their declaration scope + // (84,36): error CS8352: Cannot use variable 's101' in this context because it may expose referenced variables outside of their declaration scope // return new Range(new Index(s101), new Index(s102)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s101").WithArguments("s101").WithLocation(84, 36) + Diagnostic(ErrorCode.ERR_EscapeVariable, "s101").WithArguments("s101").WithLocation(84, 36) ); } @@ -2091,36 +2091,36 @@ Range Test11() "; var comp = CreateCompilationWithSpan(src); comp.VerifyDiagnostics( - // (29,16): error CS8352: Cannot use local 'r1' in this context because it may expose referenced variables outside of their declaration scope + // (29,16): error CS8352: Cannot use variable 'r1' in this context because it may expose referenced variables outside of their declaration scope // return r1; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1").WithArguments("r1").WithLocation(29, 16), - // (36,16): error CS8352: Cannot use local 'r2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1").WithArguments("r1").WithLocation(29, 16), + // (36,16): error CS8352: Cannot use variable 'r2' in this context because it may expose referenced variables outside of their declaration scope // return r2; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r2").WithArguments("r2").WithLocation(36, 16), - // (43,16): error CS8352: Cannot use local 'r3' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r2").WithArguments("r2").WithLocation(36, 16), + // (43,16): error CS8352: Cannot use variable 'r3' in this context because it may expose referenced variables outside of their declaration scope // return r3; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r3").WithArguments("r3").WithLocation(43, 16), - // (50,16): error CS8352: Cannot use local 'r4' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r3").WithArguments("r3").WithLocation(43, 16), + // (50,16): error CS8352: Cannot use variable 'r4' in this context because it may expose referenced variables outside of their declaration scope // return r4; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r4").WithArguments("r4").WithLocation(50, 16), - // (57,16): error CS8352: Cannot use local 'r5' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r4").WithArguments("r4").WithLocation(50, 16), + // (57,16): error CS8352: Cannot use variable 'r5' in this context because it may expose referenced variables outside of their declaration scope // return r5; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r5").WithArguments("r5").WithLocation(57, 16), - // (64,16): error CS8352: Cannot use local 'r6' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r5").WithArguments("r5").WithLocation(57, 16), + // (64,16): error CS8352: Cannot use variable 'r6' in this context because it may expose referenced variables outside of their declaration scope // return r6; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r6").WithArguments("r6").WithLocation(64, 16), - // (71,16): error CS8352: Cannot use local 'r7' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r6").WithArguments("r6").WithLocation(64, 16), + // (71,16): error CS8352: Cannot use variable 'r7' in this context because it may expose referenced variables outside of their declaration scope // return r7; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r7").WithArguments("r7").WithLocation(71, 16), - // (78,16): error CS8352: Cannot use local 'r8' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r7").WithArguments("r7").WithLocation(71, 16), + // (78,16): error CS8352: Cannot use variable 'r8' in this context because it may expose referenced variables outside of their declaration scope // return r8; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r8").WithArguments("r8").WithLocation(78, 16), - // (86,16): error CS8352: Cannot use local 'r9' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r8").WithArguments("r8").WithLocation(78, 16), + // (86,16): error CS8352: Cannot use variable 'r9' in this context because it may expose referenced variables outside of their declaration scope // return r9; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r9").WithArguments("r9").WithLocation(86, 16), - // (94,16): error CS8352: Cannot use local 'r10' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r9").WithArguments("r9").WithLocation(86, 16), + // (94,16): error CS8352: Cannot use variable 'r10' in this context because it may expose referenced variables outside of their declaration scope // return r10; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r10").WithArguments("r10").WithLocation(94, 16) + Diagnostic(ErrorCode.ERR_EscapeVariable, "r10").WithArguments("r10").WithLocation(94, 16) ); } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index 4c4f9c83b7821..d6b0e44b41a4f 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -13450,9 +13450,9 @@ public static CustomHandler M() var comp = CreateCompilation(new[] { code, InterpolatedStringHandlerAttribute }, targetFramework: TargetFramework.NetCoreApp); comp.VerifyDiagnostics( - // (17,19): error CS8352: Cannot use local 's' in this context because it may expose referenced variables outside of their declaration scope + // (17,19): error CS8352: Cannot use variable 's' in this context because it may expose referenced variables outside of their declaration scope // return $"{s}"; - Diagnostic(ErrorCode.ERR_EscapeLocal, "s").WithArguments("s").WithLocation(17, 19) + Diagnostic(ErrorCode.ERR_EscapeVariable, "s").WithArguments("s").WithLocation(17, 19) ); } @@ -13562,9 +13562,9 @@ public ref struct S1 // (17,9): error CS8350: This combination of arguments to 'CustomHandler.M2(ref S1, ref CustomHandler)' is disallowed because it may expose variables referenced by parameter 'handler' outside of their declaration scope // M2(ref s1, $"{s}"); Diagnostic(ErrorCode.ERR_CallArgMixing, @"M2(ref s1, " + expression + @")").WithArguments("CustomHandler.M2(ref S1, ref CustomHandler)", "handler").WithLocation(17, 9), - // (17,23): error CS8352: Cannot use local 's' in this context because it may expose referenced variables outside of their declaration scope + // (17,23): error CS8352: Cannot use variable 's' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s1, $"{s}"); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s").WithArguments("s").WithLocation(17, 23) + Diagnostic(ErrorCode.ERR_EscapeVariable, "s").WithArguments("s").WithLocation(17, 23) ); comp = CreateCompilation(new[] { code, InterpolatedStringHandlerAttribute, InterpolatedStringHandlerArgumentAttribute }, targetFramework: TargetFramework.NetCoreApp); @@ -13578,9 +13578,9 @@ public ref struct S1 // (17,20): error CS8347: Cannot use a result of 'CustomHandler.CustomHandler(int, int, ref S1)' in this context because it may expose variables referenced by parameter 's1' outside of their declaration scope // M2(ref s1, $"{s}"); Diagnostic(ErrorCode.ERR_EscapeCall, expression).WithArguments("CustomHandler.CustomHandler(int, int, ref S1)", "s1").WithLocation(17, 20), - // (17,23): error CS8352: Cannot use local 's' in this context because it may expose referenced variables outside of their declaration scope + // (17,23): error CS8352: Cannot use variable 's' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s1, $"{s}"); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s").WithArguments("s").WithLocation(17, 23) + Diagnostic(ErrorCode.ERR_EscapeVariable, "s").WithArguments("s").WithLocation(17, 23) ); } @@ -13713,9 +13713,9 @@ public static ref CustomHandler M2(ref Span s, [InterpolatedStringHandlerA var comp = CreateCompilation(new[] { code, InterpolatedStringHandlerAttribute, InterpolatedStringHandlerArgumentAttribute }, targetFramework: TargetFramework.NetCoreApp); comp.VerifyDiagnostics( - // (16,16): error CS8352: Cannot use local 'c' in this context because it may expose referenced variables outside of their declaration scope + // (16,16): error CS8352: Cannot use variable 'c' in this context because it may expose referenced variables outside of their declaration scope // return c; - Diagnostic(ErrorCode.ERR_EscapeLocal, "c").WithArguments("c").WithLocation(16, 16) + Diagnostic(ErrorCode.ERR_EscapeVariable, "c").WithArguments("c").WithLocation(16, 16) ); } @@ -13755,9 +13755,9 @@ public ref struct S1 // (15,9): error CS8350: This combination of arguments to 'CustomHandler.M2(ref S1, CustomHandler)' is disallowed because it may expose variables referenced by parameter 'handler' outside of their declaration scope // M2(ref s1, $"{s2}"); Diagnostic(ErrorCode.ERR_CallArgMixing, @"M2(ref s1, $""{s2}"")").WithArguments("CustomHandler.M2(ref S1, CustomHandler)", "handler").WithLocation(15, 9), - // (15,23): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (15,23): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s1, $"{s2}"); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(15, 23) + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(15, 23) ); comp = CreateCompilation(new[] { code, InterpolatedStringHandlerAttribute, InterpolatedStringHandlerArgumentAttribute }, targetFramework: TargetFramework.NetCoreApp); @@ -13771,9 +13771,9 @@ public ref struct S1 // (15,20): error CS8347: Cannot use a result of 'CustomHandler.CustomHandler(int, int, ref S1)' in this context because it may expose variables referenced by parameter 's1' outside of their declaration scope // M2(ref s1, $"{s2}"); Diagnostic(ErrorCode.ERR_EscapeCall, @"$""{s2}""").WithArguments("CustomHandler.CustomHandler(int, int, ref S1)", "s1").WithLocation(15, 20), - // (15,23): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (15,23): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s1, $"{s2}"); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(15, 23) + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(15, 23) ); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs index 13c0bf491a890..3d2966a9aacc0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs @@ -154,97 +154,96 @@ void M() }"); comp.VerifyDiagnostics( - // (16,18): error CS1660: Cannot convert lambda expression to type 'int' because it is not a delegate type - // int q1 = ()=>1; - Diagnostic(ErrorCode.ERR_AnonMethToNonDel, "()=>1").WithArguments("lambda expression", "int").WithLocation(16, 18), - // (17,18): error CS1660: Cannot convert anonymous method to type 'int' because it is not a delegate type - // int q2 = delegate { return 1; }; - Diagnostic(ErrorCode.ERR_AnonMethToNonDel, "delegate { return 1; }").WithArguments("anonymous method", "int").WithLocation(17, 18), - // (18,24): error CS1593: Delegate 'Func' does not take 1 arguments - // Func q3 = x3=>1; - Diagnostic(ErrorCode.ERR_BadDelArgCount, "x3=>1").WithArguments("System.Func", "1").WithLocation(18, 24), - // (19,37): error CS0234: The type or namespace name 'Itn23' does not exist in the namespace 'System' (are you missing an assembly reference?) - // Func q4 = (System.Itn23 x4)=>1; // type mismatch error should be suppressed on error type - Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "Itn23").WithArguments("Itn23", "System").WithLocation(19, 37), - // (20,35): error CS0234: The type or namespace name 'Duobel' does not exist in the namespace 'System' (are you missing an assembly reference?) - // Func q5 = (System.Duobel x5)=>1; // but arity error should not be suppressed on error type - Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "Duobel").WithArguments("Duobel", "System").WithLocation(20, 35), - // (20,27): error CS1593: Delegate 'Func' does not take 1 arguments - // Func q5 = (System.Duobel x5)=>1; // but arity error should not be suppressed on error type - Diagnostic(ErrorCode.ERR_BadDelArgCount, "(System.Duobel x5)=>1").WithArguments("System.Func", "1").WithLocation(20, 27), - // (21,17): error CS1661: Cannot convert lambda expression to delegate type 'C.D1' because the parameter types do not match the delegate parameter types - // D1 q6 = (double x6, ref int y6, ref int z6)=>1; - Diagnostic(ErrorCode.ERR_CantConvAnonMethParams, "(double x6, ref int y6, ref int z6)=>1").WithArguments("lambda expression", "C.D1").WithLocation(21, 17), - // (21,25): error CS1678: Parameter 1 is declared as type 'double' but should be 'ref int' - // D1 q6 = (double x6, ref int y6, ref int z6)=>1; - Diagnostic(ErrorCode.ERR_BadParamType, "x6").WithArguments("1", "", "double", "ref ", "int").WithLocation(21, 25), - // (21,37): error CS1676: Parameter 2 must be declared with the 'out' keyword - // D1 q6 = (double x6, ref int y6, ref int z6)=>1; - Diagnostic(ErrorCode.ERR_BadParamRef, "y6").WithArguments("2", "out").WithLocation(21, 37), - // (21,49): error CS1677: Parameter 3 should not be declared with the 'ref' keyword - // D1 q6 = (double x6, ref int y6, ref int z6)=>1; - Diagnostic(ErrorCode.ERR_BadParamExtraRef, "z6").WithArguments("3", "ref").WithLocation(21, 49), - // (32,17): error CS1688: Cannot convert anonymous method block without a parameter list to delegate type 'C.D1' because it has one or more out parameters - // D1 q7 = delegate {}; - Diagnostic(ErrorCode.ERR_CantConvAnonMethNoParams, "delegate {}").WithArguments("C.D1").WithLocation(32, 17), - // (34,9): error CS0246: The type or namespace name 'Frob' could not be found (are you missing a using directive or an assembly reference?) - // Frob q8 = ()=>{}; - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Frob").WithArguments("Frob").WithLocation(34, 9), - // (36,17): error CS1676: Parameter 1 must be declared with the 'out' keyword - // D2 q9 = x9=>{}; - Diagnostic(ErrorCode.ERR_BadParamRef, "x9").WithArguments("1", "out").WithLocation(36, 17), - // (38,19): error CS1676: Parameter 1 must be declared with the 'ref' keyword - // D1 q10 = (x10,y10,z10)=>{}; - Diagnostic(ErrorCode.ERR_BadParamRef, "x10").WithArguments("1", "ref").WithLocation(38, 19), - // (38,23): error CS1676: Parameter 2 must be declared with the 'out' keyword - // D1 q10 = (x10,y10,z10)=>{}; - Diagnostic(ErrorCode.ERR_BadParamRef, "y10").WithArguments("2", "out").WithLocation(38, 23), - // (52,28): error CS8030: Anonymous function converted to a void returning delegate cannot return a value - // Action q11 = ()=>{ return 1; }; - Diagnostic(ErrorCode.ERR_RetNoObjectRequiredLambda, "return").WithLocation(52, 28), - // (54,26): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement - // Action q12 = ()=>1; - Diagnostic(ErrorCode.ERR_IllegalStatement, "1").WithLocation(54, 26), - // (56,42): warning CS0162: Unreachable code detected - // Func q13 = ()=>{ if (false) return 1; }; - Diagnostic(ErrorCode.WRN_UnreachableCode, "return").WithLocation(56, 42), - // (56,27): error CS1643: Not all code paths return a value in lambda expression of type 'Func' - // Func q13 = ()=>{ if (false) return 1; }; - Diagnostic(ErrorCode.ERR_AnonymousReturnExpected, "=>").WithArguments("lambda expression", "System.Func").WithLocation(56, 27), - // (58,29): error CS0266: Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?) - // Func q14 = ()=>123.456; - Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "123.456").WithArguments("double", "int").WithLocation(58, 29), - // (58,29): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type - // Func q14 = ()=>123.456; - Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "123.456").WithArguments("lambda expression").WithLocation(58, 29), - // (62,51): error CS0266: Cannot implicitly convert type 'decimal' to 'double'. An explicit conversion exists (are you missing a cast?) - // Func q15 = ()=>{if (false) return 1m; else return 0; }; - Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "1m").WithArguments("decimal", "double").WithLocation(62, 51), - // (62,51): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type - // Func q15 = ()=>{if (false) return 1m; else return 0; }; - Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "1m").WithArguments("lambda expression").WithLocation(62, 51), - // (62,44): warning CS0162: Unreachable code detected - // Func q15 = ()=>{if (false) return 1m; else return 0; }; - Diagnostic(ErrorCode.WRN_UnreachableCode, "return").WithLocation(62, 44), - // (66,39): error CS1670: params is not valid in this context - // Action q16 = delegate (params int[] p) { }; - Diagnostic(ErrorCode.ERR_IllegalParams, "params int[] p").WithLocation(66, 39), - // (67,33): error CS1670: params is not valid in this context - // Action q17 = (params string[] s)=>{}; - Diagnostic(ErrorCode.ERR_IllegalParams, "params string[] s").WithLocation(67, 33), - // (68,45): error CS1670: params is not valid in this context - // Action q18 = (int x, params double[] s)=>{}; - Diagnostic(ErrorCode.ERR_IllegalParams, "params double[] s").WithLocation(68, 45), - // (70,34): error CS1593: Delegate 'Action' does not take 1 arguments - // object q19 = new Action( (int x)=>{} ); - Diagnostic(ErrorCode.ERR_BadDelArgCount, "(int x)=>{}").WithArguments("System.Action", "1").WithLocation(70, 34), - // (72,9): warning CS0436: The type 'Expression' in '' conflicts with the imported type 'Expression' in 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using the type defined in ''. - // Expression ex1 = ()=>1; - Diagnostic(ErrorCode.WRN_SameFullNameThisAggAgg, "Expression").WithArguments("", "System.Linq.Expressions.Expression", "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Linq.Expressions.Expression").WithLocation(72, 9), - // (72,31): error CS0835: Cannot convert lambda to an expression tree whose type argument 'int' is not a delegate type - // Expression ex1 = ()=>1; - Diagnostic(ErrorCode.ERR_ExpressionTreeMustHaveDelegate, "()=>1").WithArguments("int").WithLocation(72, 31) - ); + // (16,18): error CS1660: Cannot convert lambda expression to type 'int' because it is not a delegate type + // int q1 = ()=>1; + Diagnostic(ErrorCode.ERR_AnonMethToNonDel, "()=>1").WithArguments("lambda expression", "int").WithLocation(16, 18), + // (17,18): error CS1660: Cannot convert anonymous method to type 'int' because it is not a delegate type + // int q2 = delegate { return 1; }; + Diagnostic(ErrorCode.ERR_AnonMethToNonDel, "delegate { return 1; }").WithArguments("anonymous method", "int").WithLocation(17, 18), + // (18,24): error CS1593: Delegate 'Func' does not take 1 arguments + // Func q3 = x3=>1; + Diagnostic(ErrorCode.ERR_BadDelArgCount, "x3=>1").WithArguments("System.Func", "1").WithLocation(18, 24), + // (19,37): error CS0234: The type or namespace name 'Itn23' does not exist in the namespace 'System' (are you missing an assembly reference?) + // Func q4 = (System.Itn23 x4)=>1; // type mismatch error should be suppressed on error type + Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "Itn23").WithArguments("Itn23", "System").WithLocation(19, 37), + // (20,35): error CS0234: The type or namespace name 'Duobel' does not exist in the namespace 'System' (are you missing an assembly reference?) + // Func q5 = (System.Duobel x5)=>1; // but arity error should not be suppressed on error type + Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "Duobel").WithArguments("Duobel", "System").WithLocation(20, 35), + // (20,27): error CS1593: Delegate 'Func' does not take 1 arguments + // Func q5 = (System.Duobel x5)=>1; // but arity error should not be suppressed on error type + Diagnostic(ErrorCode.ERR_BadDelArgCount, "(System.Duobel x5)=>1").WithArguments("System.Func", "1").WithLocation(20, 27), + // (21,17): error CS1661: Cannot convert lambda expression to type 'C.D1' because the parameter types do not match the delegate parameter types + // D1 q6 = (double x6, ref int y6, ref int z6)=>1; + Diagnostic(ErrorCode.ERR_CantConvAnonMethParams, "(double x6, ref int y6, ref int z6)=>1").WithArguments("lambda expression", "C.D1").WithLocation(21, 17), + // (21,25): error CS1678: Parameter 1 is declared as type 'double' but should be 'ref int' + // D1 q6 = (double x6, ref int y6, ref int z6)=>1; + Diagnostic(ErrorCode.ERR_BadParamType, "x6").WithArguments("1", "", "double", "ref ", "int").WithLocation(21, 25), + // (21,37): error CS1676: Parameter 2 must be declared with the 'out' keyword + // D1 q6 = (double x6, ref int y6, ref int z6)=>1; + Diagnostic(ErrorCode.ERR_BadParamRef, "y6").WithArguments("2", "out").WithLocation(21, 37), + // (21,49): error CS1677: Parameter 3 should not be declared with the 'ref' keyword + // D1 q6 = (double x6, ref int y6, ref int z6)=>1; + Diagnostic(ErrorCode.ERR_BadParamExtraRef, "z6").WithArguments("3", "ref").WithLocation(21, 49), + // (32,17): error CS1688: Cannot convert anonymous method block without a parameter list to delegate type 'C.D1' because it has one or more out parameters + // D1 q7 = delegate {}; + Diagnostic(ErrorCode.ERR_CantConvAnonMethNoParams, "delegate {}").WithArguments("C.D1").WithLocation(32, 17), + // (34,9): error CS0246: The type or namespace name 'Frob' could not be found (are you missing a using directive or an assembly reference?) + // Frob q8 = ()=>{}; + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Frob").WithArguments("Frob").WithLocation(34, 9), + // (36,17): error CS1676: Parameter 1 must be declared with the 'out' keyword + // D2 q9 = x9=>{}; + Diagnostic(ErrorCode.ERR_BadParamRef, "x9").WithArguments("1", "out").WithLocation(36, 17), + // (38,19): error CS1676: Parameter 1 must be declared with the 'ref' keyword + // D1 q10 = (x10,y10,z10)=>{}; + Diagnostic(ErrorCode.ERR_BadParamRef, "x10").WithArguments("1", "ref").WithLocation(38, 19), + // (38,23): error CS1676: Parameter 2 must be declared with the 'out' keyword + // D1 q10 = (x10,y10,z10)=>{}; + Diagnostic(ErrorCode.ERR_BadParamRef, "y10").WithArguments("2", "out").WithLocation(38, 23), + // (52,28): error CS8030: Anonymous function converted to a void returning delegate cannot return a value + // Action q11 = ()=>{ return 1; }; + Diagnostic(ErrorCode.ERR_RetNoObjectRequiredLambda, "return").WithLocation(52, 28), + // (54,26): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement + // Action q12 = ()=>1; + Diagnostic(ErrorCode.ERR_IllegalStatement, "1").WithLocation(54, 26), + // (56,42): warning CS0162: Unreachable code detected + // Func q13 = ()=>{ if (false) return 1; }; + Diagnostic(ErrorCode.WRN_UnreachableCode, "return").WithLocation(56, 42), + // (56,27): error CS1643: Not all code paths return a value in lambda expression of type 'Func' + // Func q13 = ()=>{ if (false) return 1; }; + Diagnostic(ErrorCode.ERR_AnonymousReturnExpected, "=>").WithArguments("lambda expression", "System.Func").WithLocation(56, 27), + // (58,29): error CS0266: Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?) + // Func q14 = ()=>123.456; + Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "123.456").WithArguments("double", "int").WithLocation(58, 29), + // (58,29): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type + // Func q14 = ()=>123.456; + Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "123.456").WithArguments("lambda expression").WithLocation(58, 29), + // (62,51): error CS0266: Cannot implicitly convert type 'decimal' to 'double'. An explicit conversion exists (are you missing a cast?) + // Func q15 = ()=>{if (false) return 1m; else return 0; }; + Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "1m").WithArguments("decimal", "double").WithLocation(62, 51), + // (62,51): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type + // Func q15 = ()=>{if (false) return 1m; else return 0; }; + Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "1m").WithArguments("lambda expression").WithLocation(62, 51), + // (62,44): warning CS0162: Unreachable code detected + // Func q15 = ()=>{if (false) return 1m; else return 0; }; + Diagnostic(ErrorCode.WRN_UnreachableCode, "return").WithLocation(62, 44), + // (66,39): error CS1670: params is not valid in this context + // Action q16 = delegate (params int[] p) { }; + Diagnostic(ErrorCode.ERR_IllegalParams, "params").WithLocation(66, 39), + // (67,33): error CS1670: params is not valid in this context + // Action q17 = (params string[] s)=>{}; + Diagnostic(ErrorCode.ERR_IllegalParams, "params").WithLocation(67, 33), + // (68,45): error CS1670: params is not valid in this context + // Action q18 = (int x, params double[] s)=>{}; + Diagnostic(ErrorCode.ERR_IllegalParams, "params").WithLocation(68, 45), + // (70,34): error CS1593: Delegate 'Action' does not take 1 arguments + // object q19 = new Action( (int x)=>{} ); + Diagnostic(ErrorCode.ERR_BadDelArgCount, "(int x)=>{}").WithArguments("System.Action", "1").WithLocation(70, 34), + // (72,9): warning CS0436: The type 'Expression' in '' conflicts with the imported type 'Expression' in 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using the type defined in ''. + // Expression ex1 = ()=>1; + Diagnostic(ErrorCode.WRN_SameFullNameThisAggAgg, "Expression").WithArguments("", "System.Linq.Expressions.Expression", "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Linq.Expressions.Expression").WithLocation(72, 9), + // (72,31): error CS0835: Cannot convert lambda to an expression tree whose type argument 'int' is not a delegate type + // Expression ex1 = ()=>1; + Diagnostic(ErrorCode.ERR_ExpressionTreeMustHaveDelegate, "()=>1").WithArguments("int").WithLocation(72, 31)); } [Fact] // 5368 @@ -6732,5 +6731,56 @@ void M(int _) Assert.Equal("System.String _", model.GetSymbolInfo(underscore).Symbol.ToTestDisplayString()); } + + [WorkItem(62085, "https://github.com/dotnet/roslyn/issues/62085")] + [Fact] + public void DuplicateRef() + { + var source = +@"delegate void D(ref int i); +class Program +{ + static void Main() + { + D d1 = (ref ref int i) => { }; + D d2 = (in ref int i) => { }; + D d3 = (out ref int i) => { }; + } +}"; + var comp = CreateCompilation(source); + comp.VerifyEmitDiagnostics( + // (6,21): error CS1107: A parameter can only have one 'ref' modifier + // D d1 = (ref ref int i) => { }; + Diagnostic(ErrorCode.ERR_DupParamMod, "ref").WithArguments("ref").WithLocation(6, 21), + // (7,16): error CS1661: Cannot convert lambda expression to type 'D' because the parameter types do not match the delegate parameter types + // D d2 = (in ref int i) => { }; + Diagnostic(ErrorCode.ERR_CantConvAnonMethParams, "(in ref int i) => { }").WithArguments("lambda expression", "D").WithLocation(7, 16), + // (7,20): error CS8328: The parameter modifier 'ref' cannot be used with 'in' + // D d2 = (in ref int i) => { }; + Diagnostic(ErrorCode.ERR_BadParameterModifiers, "ref").WithArguments("ref", "in").WithLocation(7, 20), + // (7,28): error CS1676: Parameter 1 must be declared with the 'ref' keyword + // D d2 = (in ref int i) => { }; + Diagnostic(ErrorCode.ERR_BadParamRef, "i").WithArguments("1", "ref").WithLocation(7, 28), + // (8,16): error CS1661: Cannot convert lambda expression to type 'D' because the parameter types do not match the delegate parameter types + // D d3 = (out ref int i) => { }; + Diagnostic(ErrorCode.ERR_CantConvAnonMethParams, "(out ref int i) => { }").WithArguments("lambda expression", "D").WithLocation(8, 16), + // (8,16): error CS0177: The out parameter 'i' must be assigned to before control leaves the current method + // D d3 = (out ref int i) => { }; + Diagnostic(ErrorCode.ERR_ParamUnassigned, "(out ref int i) => { }").WithArguments("i").WithLocation(8, 16), + // (8,21): error CS8328: The parameter modifier 'ref' cannot be used with 'out' + // D d3 = (out ref int i) => { }; + Diagnostic(ErrorCode.ERR_BadParameterModifiers, "ref").WithArguments("ref", "out").WithLocation(8, 21), + // (8,29): error CS1676: Parameter 1 must be declared with the 'ref' keyword + // D d3 = (out ref int i) => { }; + Diagnostic(ErrorCode.ERR_BadParamRef, "i").WithArguments("1", "ref").WithLocation(8, 29)); + + var tree = comp.SyntaxTrees[0]; + var model = comp.GetSemanticModel(tree); + var lambdas = tree.GetRoot().DescendantNodes().OfType().Select(e => model.GetSymbolInfo(e).Symbol.GetSymbol()).ToArray(); + + Assert.Equal(RefKind.Ref, lambdas[0].Parameters[0].RefKind); + Assert.Equal(RefKind.In, lambdas[1].Parameters[0].RefKind); + Assert.Equal(RefKind.Out, lambdas[2].Parameters[0].RefKind); + } } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs index 7a14b2051524d..595b76dd2a960 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs @@ -6730,9 +6730,9 @@ public ref int M() throw null; } }").VerifyDiagnostics( - // (10,24): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (10,24): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return ref inner[5]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(10, 24)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(10, 24)); } [Fact] @@ -6758,9 +6758,9 @@ public ref int M() // (8,13): warning CS8794: An expression of type 'Span' always matches the provided pattern. // if (outer is ({} and var x) and Span inner) Diagnostic(ErrorCode.WRN_IsPatternAlways, "outer is ({} and var x) and Span inner").WithArguments("System.Span").WithLocation(8, 13), - // (10,24): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (10,24): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return ref inner[5]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(10, 24) + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(10, 24) ); } @@ -6786,9 +6786,9 @@ public ref int M() throw null; } }").VerifyDiagnostics( - // (12,28): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (12,28): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return ref inner[5]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(12, 28)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(12, 28)); } [Fact] @@ -6813,9 +6813,9 @@ public ref int M() throw null; } }").VerifyDiagnostics( - // (12,28): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (12,28): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return ref inner[5]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(12, 28)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(12, 28)); } [Fact] @@ -6890,27 +6890,27 @@ public R M7() } } ").VerifyDiagnostics( - // (16,42): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (16,42): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case { Prop: var x }: return x; // error 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(16, 42), - // (24,40): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(16, 42), + // (24,40): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case { Prop: R x }: return x; // error 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(24, 40), - // (32,41): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(24, 40), + // (32,41): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case (var x, var y): return x; // error 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(32, 41), - // (40,37): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(32, 41), + // (40,37): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case (R x, R y): return x; // error 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(40, 37), - // (48,37): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(40, 37), + // (48,37): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case var (x, y): return x; // error 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(48, 37), - // (56,32): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(48, 37), + // (56,32): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case { } x: return x; // error 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(56, 32), - // (64,35): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(56, 32), + // (64,35): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case (_, _) x: return x; // error 7 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(64, 35) + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(64, 35) ); } @@ -6986,27 +6986,27 @@ public R M7() } } ").VerifyDiagnostics( - // (16,76): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (16,76): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case var _ and {} and { Prop: var _ and {} and var x }: return x; // error 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(16, 76), - // (24,74): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(16, 76), + // (24,74): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case var _ and {} and { Prop: var _ and {} and R x }: return x; // error 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(24, 74), - // (32,92): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(24, 74), + // (32,92): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case var _ and {} and (var _ and {} and var x, var _ and {} and var y): return x; // error 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(32, 92), - // (40,88): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(32, 92), + // (40,88): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case var _ and {} and (var _ and {} and R x, var _ and {} and R y): return x; // error 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(40, 88), - // (48,54): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(40, 88), + // (48,54): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case var _ and {} and var (x, y): return x; // error 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(48, 54), - // (56,49): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(48, 54), + // (56,49): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case var _ and {} and { } x: return x; // error 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(56, 49), - // (64,86): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(56, 49), + // (64,86): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // case var _ and {} and (var _ and {} and _, var _ and {} and _) x: return x; // error 7 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(64, 86) + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(64, 86) ); } @@ -7068,27 +7068,27 @@ public R M7() } } ").VerifyDiagnostics( - // (14,46): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (14,46): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is { Prop: var x }) return x; // error 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(14, 46), - // (20,44): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(14, 46), + // (20,44): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is { Prop: R x }) return x; // error 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(20, 44), - // (26,45): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(20, 44), + // (26,45): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is (var x, var y)) return x; // error 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(26, 45), - // (32,41): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(26, 45), + // (32,41): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is (R x, R y)) return x; // error 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(32, 41), - // (38,41): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(32, 41), + // (38,41): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is var (x, y)) return x; // error 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(38, 41), - // (44,36): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(38, 41), + // (44,36): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is { } x) return x; // error 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(44, 36), - // (50,39): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(44, 36), + // (50,39): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is (_, _) x) return x; // error 7 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(50, 39) + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(50, 39) ); } @@ -7152,45 +7152,45 @@ public R M7() ").VerifyDiagnostics( // if (outer is var _ and {} and { Prop: var _ and {} and var x }) return x; // error 1 Diagnostic(ErrorCode.WRN_IsPatternAlways, "outer is var _ and {} and { Prop: var _ and {} and var x }").WithArguments("R").WithLocation(14, 13), - // (14,80): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (14,80): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is var _ and {} and { Prop: var _ and {} and var x }) return x; // error 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(14, 80), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(14, 80), // (20,13): warning CS8794: An expression of type 'R' always matches the provided pattern. // if (outer is var _ and {} and { Prop: var _ and {} and R x }) return x; // error 2 Diagnostic(ErrorCode.WRN_IsPatternAlways, "outer is var _ and {} and { Prop: var _ and {} and R x }").WithArguments("R").WithLocation(20, 13), - // (20,78): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (20,78): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is var _ and {} and { Prop: var _ and {} and R x }) return x; // error 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(20, 78), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(20, 78), // (26,13): warning CS8794: An expression of type 'R' always matches the provided pattern. // if (outer is var _ and {} and (var _ and {} and var x, var _ and {} and var y)) return x; // error 3 Diagnostic(ErrorCode.WRN_IsPatternAlways, "outer is var _ and {} and (var _ and {} and var x, var _ and {} and var y)").WithArguments("R").WithLocation(26, 13), - // (26,96): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (26,96): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is var _ and {} and (var _ and {} and var x, var _ and {} and var y)) return x; // error 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(26, 96), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(26, 96), // (32,13): warning CS8794: An expression of type 'R' always matches the provided pattern. // if (outer is var _ and {} and (var _ and {} and R x, var _ and {} and R y)) return x; // error 4 Diagnostic(ErrorCode.WRN_IsPatternAlways, "outer is var _ and {} and (var _ and {} and R x, var _ and {} and R y)").WithArguments("R").WithLocation(32, 13), - // (32,92): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (32,92): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is var _ and {} and (var _ and {} and R x, var _ and {} and R y)) return x; // error 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(32, 92), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(32, 92), // (38,13): warning CS8794: An expression of type 'R' always matches the provided pattern. // if (outer is var _ and {} and var (x, y)) return x; // error 5 Diagnostic(ErrorCode.WRN_IsPatternAlways, "outer is var _ and {} and var (x, y)").WithArguments("R").WithLocation(38, 13), - // (38,58): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (38,58): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is var _ and {} and var (x, y)) return x; // error 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(38, 58), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(38, 58), // (44,13): warning CS8794: An expression of type 'R' always matches the provided pattern. // if (outer is var _ and {} and { } x) return x; // error 6 Diagnostic(ErrorCode.WRN_IsPatternAlways, "outer is var _ and {} and { } x").WithArguments("R").WithLocation(44, 13), - // (44,53): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (44,53): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is var _ and {} and { } x) return x; // error 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(44, 53), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(44, 53), // (50,13): warning CS8794: An expression of type 'R' always matches the provided pattern. // if (outer is var _ and {} and (_, _) x) return x; // error 7 Diagnostic(ErrorCode.WRN_IsPatternAlways, "outer is var _ and {} and (_, _) x").WithArguments("R").WithLocation(50, 13), - // (50,56): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (50,56): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // if (outer is var _ and {} and (_, _) x) return x; // error 7 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(50, 56) + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(50, 56) ); } @@ -7226,12 +7226,12 @@ public void M1(ref R r, ref S s) if (outer is { RProp: { SProp: var rs1 }}) s = rs1; // OK } }").VerifyDiagnostics( - // (19,52): error CS8352: Cannot use local 'rr0' in this context because it may expose referenced variables outside of their declaration scope + // (19,52): error CS8352: Cannot use variable 'rr0' in this context because it may expose referenced variables outside of their declaration scope // if (outer is { RProp.RProp: var rr0 }) r = rr0; // error - Diagnostic(ErrorCode.ERR_EscapeLocal, "rr0").WithArguments("rr0").WithLocation(19, 52), - // (23,56): error CS8352: Cannot use local 'rr1' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "rr0").WithArguments("rr0").WithLocation(19, 52), + // (23,56): error CS8352: Cannot use variable 'rr1' in this context because it may expose referenced variables outside of their declaration scope // if (outer is { RProp: { RProp: var rr1 }}) r = rr1; // error - Diagnostic(ErrorCode.ERR_EscapeLocal, "rr1").WithArguments("rr1").WithLocation(23, 56)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "rr1").WithArguments("rr1").WithLocation(23, 56)); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs index ece30c4353e11..1ccca16527844 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs @@ -503,9 +503,9 @@ public static RGBColor FromSpan(int r, int g, int b) // (17,18): error CS8347: Cannot use a result of 'Program.RGBColor.RGBColor(Span)' in this context because it may expose variables referenced by parameter 'span' outside of their declaration scope // 1 => new RGBColor(span), Diagnostic(ErrorCode.ERR_EscapeCall, "new RGBColor(span)").WithArguments("Program.RGBColor.RGBColor(System.Span)", "span").WithLocation(17, 18), - // (17,31): error CS8352: Cannot use local 'span' in this context because it may expose referenced variables outside of their declaration scope + // (17,31): error CS8352: Cannot use variable 'span' in this context because it may expose referenced variables outside of their declaration scope // 1 => new RGBColor(span), - Diagnostic(ErrorCode.ERR_EscapeLocal, "span").WithArguments("span").WithLocation(17, 31)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "span").WithArguments("span").WithLocation(17, 31)); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs index f5d0698de3da1..2f96e69ec5d32 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs @@ -2848,18 +2848,18 @@ public void M2b(ref R r) } } }").VerifyDiagnostics( - // (15,35): error CS8352: Cannot use local 'list' in this context because it may expose referenced variables outside of their declaration scope + // (15,35): error CS8352: Cannot use variable 'list' in this context because it may expose referenced variables outside of their declaration scope // if (outer is [] list) s = list; // error 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "list").WithArguments("list").WithLocation(15, 35), - // (22,17): error CS8352: Cannot use local 'element' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "list").WithArguments("list").WithLocation(15, 35), + // (22,17): error CS8352: Cannot use variable 'element' in this context because it may expose referenced variables outside of their declaration scope // r = element; // error 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "element").WithArguments("element").WithLocation(22, 17), - // (23,17): error CS8352: Cannot use local 'slice' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "element").WithArguments("element").WithLocation(22, 17), + // (23,17): error CS8352: Cannot use variable 'slice' in this context because it may expose referenced variables outside of their declaration scope // r = slice; // error 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "slice").WithArguments("slice").WithLocation(23, 17), - // (24,17): error CS8352: Cannot use local 'list' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "slice").WithArguments("slice").WithLocation(23, 17), + // (24,17): error CS8352: Cannot use variable 'list' in this context because it may expose referenced variables outside of their declaration scope // r = list; // error 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "list").WithArguments("list").WithLocation(24, 17)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "list").WithArguments("list").WithLocation(24, 17)); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RawInterpolationTests_Handler.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RawInterpolationTests_Handler.cs index 751fd8157dc8c..bc25f8214cde2 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RawInterpolationTests_Handler.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RawInterpolationTests_Handler.cs @@ -10983,9 +10983,9 @@ public static CustomHandler M() var comp = CreateCompilation(new[] { code, InterpolatedStringHandlerAttribute }, targetFramework: TargetFramework.NetCoreApp); comp.VerifyDiagnostics( - // (17,19): error CS8352: Cannot use local 's' in this context because it may expose referenced variables outside of their declaration scope + // (17,19): error CS8352: Cannot use variable 's' in this context because it may expose referenced variables outside of their declaration scope // return $"{s}"; - Diagnostic(ErrorCode.ERR_EscapeLocal, "s").WithArguments("s").WithLocation(17, 21)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "s").WithArguments("s").WithLocation(17, 21)); } [Theory] @@ -11104,9 +11104,9 @@ public ref struct S1 // (17,20): error CS8347: Cannot use a result of 'CustomHandler.CustomHandler(int, int, ref S1)' in this context because it may expose variables referenced by parameter 's1' outside of their declaration scope // M2(ref s1, $"""{s}""" + $""" Diagnostic(ErrorCode.ERR_EscapeCall, expression).WithArguments("CustomHandler.CustomHandler(int, int, ref S1)", "s1").WithLocation(17, 20), - // (17,23): error CS8352: Cannot use local 's' in this context because it may expose referenced variables outside of their declaration scope + // (17,23): error CS8352: Cannot use variable 's' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s1, $"{s}"); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s").WithArguments("s").WithLocation(17, 25)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "s").WithArguments("s").WithLocation(17, 25)); } [Theory] @@ -11246,9 +11246,9 @@ public static ref CustomHandler M2(ref Span s, [InterpolatedStringHandlerA var comp = CreateCompilation(new[] { code, InterpolatedStringHandlerAttribute, InterpolatedStringHandlerArgumentAttribute }, targetFramework: TargetFramework.NetCoreApp); comp.VerifyDiagnostics( - // (16,16): error CS8352: Cannot use local 'c' in this context because it may expose referenced variables outside of their declaration scope + // (16,16): error CS8352: Cannot use variable 'c' in this context because it may expose referenced variables outside of their declaration scope // return c; - Diagnostic(ErrorCode.ERR_EscapeLocal, "c").WithArguments("c").WithLocation(18, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "c").WithArguments("c").WithLocation(18, 16)); } [Fact] @@ -11293,9 +11293,9 @@ public ref struct S1 // (15,20): error CS8347: Cannot use a result of 'CustomHandler.CustomHandler(int, int, ref S1)' in this context because it may expose variables referenced by parameter 's1' outside of their declaration scope // M2(ref s1, $"""{s2}"""); Diagnostic(ErrorCode.ERR_EscapeCall, @"$""""""{s2}""""""").WithArguments("CustomHandler.CustomHandler(int, int, ref S1)", "s1").WithLocation(15, 20), - // (15,23): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (15,23): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s1, $"{s2}"); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(15, 25)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(15, 25)); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordStructTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordStructTests.cs index ba5fb67ec78b5..3e2e401936dab 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordStructTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordStructTests.cs @@ -7933,12 +7933,12 @@ public ref struct S2 } "; CreateCompilationWithMscorlibAndSpan(text, parseOptions: TestOptions.RegularPreview).VerifyDiagnostics( - // (12,48): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (12,48): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return new S2() with { Field1 = outer, Field2 = inner }; - Diagnostic(ErrorCode.ERR_EscapeLocal, "Field2 = inner").WithArguments("inner").WithLocation(12, 48), - // (23,34): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "Field2 = inner").WithArguments("inner").WithLocation(12, 48), + // (23,34): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // result = new S2() with { Field1 = inner, Field2 = outer }; - Diagnostic(ErrorCode.ERR_EscapeLocal, "Field1 = inner").WithArguments("inner").WithLocation(23, 34) + Diagnostic(ErrorCode.ERR_EscapeVariable, "Field1 = inner").WithArguments("inner").WithLocation(23, 34) ); } @@ -7969,9 +7969,9 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (9,26): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (9,26): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // sp = MayWrap(ref local) with { }; // 1, 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(9, 26), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(9, 26), // (9,14): error CS8347: Cannot use a result of 'Program.MayWrap(ref Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // sp = MayWrap(ref local) with { }; // 1, 2 Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(ref local)").WithArguments("Program.MayWrap(ref System.Span)", "arg").WithLocation(9, 14) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefEscapingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefEscapingTests.cs index 9ad408d3bddfd..c4e52654972b2 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefEscapingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefEscapingTests.cs @@ -136,9 +136,9 @@ void M() } }"); comp.VerifyDiagnostics( - // (10,21): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (10,21): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // outer = inner; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(10, 21)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(10, 21)); } [Fact] @@ -179,9 +179,9 @@ IEnumerable Gen() } }"); comp.VerifyDiagnostics( - // (9,22): error CS8352: Cannot use local 's' in this context because it may expose referenced variables outside of their declaration scope + // (9,22): error CS8352: Cannot use variable 's' in this context because it may expose referenced variables outside of their declaration scope // yield return s; - Diagnostic(ErrorCode.ERR_EscapeLocal, "s").WithArguments("s").WithLocation(9, 22)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "s").WithArguments("s").WithLocation(9, 22)); } [Fact()] @@ -218,9 +218,9 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (23,42): error CS8526: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (23,42): error CS8526: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // return ref Test1(MayWrap(ref local)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(23, 42), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(23, 42), // (23,30): error CS8521: Cannot use a result of 'Program.MayWrap(ref Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // return ref Test1(MayWrap(ref local)); Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(ref local)").WithArguments("Program.MayWrap(ref System.Span)", "arg").WithLocation(23, 30), @@ -229,7 +229,7 @@ ref struct S1 Diagnostic(ErrorCode.ERR_EscapeCall, "Test1(MayWrap(ref local))").WithArguments("Program.Test1(Program.S1)", "arg").WithLocation(23, 24) ); - // C#11 reports ERR_RefReturnLocal rather than ERR_EscapeLocal for 'local' because CheckInvocationEscape() + // C#11 reports ERR_RefReturnLocal rather than ERR_EscapeVariable for 'local' because CheckInvocationEscape() // checks for ref-safe-to-escape of 'local' since it is passed as a 'ref' parameter to a method returning a ref struct. CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( // (23,42): error CS8168: Cannot return local 'local' by reference because it is not a ref local @@ -279,9 +279,9 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (24,30): error CS8526: Cannot use local 'sp' in this context because it may expose referenced variables outside of their declaration scope + // (24,30): error CS8526: Cannot use variable 'sp' in this context because it may expose referenced variables outside of their declaration scope // return ref Test1(sp); - Diagnostic(ErrorCode.ERR_EscapeLocal, "sp").WithArguments("sp").WithLocation(24, 30), + Diagnostic(ErrorCode.ERR_EscapeVariable, "sp").WithArguments("sp").WithLocation(24, 30), // (24,24): error CS8521: Cannot use a result of 'Program.Test1(Program.S1)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // return ref Test1(sp); Diagnostic(ErrorCode.ERR_EscapeCall, "Test1(sp)").WithArguments("Program.Test1(Program.S1)", "arg").WithLocation(24, 24) @@ -393,12 +393,12 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (33,19): error CS8526: Cannot use local 'spNr' in this context because it may expose referenced variables outside of their declaration scope + // (33,19): error CS8526: Cannot use variable 'spNr' in this context because it may expose referenced variables outside of their declaration scope // spR = spNr; - Diagnostic(ErrorCode.ERR_EscapeLocal, "spNr").WithArguments("spNr").WithLocation(33, 19), - // (39,19): error CS8526: Cannot use local 'ternary' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "spNr").WithArguments("spNr").WithLocation(33, 19), + // (39,19): error CS8526: Cannot use variable 'ternary' in this context because it may expose referenced variables outside of their declaration scope // spR = ternary; - Diagnostic(ErrorCode.ERR_EscapeLocal, "ternary").WithArguments("ternary").WithLocation(39, 19) + Diagnostic(ErrorCode.ERR_EscapeVariable, "ternary").WithArguments("ternary").WithLocation(39, 19) ); // The initializer for `var spR = MayWrap(Test1(ref sp));` has escape scope of @@ -449,9 +449,9 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (31,30): error CS8352: Cannot use local 'sp' in this context because it may expose referenced variables outside of their declaration scope + // (31,30): error CS8352: Cannot use variable 'sp' in this context because it may expose referenced variables outside of their declaration scope // return ref Test1(sp); - Diagnostic(ErrorCode.ERR_EscapeLocal, "sp").WithArguments("sp").WithLocation(31, 30), + Diagnostic(ErrorCode.ERR_EscapeVariable, "sp").WithArguments("sp").WithLocation(31, 30), // (31,24): error CS8347: Cannot use a result of 'Program.Test1(Program.S1)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // return ref Test1(sp); Diagnostic(ErrorCode.ERR_EscapeCall, "Test1(sp)").WithArguments("Program.Test1(Program.S1)", "arg").WithLocation(31, 24), @@ -543,9 +543,9 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (18,29): error CS8526: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (18,29): error CS8526: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // x = MayWrap(inner); - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(18, 29), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(18, 29), // (18,21): error CS8521: Cannot use a result of 'Program.MayWrap(Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // x = MayWrap(inner); Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(inner)").WithArguments("Program.MayWrap(System.Span)", "arg").WithLocation(18, 21) @@ -587,9 +587,9 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (18,35): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (18,35): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // x = MayWrap(__arglist(inner)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(18, 35), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(18, 35), // (18,17): error CS8347: Cannot use a result of 'Program.MayWrap(__arglist)' in this context because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // x = MayWrap(__arglist(inner)); Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(__arglist(inner))").WithArguments("Program.MayWrap(__arglist)", "__arglist").WithLocation(18, 17) @@ -646,9 +646,9 @@ static ref int ReturnsRefSpan1(__arglist) // (24,20): error CS8156: An expression cannot be used in this context because it may not be returned by reference // return ref __refvalue(ai.GetNextArg(), int); Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "__refvalue(ai.GetNextArg(), int)").WithLocation(24, 20), - // (32,46): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (32,46): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // return ref ReturnsRef1(__arglist(ref local)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(32, 46), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(32, 46), // (32,20): error CS8347: Cannot use a result of 'Program.ReturnsRef1(__arglist)' in this context because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // return ref ReturnsRef1(__arglist(ref local)); Diagnostic(ErrorCode.ERR_EscapeCall, "ReturnsRef1(__arglist(ref local))").WithArguments("Program.ReturnsRef1(__arglist)", "__arglist").WithLocation(32, 20) @@ -729,12 +729,12 @@ ref struct S1 "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (22,18): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (22,18): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // global = local && global; - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(22, 18), - // (25,26): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(22, 18), + // (25,26): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // return global || local; - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(25, 26) + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(25, 26) ); } @@ -771,7 +771,7 @@ static ref int ReturnsRef1(out int x) Diagnostic(ErrorCode.ERR_EscapeCall, "ReturnsRef1(out var _)").WithArguments("Program.ReturnsRef1(out int)", "x").WithLocation(12, 20) ); CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (18,20): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (18,20): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // return ref x; Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(18, 20) ); @@ -822,7 +822,7 @@ static ref int ReturnsRef(out int x) Diagnostic(ErrorCode.ERR_EscapeCall, "ReturnsRef(out z)").WithArguments("Program.ReturnsRef(out int)", "x").WithLocation(17, 20) ); CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (24,20): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (24,20): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // return ref x; Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(24, 20) ); @@ -887,7 +887,7 @@ static ref Span ReturnsSpan(out Span x) // (32,35): error CS8353: A result of a stackalloc expression of type 'Span' cannot be used in this context because it may be exposed outside of the containing method // ReturnsSpan(out var _ ) = stackalloc int[1]; Diagnostic(ErrorCode.ERR_EscapeStackAlloc, "stackalloc int[1]").WithArguments("System.Span").WithLocation(32, 35), - // (38,20): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (38,20): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // return ref x; Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(38, 20) ); @@ -992,7 +992,7 @@ static ref Span ReturnsSpan(out Span x) // (60,30): error CS8353: A result of a stackalloc expression of type 'Span' cannot be used in this context because it may be exposed outside of the containing method // ReturnsSpan(out s) = stackalloc int[1]; Diagnostic(ErrorCode.ERR_EscapeStackAlloc, "stackalloc int[1]").WithArguments("System.Span").WithLocation(60, 30), - // (66,20): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (66,20): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // return ref x; Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(66, 20) ); @@ -1034,9 +1034,9 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (19,33): error CS8526: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (19,33): error CS8526: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // x = MayWrap(ref inner); - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(19, 33), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(19, 33), // (19,21): error CS8521: Cannot use a result of 'Program.MayWrap(ref Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // x = MayWrap(ref inner); Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(ref inner)").WithArguments("Program.MayWrap(ref System.Span)", "arg").WithLocation(19, 21) @@ -1101,9 +1101,9 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (21,33): error CS8526: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (21,33): error CS8526: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // x = MayWrap(ref inner).Slice(1); - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(21, 33), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(21, 33), // (21,21): error CS8521: Cannot use a result of 'Program.MayWrap(ref Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // x = MayWrap(ref inner).Slice(1); Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(ref inner)").WithArguments("Program.MayWrap(ref System.Span)", "arg").WithLocation(21, 21) @@ -1162,21 +1162,21 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (20,32): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (20,32): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // x[0] = MayWrap(ref inner).Slice(1)[0]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(20, 32), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(20, 32), // (20,20): error CS8347: Cannot use a result of 'Program.MayWrap(ref Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // x[0] = MayWrap(ref inner).Slice(1)[0]; Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(ref inner)").WithArguments("Program.MayWrap(ref System.Span)", "arg").WithLocation(20, 20), - // (25,32): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (25,32): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // x[x] = MayWrap(ref inner).Slice(1)[0]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(25, 32), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(25, 32), // (25,20): error CS8347: Cannot use a result of 'Program.MayWrap(ref Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // x[x] = MayWrap(ref inner).Slice(1)[0]; Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(ref inner)").WithArguments("Program.MayWrap(ref System.Span)", "arg").WithLocation(25, 20), - // (28,50): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (28,50): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // x.ReturnsRefArg(ref x) = MayWrap(ref inner).Slice(1)[0]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(28, 50), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(28, 50), // (28,38): error CS8347: Cannot use a result of 'Program.MayWrap(ref Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // x.ReturnsRefArg(ref x) = MayWrap(ref inner).Slice(1)[0]; Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(ref inner)").WithArguments("Program.MayWrap(ref System.Span)", "arg").WithLocation(28, 38) @@ -1225,9 +1225,9 @@ ref struct S0 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (18,31): error CS8526: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (18,31): error CS8526: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // x.field = MayWrap(inner).Slice(1).field; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(18, 31), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(18, 31), // (18,23): error CS8521: Cannot use a result of 'Program.MayWrap(Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // x.field = MayWrap(inner).Slice(1).field; Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(inner)").WithArguments("Program.MayWrap(System.Span)", "arg").WithLocation(18, 23) @@ -1367,15 +1367,15 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (20,39): error CS8526: Cannot use local 'rInner' in this context because it may expose referenced variables outside of their declaration scope + // (20,39): error CS8526: Cannot use variable 'rInner' in this context because it may expose referenced variables outside of their declaration scope // MayAssign(ref rOuter, ref rInner); - Diagnostic(ErrorCode.ERR_EscapeLocal, "rInner").WithArguments("rInner").WithLocation(20, 39), + Diagnostic(ErrorCode.ERR_EscapeVariable, "rInner").WithArguments("rInner").WithLocation(20, 39), // (20,13): error CS8524: This combination of arguments to 'Program.MayAssign(ref Program.S1, ref Program.S1)' is disallowed because it may expose variables referenced by parameter 'arg2' outside of their declaration scope // MayAssign(ref rOuter, ref rInner); Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssign(ref rOuter, ref rInner)").WithArguments("Program.MayAssign(ref Program.S1, ref Program.S1)", "arg2").WithLocation(20, 13), - // (23,27): error CS8526: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (23,27): error CS8526: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // MayAssign(ref inner, ref rOuter); - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(23, 27), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(23, 27), // (23,13): error CS8524: This combination of arguments to 'Program.MayAssign(ref Span, ref Program.S1)' is disallowed because it may expose variables referenced by parameter 'arg1' outside of their declaration scope // MayAssign(ref inner, ref rOuter); Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssign(ref inner, ref rOuter)").WithArguments("Program.MayAssign(ref System.Span, ref Program.S1)", "arg1").WithLocation(23, 13) @@ -1441,15 +1441,15 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (20,46): error CS8352: Cannot use local 'rInner' in this context because it may expose referenced variables outside of their declaration scope + // (20,46): error CS8352: Cannot use variable 'rInner' in this context because it may expose referenced variables outside of their declaration scope // MayAssign2(__arglist(ref rOuter, ref rInner)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "rInner").WithArguments("rInner").WithLocation(20, 46), + Diagnostic(ErrorCode.ERR_EscapeVariable, "rInner").WithArguments("rInner").WithLocation(20, 46), // (20,9): error CS8350: This combination of arguments to 'Program.MayAssign2(__arglist)' is disallowed because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // MayAssign2(__arglist(ref rOuter, ref rInner)); Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssign2(__arglist(ref rOuter, ref rInner))").WithArguments("Program.MayAssign2(__arglist)", "__arglist").WithLocation(20, 9), - // (23,34): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (23,34): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // MayAssign1(__arglist(ref inner, ref rOuter)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(23, 34), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(23, 34), // (23,9): error CS8350: This combination of arguments to 'Program.MayAssign1(__arglist)' is disallowed because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // MayAssign1(__arglist(ref inner, ref rOuter)); Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssign1(__arglist(ref inner, ref rOuter))").WithArguments("Program.MayAssign1(__arglist)", "__arglist").WithLocation(23, 9) @@ -1459,15 +1459,15 @@ ref struct S1 // returns a ref struct is safe-to-escape from ... the ref-safe-to-escape of all ref arguments, // and arg2 is initialized with __refvalue which has ref-safe-to-escape of the current method. CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (20,46): error CS8352: Cannot use local 'rInner' in this context because it may expose referenced variables outside of their declaration scope + // (20,46): error CS8352: Cannot use variable 'rInner' in this context because it may expose referenced variables outside of their declaration scope // MayAssign2(__arglist(ref rOuter, ref rInner)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "rInner").WithArguments("rInner").WithLocation(20, 46), + Diagnostic(ErrorCode.ERR_EscapeVariable, "rInner").WithArguments("rInner").WithLocation(20, 46), // (20,9): error CS8350: This combination of arguments to 'Program.MayAssign2(__arglist)' is disallowed because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // MayAssign2(__arglist(ref rOuter, ref rInner)); Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssign2(__arglist(ref rOuter, ref rInner))").WithArguments("Program.MayAssign2(__arglist)", "__arglist").WithLocation(20, 9), - // (23,34): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (23,34): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // MayAssign1(__arglist(ref inner, ref rOuter)); - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(23, 34), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(23, 34), // (23,9): error CS8350: This combination of arguments to 'Program.MayAssign1(__arglist)' is disallowed because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // MayAssign1(__arglist(ref inner, ref rOuter)); Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssign1(__arglist(ref inner, ref rOuter))").WithArguments("Program.MayAssign1(__arglist)", "__arglist").WithLocation(23, 9), @@ -1610,15 +1610,15 @@ public int this[in S1 arg1] } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (24,29): error CS8526: Cannot use local 'rInner' in this context because it may expose referenced variables outside of their declaration scope + // (24,29): error CS8526: Cannot use variable 'rInner' in this context because it may expose referenced variables outside of their declaration scope // int dummy3 = rOuter[rInner]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "rInner").WithArguments("rInner").WithLocation(24, 29), + Diagnostic(ErrorCode.ERR_EscapeVariable, "rInner").WithArguments("rInner").WithLocation(24, 29), // (24,22): error CS8524: This combination of arguments to 'Program.S1.this[in Program.S1]' is disallowed because it may expose variables referenced by parameter 'arg1' outside of their declaration scope // int dummy3 = rOuter[rInner]; Diagnostic(ErrorCode.ERR_CallArgMixing, "rOuter[rInner]").WithArguments("Program.S1.this[in Program.S1]", "arg1").WithLocation(24, 22), - // (27,29): error CS8526: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (27,29): error CS8526: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // int dummy4 = rOuter[inner]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(27, 29), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(27, 29), // (27,22): error CS8524: This combination of arguments to 'Program.S1.this[in Span]' is disallowed because it may expose variables referenced by parameter 'arg1' outside of their declaration scope // int dummy4 = rOuter[inner]; Diagnostic(ErrorCode.ERR_CallArgMixing, "rOuter[inner]").WithArguments("Program.S1.this[in System.Span]", "arg1").WithLocation(27, 22) @@ -1680,15 +1680,15 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (26,43): error CS8526: Cannot use local 'rInner' in this context because it may expose referenced variables outside of their declaration scope + // (26,43): error CS8526: Cannot use variable 'rInner' in this context because it may expose referenced variables outside of their declaration scope // MayAssignDel1(ref rOuter, ref rInner); - Diagnostic(ErrorCode.ERR_EscapeLocal, "rInner").WithArguments("rInner").WithLocation(26, 43), + Diagnostic(ErrorCode.ERR_EscapeVariable, "rInner").WithArguments("rInner").WithLocation(26, 43), // (26,13): error CS8524: This combination of arguments to 'Program.D1.Invoke(ref Program.S1, ref Program.S1)' is disallowed because it may expose variables referenced by parameter 'arg2' outside of their declaration scope // MayAssignDel1(ref rOuter, ref rInner); Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssignDel1(ref rOuter, ref rInner)").WithArguments("Program.D1.Invoke(ref Program.S1, ref Program.S1)", "arg2").WithLocation(26, 13), - // (29,31): error CS8526: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (29,31): error CS8526: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // MayAssignDel2(ref inner, ref rOuter); - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(29, 31), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(29, 31), // (29,13): error CS8524: This combination of arguments to 'Program.D2.Invoke(ref Span, ref Program.S1)' is disallowed because it may expose variables referenced by parameter 'arg1' outside of their declaration scope // MayAssignDel2(ref inner, ref rOuter); Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssignDel2(ref inner, ref rOuter)").WithArguments("Program.D2.Invoke(ref System.Span, ref Program.S1)", "arg1").WithLocation(29, 13) @@ -1750,12 +1750,12 @@ public ref struct S2 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (16,47): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (16,47): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return new S2() { Field1 = outer, Field2 = inner }; - Diagnostic(ErrorCode.ERR_EscapeLocal, "Field2 = inner").WithArguments("inner").WithLocation(16, 47), - // (27,33): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "Field2 = inner").WithArguments("inner").WithLocation(16, 47), + // (27,33): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // result = new S2() { Field1 = inner, Field2 = outer }; - Diagnostic(ErrorCode.ERR_EscapeLocal, "Field1 = inner").WithArguments("inner").WithLocation(27, 33) + Diagnostic(ErrorCode.ERR_EscapeVariable, "Field1 = inner").WithArguments("inner").WithLocation(27, 33) ); } @@ -1817,12 +1817,12 @@ public ref struct S2 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (18,20): error CS8352: Cannot use local 'x1' in this context because it may expose referenced variables outside of their declaration scope + // (18,20): error CS8352: Cannot use variable 'x1' in this context because it may expose referenced variables outside of their declaration scope // return x1; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x1").WithArguments("x1").WithLocation(18, 20), - // (29,20): error CS8352: Cannot use local 'x2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x1").WithArguments("x1").WithLocation(18, 20), + // (29,20): error CS8352: Cannot use variable 'x2' in this context because it may expose referenced variables outside of their declaration scope // return x2; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x2").WithArguments("x2").WithLocation(29, 20) + Diagnostic(ErrorCode.ERR_EscapeVariable, "x2").WithArguments("x2").WithLocation(29, 20) ); } @@ -1890,12 +1890,12 @@ public S1 this[S1 i] } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (16,28): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (16,28): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return new S2() { [inner] = outer, Field2 = outer }; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(16, 28), - // (25,27): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(16, 28), + // (25,27): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return new S2() { [outer] = inner, Field2 = outer }; - Diagnostic(ErrorCode.ERR_EscapeLocal, "[outer] = inner").WithArguments("inner").WithLocation(25, 27) + Diagnostic(ErrorCode.ERR_EscapeVariable, "[outer] = inner").WithArguments("inner").WithLocation(25, 27) ); } @@ -1972,12 +1972,12 @@ public S1 this[S1 i] } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (18,16): error CS8352: Cannot use local 'x1' in this context because it may expose referenced variables outside of their declaration scope + // (18,16): error CS8352: Cannot use variable 'x1' in this context because it may expose referenced variables outside of their declaration scope // return x1; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x1").WithArguments("x1").WithLocation(18, 16), - // (29,29): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x1").WithArguments("x1").WithLocation(18, 16), + // (29,29): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // result = new S2() { [outer] = inner, Field2 = outer }; - Diagnostic(ErrorCode.ERR_EscapeLocal, "[outer] = inner").WithArguments("inner").WithLocation(29, 29) + Diagnostic(ErrorCode.ERR_EscapeVariable, "[outer] = inner").WithArguments("inner").WithLocation(29, 29) ); } @@ -2060,15 +2060,15 @@ public ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (15,38): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (15,38): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return new S2() { Field2 = {[inner] = outer} }; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(15, 38), - // (25,16): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(15, 38), + // (25,16): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // return x; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(25, 16), - // (33,37): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(25, 16), + // (33,37): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // return new S2() { Field2 = {[outer] = inner} }; - Diagnostic(ErrorCode.ERR_EscapeLocal, "[outer] = inner").WithArguments("inner").WithLocation(33, 37), + Diagnostic(ErrorCode.ERR_EscapeVariable, "[outer] = inner").WithArguments("inner").WithLocation(33, 37), // (67,19): warning CS0649: Field 'Program.S3.Field2' is never assigned to, and will always have its default value // public S1 Field2; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "Field2").WithArguments("Program.S3.Field2", "").WithLocation(67, 19) @@ -2148,15 +2148,15 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (20,54): error CS8526: Cannot use local 'rInner' in this context because it may expose referenced variables outside of their declaration scope + // (20,54): error CS8526: Cannot use variable 'rInner' in this context because it may expose referenced variables outside of their declaration scope // var dummy2 = new Program(ref rOuter, ref rInner); - Diagnostic(ErrorCode.ERR_EscapeLocal, "rInner").WithArguments("rInner").WithLocation(20, 54), + Diagnostic(ErrorCode.ERR_EscapeVariable, "rInner").WithArguments("rInner").WithLocation(20, 54), // (20,26): error CS8524: This combination of arguments to 'Program.Program(ref Program.S1, ref Program.S1)' is disallowed because it may expose variables referenced by parameter 'arg2' outside of their declaration scope // var dummy2 = new Program(ref rOuter, ref rInner); Diagnostic(ErrorCode.ERR_CallArgMixing, "new Program(ref rOuter, ref rInner)").WithArguments("Program.Program(ref Program.S1, ref Program.S1)", "arg2").WithLocation(20, 26), - // (23,42): error CS8526: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (23,42): error CS8526: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // var dummy3 = new Program(ref inner, ref rOuter); - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(23, 42), + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(23, 42), // (23,26): error CS8524: This combination of arguments to 'Program.Program(ref Span, ref Program.S1)' is disallowed because it may expose variables referenced by parameter 'arg1' outside of their declaration scope // var dummy3 = new Program(ref inner, ref rOuter); Diagnostic(ErrorCode.ERR_CallArgMixing, "new Program(ref inner, ref rOuter)").WithArguments("Program.Program(ref System.Span, ref Program.S1)", "arg1").WithLocation(23, 26) @@ -2313,27 +2313,27 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (27,44): error CS8526: Cannot use local 'sInner' in this context because it may expose referenced variables outside of their declaration scope + // (27,44): error CS8526: Cannot use variable 'sInner' in this context because it may expose referenced variables outside of their declaration scope // ternarySame2 = true ? sOuter : sInner; - Diagnostic(ErrorCode.ERR_EscapeLocal, "sInner").WithArguments("sInner").WithLocation(27, 44), - // (30,35): error CS8526: Cannot use local 'sInner' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "sInner").WithArguments("sInner").WithLocation(27, 44), + // (30,35): error CS8526: Cannot use variable 'sInner' in this context because it may expose referenced variables outside of their declaration scope // ternarySame2 = true ? sInner : sOuter; - Diagnostic(ErrorCode.ERR_EscapeLocal, "sInner").WithArguments("sInner").WithLocation(30, 35), - // (33,60): error CS8526: Cannot use local 'sInner' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "sInner").WithArguments("sInner").WithLocation(30, 35), + // (33,60): error CS8526: Cannot use variable 'sInner' in this context because it may expose referenced variables outside of their declaration scope // ref var ternary1 = ref true ? ref sOuter : ref sInner; - Diagnostic(ErrorCode.ERR_EscapeLocal, "sInner").WithArguments("sInner").WithLocation(33, 60), + Diagnostic(ErrorCode.ERR_EscapeVariable, "sInner").WithArguments("sInner").WithLocation(33, 60), // (33,36): error CS8525: Branches of a ref ternary operator cannot refer to variables with incompatible declaration scopes // ref var ternary1 = ref true ? ref sOuter : ref sInner; Diagnostic(ErrorCode.ERR_MismatchedRefEscapeInTernary, "true ? ref sOuter : ref sInner").WithLocation(33, 36), - // (36,47): error CS8526: Cannot use local 'sInner' in this context because it may expose referenced variables outside of their declaration scope + // (36,47): error CS8526: Cannot use variable 'sInner' in this context because it may expose referenced variables outside of their declaration scope // ref var ternary2 = ref true ? ref sInner : ref sOuter; - Diagnostic(ErrorCode.ERR_EscapeLocal, "sInner").WithArguments("sInner").WithLocation(36, 47), + Diagnostic(ErrorCode.ERR_EscapeVariable, "sInner").WithArguments("sInner").WithLocation(36, 47), // (36,36): error CS8525: Branches of a ref ternary operator cannot refer to variables with incompatible declaration scopes // ref var ternary2 = ref true ? ref sInner : ref sOuter; Diagnostic(ErrorCode.ERR_MismatchedRefEscapeInTernary, "true ? ref sInner : ref sOuter").WithLocation(36, 36), - // (39,47): error CS8526: Cannot use local 'ternarySame1' in this context because it may expose referenced variables outside of their declaration scope + // (39,47): error CS8526: Cannot use variable 'ternarySame1' in this context because it may expose referenced variables outside of their declaration scope // ref var ternary3 = ref true ? ref ternarySame1 : ref ternarySame2; - Diagnostic(ErrorCode.ERR_EscapeLocal, "ternarySame1").WithArguments("ternarySame1").WithLocation(39, 47), + Diagnostic(ErrorCode.ERR_EscapeVariable, "ternarySame1").WithArguments("ternarySame1").WithLocation(39, 47), // (39,36): error CS8525: Branches of a ref ternary operator cannot refer to variables with incompatible declaration scopes // ref var ternary3 = ref true ? ref ternarySame1 : ref ternarySame2; Diagnostic(ErrorCode.ERR_MismatchedRefEscapeInTernary, "true ? ref ternarySame1 : ref ternarySame2").WithLocation(39, 36) @@ -2379,9 +2379,9 @@ Span Test6() } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (19,26): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (19,26): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // return true? local : default(Span); - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(19, 26), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(19, 26), // (24,19): error CS8353: A result of a stackalloc expression of type 'Span' cannot be used in this context because it may be exposed outside of the containing method // arg = stackalloc int[10]; Diagnostic(ErrorCode.ERR_EscapeStackAlloc, "stackalloc int[10]").WithArguments("System.Span").WithLocation(24, 19), @@ -2431,18 +2431,18 @@ ref struct S1 } "; CreateCompilationWithMscorlibAndSpan(text, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (16,30): error CS8526: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (16,30): error CS8526: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // sp = MayWrap(ref local); - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(16, 30), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(16, 30), // (16,18): error CS8521: Cannot use a result of 'Program.MayWrap(ref Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // sp = MayWrap(ref local); Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(ref local)").WithArguments("Program.MayWrap(ref System.Span)", "arg").WithLocation(16, 18), - // (22,20): error CS8526: Cannot use local 'sp1' in this context because it may expose referenced variables outside of their declaration scope + // (22,20): error CS8526: Cannot use variable 'sp1' in this context because it may expose referenced variables outside of their declaration scope // return sp1; - Diagnostic(ErrorCode.ERR_EscapeLocal, "sp1").WithArguments("sp1").WithLocation(22, 20) + Diagnostic(ErrorCode.ERR_EscapeVariable, "sp1").WithArguments("sp1").WithLocation(22, 20) ); - // C#11 reports ERR_RefReturnLocal rather than ERR_EscapeLocal for 'local' because CheckInvocationEscape() + // C#11 reports ERR_RefReturnLocal rather than ERR_EscapeVariable for 'local' because CheckInvocationEscape() // checks for ref-safe-to-escape of 'local' since it is passed as a 'ref' parameter to a method returning a ref struct. CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( // (16,30): error CS8168: Cannot return local 'local' by reference because it is not a ref local @@ -2451,9 +2451,9 @@ ref struct S1 // (16,18): error CS8521: Cannot use a result of 'Program.MayWrap(ref Span)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // sp = MayWrap(ref local); Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(ref local)").WithArguments("Program.MayWrap(ref System.Span)", "arg").WithLocation(16, 18), - // (22,20): error CS8526: Cannot use local 'sp1' in this context because it may expose referenced variables outside of their declaration scope + // (22,20): error CS8526: Cannot use variable 'sp1' in this context because it may expose referenced variables outside of their declaration scope // return sp1; - Diagnostic(ErrorCode.ERR_EscapeLocal, "sp1").WithArguments("sp1").WithLocation(22, 20) + Diagnostic(ErrorCode.ERR_EscapeVariable, "sp1").WithArguments("sp1").WithLocation(22, 20) ); } @@ -2542,9 +2542,9 @@ public void TryGet(out Span result) } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (12,33): error CS8526: Cannot use local 'value1' in this context because it may expose referenced variables outside of their declaration scope + // (12,33): error CS8526: Cannot use variable 'value1' in this context because it may expose referenced variables outside of their declaration scope // new SW().TryGet(out value1); - Diagnostic(ErrorCode.ERR_EscapeLocal, "value1").WithArguments("value1").WithLocation(12, 33), + Diagnostic(ErrorCode.ERR_EscapeVariable, "value1").WithArguments("value1").WithLocation(12, 33), // (12,13): error CS8524: This combination of arguments to 'SW.TryGet(out Span)' is disallowed because it may expose variables referenced by parameter 'result' outside of their declaration scope // new SW().TryGet(out value1); Diagnostic(ErrorCode.ERR_CallArgMixing, "new SW().TryGet(out value1)").WithArguments("SW.TryGet(out System.Span)", "result").WithLocation(12, 13) @@ -2586,9 +2586,9 @@ public void CopyTo(Span other) } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (17,43): error CS8352: Cannot use local 'stackAllocated' in this context because it may expose referenced variables outside of their declaration scope + // (17,43): error CS8352: Cannot use variable 'stackAllocated' in this context because it may expose referenced variables outside of their declaration scope // new NotReadOnly().CopyTo(stackAllocated); - Diagnostic(ErrorCode.ERR_EscapeLocal, "stackAllocated").WithArguments("stackAllocated").WithLocation(17, 43), + Diagnostic(ErrorCode.ERR_EscapeVariable, "stackAllocated").WithArguments("stackAllocated").WithLocation(17, 43), // (17,13): error CS8350: This combination of arguments to 'NotReadOnly.CopyTo(Span)' is disallowed because it may expose variables referenced by parameter 'other' outside of their declaration scope // new NotReadOnly().CopyTo(stackAllocated); Diagnostic(ErrorCode.ERR_CallArgMixing, "new NotReadOnly().CopyTo(stackAllocated)").WithArguments("NotReadOnly.CopyTo(System.Span)", "other").WithLocation(17, 13) @@ -2656,9 +2656,9 @@ public unsafe static void N(S b) "; var comp = CreateCompilationWithMscorlibAndSpan(csharp, TestOptions.UnsafeDebugDll); comp.VerifyDiagnostics( - // (11,15): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (11,15): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // b.P = x; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(11, 15)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(11, 15)); } [Fact, WorkItem(35146, "https://github.com/dotnet/roslyn/issues/35146")] @@ -2680,9 +2680,9 @@ public unsafe static void N(S b) "; var comp = CreateCompilationWithMscorlibAndSpan(csharp, TestOptions.UnsafeDebugDll); comp.VerifyDiagnostics( - // (11,15): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (11,15): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // b.P = x; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(11, 15)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(11, 15)); } [Fact, WorkItem(35146, "https://github.com/dotnet/roslyn/issues/35146")] @@ -2704,9 +2704,9 @@ public unsafe static void N(S b) "; var comp = CreateCompilationWithMscorlibAndSpan(csharp, TestOptions.UnsafeDebugDll); comp.VerifyDiagnostics( - // (11,15): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (11,15): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // b.P = x; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(11, 15)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(11, 15)); } [Fact, WorkItem(35146, "https://github.com/dotnet/roslyn/issues/35146")] @@ -2733,9 +2733,9 @@ public unsafe static Span N(S b) // (13,16): error CS8347: Cannot use a result of 'S.this[Span]' in this context because it may expose variables referenced by parameter 'span' outside of their declaration scope // return b[x]; Diagnostic(ErrorCode.ERR_EscapeCall, "b[x]").WithArguments("S.this[System.Span]", "span").WithLocation(13, 16), - // (13,18): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (13,18): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // return b[x]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(13, 18)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(13, 18)); } [Fact, WorkItem(35146, "https://github.com/dotnet/roslyn/issues/35146")] @@ -2760,15 +2760,15 @@ public unsafe static void N(S b) // (10,13): error CS8350: This combination of arguments to 'S.this[Span]' is disallowed because it may expose variables referenced by parameter 'span' outside of their declaration scope // _ = b[x]; Diagnostic(ErrorCode.ERR_CallArgMixing, "b[x]").WithArguments("S.this[System.Span]", "span").WithLocation(10, 13), - // (10,15): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (10,15): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // _ = b[x]; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(10, 15), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(10, 15), // (11,9): error CS8350: This combination of arguments to 'S.this[Span]' is disallowed because it may expose variables referenced by parameter 'span' outside of their declaration scope // b[x] = x; Diagnostic(ErrorCode.ERR_CallArgMixing, "b[x]").WithArguments("S.this[System.Span]", "span").WithLocation(11, 9), - // (11,11): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (11,11): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // b[x] = x; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(11, 11)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(11, 11)); } [WorkItem(22197, "https://github.com/dotnet/roslyn/issues/22197")] @@ -2802,15 +2802,15 @@ public static void Main() } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (13,56): error CS8526: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (13,56): error CS8526: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // ref var r1 = ref (flag1 ? ref global : ref local); - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(13, 56), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(13, 56), // (13,31): error CS8525: Branches of a ref ternary operator cannot refer to variables with incompatible declaration scopes // ref var r1 = ref (flag1 ? ref global : ref local); Diagnostic(ErrorCode.ERR_MismatchedRefEscapeInTernary, "flag1 ? ref global : ref local").WithLocation(13, 31), - // (14,56): error CS8526: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (14,56): error CS8526: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // ref var r2 = ref (flag2 ? ref global : ref local); - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(14, 56), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(14, 56), // (14,31): error CS8525: Branches of a ref ternary operator cannot refer to variables with incompatible declaration scopes // ref var r2 = ref (flag2 ? ref global : ref local); Diagnostic(ErrorCode.ERR_MismatchedRefEscapeInTernary, "flag2 ? ref global : ref local").WithLocation(14, 31) @@ -2886,15 +2886,15 @@ public static void Deconstruct(this Span self, out Span x, out Span, out Span, out Span)' is disallowed because it may expose variables referenced by parameter 'x' outside of their declaration scope // (global, global) = global; Diagnostic(ErrorCode.ERR_CallArgMixing, "global").WithArguments("Extensions.Deconstruct(ref System.Span, out System.Span, out System.Span)", "x").WithLocation(8, 28) @@ -2980,9 +2980,9 @@ public static class Extensions } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (10,28): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (10,28): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // (global, global) = local; // error - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(10, 28) + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(10, 28) ); } @@ -3275,21 +3275,21 @@ public ValueTuple(T1 item1, T2 item2) // (12,36): error CS0306: The type 'Span' may not be used as a type argument // (global, global) = (local, local); // error 1 Diagnostic(ErrorCode.ERR_BadTypeArgument, "local").WithArguments("System.Span").WithLocation(12, 36), - // (12,29): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (12,29): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // (global, global) = (local, local); // error 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(12, 29), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(12, 29), // (14,24): error CS0306: The type 'Span' may not be used as a type argument // (global, s) = (local, ""); // error 2 Diagnostic(ErrorCode.ERR_BadTypeArgument, "local").WithArguments("System.Span").WithLocation(14, 24), - // (14,24): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (14,24): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // (global, s) = (local, ""); // error 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(14, 24), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(14, 24), // (15,24): error CS0306: The type 'Span' may not be used as a type argument // (global, s) = (local, null); // error 3 Diagnostic(ErrorCode.ERR_BadTypeArgument, "local").WithArguments("System.Span").WithLocation(15, 24), - // (15,24): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (15,24): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // (global, s) = (local, null); // error 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(15, 24), + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(15, 24), // (17,23): error CS0306: The type 'Span' may not be used as a type argument // (local, s) = (global, ""); // error 4 Diagnostic(ErrorCode.ERR_BadTypeArgument, "global").WithArguments("System.Span").WithLocation(17, 23), @@ -3360,12 +3360,12 @@ public static class Extensions } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (10,18): error CS8352: Cannot use local 'local1' in this context because it may expose referenced variables outside of their declaration scope + // (10,18): error CS8352: Cannot use variable 'local1' in this context because it may expose referenced variables outside of their declaration scope // global = local1; // error 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "local1").WithArguments("local1").WithLocation(10, 18), - // (11,18): error CS8352: Cannot use local 'local2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "local1").WithArguments("local1").WithLocation(10, 18), + // (11,18): error CS8352: Cannot use variable 'local2' in this context because it may expose referenced variables outside of their declaration scope // global = local2; // error 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "local2").WithArguments("local2").WithLocation(11, 18) + Diagnostic(ErrorCode.ERR_EscapeVariable, "local2").WithArguments("local2").WithLocation(11, 18) ); } @@ -3397,9 +3397,9 @@ public ref struct S } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (11,22): error CS8352: Cannot use local 'local' in this context because it may expose referenced variables outside of their declaration scope + // (11,22): error CS8352: Cannot use variable 'local' in this context because it may expose referenced variables outside of their declaration scope // global = local; // error - Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(11, 22) + Diagnostic(ErrorCode.ERR_EscapeVariable, "local").WithArguments("local").WithLocation(11, 22) ); } @@ -3433,12 +3433,12 @@ public ref struct S } "; CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (11,22): error CS8352: Cannot use local 'local1' in this context because it may expose referenced variables outside of their declaration scope + // (11,22): error CS8352: Cannot use variable 'local1' in this context because it may expose referenced variables outside of their declaration scope // global = local1; // error 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "local1").WithArguments("local1").WithLocation(11, 22), - // (12,22): error CS8352: Cannot use local 'local2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "local1").WithArguments("local1").WithLocation(11, 22), + // (12,22): error CS8352: Cannot use variable 'local2' in this context because it may expose referenced variables outside of their declaration scope // global = local2; // error 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "local2").WithArguments("local2").WithLocation(12, 22) + Diagnostic(ErrorCode.ERR_EscapeVariable, "local2").WithArguments("local2").WithLocation(12, 22) ); } @@ -3470,9 +3470,9 @@ public ref struct S // Tracking issue: https://github.com/dotnet/roslyn/issues/22361 CreateCompilationWithMscorlibAndSpan(text).VerifyDiagnostics( - // (9,9): error CS8352: Cannot use local 'local1' in this context because it may expose referenced variables outside of their declaration scope + // (9,9): error CS8352: Cannot use variable 'local1' in this context because it may expose referenced variables outside of their declaration scope // local1.M(out S local2); - Diagnostic(ErrorCode.ERR_EscapeLocal, "local1").WithArguments("local1").WithLocation(9, 9) + Diagnostic(ErrorCode.ERR_EscapeVariable, "local1").WithArguments("local1").WithLocation(9, 9) ); } @@ -3900,9 +3900,9 @@ Span M() return null ?? x; } }", options: TestOptions.ReleaseDll).VerifyDiagnostics( - // (8,24): error CS8352: Cannot use local 'x' in this context because it may expose referenced variables outside of their declaration scope + // (8,24): error CS8352: Cannot use variable 'x' in this context because it may expose referenced variables outside of their declaration scope // return null ?? x; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("x").WithLocation(8, 24) + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("x").WithLocation(8, 24) ); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index e851f58d48937..9fe48bb488305 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -418,9 +418,14 @@ public void FixedField_01() public fixed ref int F1[3]; public fixed ref readonly int F2[3]; }"; - // PROTOTYPE: `fixed ref` field declaration should be disallowed. var comp = CreateCompilation(source, options: TestOptions.UnsafeReleaseDll); - comp.VerifyEmitDiagnostics(); + comp.VerifyEmitDiagnostics( + // (3,26): error CS9049: A fixed field must not be a ref field. + // public fixed ref int F1[3]; + Diagnostic(ErrorCode.ERR_FixedFieldMustNotBeRef, "F1").WithLocation(3, 26), + // (4,35): error CS9049: A fixed field must not be a ref field. + // public fixed ref readonly int F2[3]; + Diagnostic(ErrorCode.ERR_FixedFieldMustNotBeRef, "F2").WithLocation(4, 35)); } [Fact] @@ -451,9 +456,86 @@ unsafe static void Main() Console.WriteLine(s.F[1]); } }"; - // PROTOTYPE: `fixed ref` field use should be disallowed. var comp = CreateCompilation(sourceB, references: new[] { refA }, options: TestOptions.UnsafeReleaseExe); - comp.VerifyEmitDiagnostics(); + comp.VerifyEmitDiagnostics( + // (7,29): error CS0570: 'S.F' is not supported by the language + // Console.WriteLine(s.F[1]); + Diagnostic(ErrorCode.ERR_BindToBogus, "F").WithArguments("S.F").WithLocation(7, 29)); + } + + [Fact] + public void Volatile() + { + var sourceA = +@".class public sealed R extends [mscorlib]System.ValueType +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = (01 00 00 00) + .field public int32& modreq([mscorlib]System.Runtime.CompilerServices.IsVolatile) F1 + .field public int32 modreq([mscorlib]System.Runtime.CompilerServices.IsVolatile)& F2 +}"; + var refA = CompileIL(sourceA); + + var sourceB = +@"using System; +class Program +{ + static void Main() + { + var r = new R(); + Console.WriteLine(r.F1); + Console.WriteLine(r.F2); + } +}"; + var comp = CreateCompilation(sourceB, references: new[] { refA }); + comp.VerifyEmitDiagnostics( + // (7,29): error CS0570: 'R.F1' is not supported by the language + // Console.WriteLine(r.F1); + Diagnostic(ErrorCode.ERR_BindToBogus, "F1").WithArguments("R.F1").WithLocation(7, 29), + // (8,29): error CS0570: 'R.F2' is not supported by the language + // Console.WriteLine(r.F2); + Diagnostic(ErrorCode.ERR_BindToBogus, "F2").WithArguments("R.F2").WithLocation(8, 29)); + } + + [Fact] + public void Modifiers() + { + var source = +@"#pragma warning disable 0169 +ref struct R +{ + static ref int _s1; + static ref readonly int _s2; + const ref int _c1 = default; + const ref readonly int _c2 = default; + volatile ref int _v1; + volatile ref readonly int _v2; +}"; + var comp = CreateCompilation(source); + comp.VerifyEmitDiagnostics( + // (4,20): error CS0106: The modifier 'static' is not valid for this item + // static ref int _s1; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "_s1").WithArguments("static").WithLocation(4, 20), + // (5,29): error CS0106: The modifier 'static' is not valid for this item + // static ref readonly int _s2; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "_s2").WithArguments("static").WithLocation(5, 29), + // (6,19): error CS0106: The modifier 'static' is not valid for this item + // const ref int _c1 = default; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "_c1").WithArguments("static").WithLocation(6, 19), + // (6,19): error CS0106: The modifier 'const' is not valid for this item + // const ref int _c1 = default; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "_c1").WithArguments("const").WithLocation(6, 19), + // (7,28): error CS0106: The modifier 'static' is not valid for this item + // const ref readonly int _c2 = default; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "_c2").WithArguments("static").WithLocation(7, 28), + // (7,28): error CS0106: The modifier 'const' is not valid for this item + // const ref readonly int _c2 = default; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "_c2").WithArguments("const").WithLocation(7, 28), + // (8,22): error CS0106: The modifier 'volatile' is not valid for this item + // volatile ref int _v1; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "_v1").WithArguments("volatile").WithLocation(8, 22), + // (9,31): error CS0106: The modifier 'volatile' is not valid for this item + // volatile ref readonly int _v2; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "_v2").WithArguments("volatile").WithLocation(9, 31)); } /// @@ -674,6 +756,7 @@ private static void VerifyFieldSymbol(FieldSymbol field, string expectedDisplayS Assert.Equal(expectedDisplayString, field.ToTestDisplayString()); } + [WorkItem(62131, "https://github.com/dotnet/roslyn/issues/62131")] [CombinatorialData] [Theory] public void RuntimeFeature(bool useCompilationReference) @@ -730,10 +813,15 @@ static ref T F(R r) Assert.False(comp.Assembly.RuntimeSupportsByRefFields); comp = CreateEmptyCompilation(source, references: new[] { refAB }, parseOptions: TestOptions.Regular10); + // https://github.com/dotnet/roslyn/issues/62131: Enable updated escape rules if + // System.Runtime.CompilerServices.RuntimeFeature.ByRefFields exists. comp.VerifyDiagnostics( // (3,12): error CS8652: The feature 'ref fields' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // public ref T F; - Diagnostic(ErrorCode.ERR_FeatureInPreview, "ref T").WithArguments("ref fields").WithLocation(3, 12)); + Diagnostic(ErrorCode.ERR_FeatureInPreview, "ref T").WithArguments("ref fields").WithLocation(3, 12), + // (10,20): error CS8167: Cannot return by reference a member of parameter 'r' because it is not a ref or out parameter + // return ref r.F; + Diagnostic(ErrorCode.ERR_RefReturnParameter2, "r").WithArguments("r").WithLocation(10, 20)); Assert.True(comp.Assembly.RuntimeSupportsByRefFields); comp = CreateEmptyCompilation(source, references: new[] { refA }); @@ -783,9 +871,9 @@ static ref T F2(T t) var expectedUpdatedDiagnostics = new DiagnosticDescription[] { - // (13,20): error CS8352: Cannot use local 'r2' in this context because it may expose referenced variables outside of their declaration scope + // (13,20): error CS8352: Cannot use variable 'r2' in this context because it may expose referenced variables outside of their declaration scope // return ref r2.F; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r2.F").WithArguments("r2").WithLocation(13, 20), + Diagnostic(ErrorCode.ERR_EscapeVariable, "r2.F").WithArguments("r2").WithLocation(13, 20), }; var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); @@ -896,16 +984,15 @@ class Program { }; - // PROTOTYPE: Update ERR_RefReturnParameter message or report a distinct error, because the parameter is an 'out' parameter. var expectedUpdatedDiagnostics = new DiagnosticDescription[] { - // (12,56): error CS8166: Cannot return a parameter by reference 'c' because it is not a ref or out parameter + // (12,56): error CS8166: Cannot return a parameter by reference 'c' because it is not a ref parameter // static ref C F7(out C c) { c = default; return ref c; } // 1 Diagnostic(ErrorCode.ERR_RefReturnParameter, "c").WithArguments("c").WithLocation(12, 56), - // (13,56): error CS8166: Cannot return a parameter by reference 's' because it is not a ref or out parameter + // (13,56): error CS8166: Cannot return a parameter by reference 's' because it is not a ref parameter // static ref S F8(out S s) { s = default; return ref s; } // 2 Diagnostic(ErrorCode.ERR_RefReturnParameter, "s").WithArguments("s").WithLocation(13, 56), - // (14,56): error CS8166: Cannot return a parameter by reference 'r' because it is not a ref or out parameter + // (14,56): error CS8166: Cannot return a parameter by reference 'r' because it is not a ref parameter // static ref R F9(out R r) { r = default; return ref r; } // 3 Diagnostic(ErrorCode.ERR_RefReturnParameter, "r").WithArguments("r").WithLocation(14, 56) }; @@ -1019,19 +1106,19 @@ class Program // (24,75): error CS8347: Cannot use a result of 'S.F1(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // static ref T F31(out T t) { S s = default; t = default; return ref s.F1(ref t); } // 4 Diagnostic(ErrorCode.ERR_EscapeCall, "s.F1(ref t)").WithArguments("S.F1(ref T)", "t").WithLocation(24, 75), - // (24,84): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (24,84): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static ref T F31(out T t) { S s = default; t = default; return ref s.F1(ref t); } // 4 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(24, 84), // (25,75): error CS8347: Cannot use a result of 'S.F2(in T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // static ref T F32(out T t) { S s = default; t = default; return ref s.F2(in t); } // 5 Diagnostic(ErrorCode.ERR_EscapeCall, "s.F2(in t)").WithArguments("S.F2(in T)", "t").WithLocation(25, 75), - // (25,83): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (25,83): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static ref T F32(out T t) { S s = default; t = default; return ref s.F2(in t); } // 5 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(25, 83), // (26,75): error CS8347: Cannot use a result of 'S.F2(in T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // static ref T F33(out T t) { S s = default; t = default; return ref s.F2(t); } // 6 Diagnostic(ErrorCode.ERR_EscapeCall, "s.F2(t)").WithArguments("S.F2(in T)", "t").WithLocation(26, 75), - // (26,80): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (26,80): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static ref T F33(out T t) { S s = default; t = default; return ref s.F2(t); } // 6 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(26, 80), // (29,61): error CS8347: Cannot use a result of 'S.F1(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope @@ -1137,19 +1224,19 @@ public void MethodInvocation_Lvalue_02() // (22,53): error CS8347: Cannot use a result of 'C.F1(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // ref T F31(out T t) { t = default; return ref F1(ref t); } // 4 Diagnostic(ErrorCode.ERR_EscapeCall, "F1(ref t)").WithArguments("C.F1(ref T)", "t").WithLocation(22, 53), - // (22,60): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (22,60): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // ref T F31(out T t) { t = default; return ref F1(ref t); } // 4 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(22, 60), // (23,53): error CS8347: Cannot use a result of 'C.F2(in T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // ref T F32(out T t) { t = default; return ref F2(in t); } // 5 Diagnostic(ErrorCode.ERR_EscapeCall, "F2(in t)").WithArguments("C.F2(in T)", "t").WithLocation(23, 53), - // (23,59): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (23,59): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // ref T F32(out T t) { t = default; return ref F2(in t); } // 5 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(23, 59), // (24,53): error CS8347: Cannot use a result of 'C.F2(in T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // ref T F33(out T t) { t = default; return ref F2(t); } // 6 Diagnostic(ErrorCode.ERR_EscapeCall, "F2(t)").WithArguments("C.F2(in T)", "t").WithLocation(24, 53), - // (24,56): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (24,56): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // ref T F33(out T t) { t = default; return ref F2(t); } // 6 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(24, 56) }; @@ -1713,19 +1800,19 @@ class Program // (27,70): error CS8347: Cannot use a result of 'S.F1(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // static R F31(out T t) { S s = default; t = default; return s.F1(ref t); } // 4 Diagnostic(ErrorCode.ERR_EscapeCall, "s.F1(ref t)").WithArguments("S.F1(ref T)", "t").WithLocation(27, 70), - // (27,79): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (27,79): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static R F31(out T t) { S s = default; t = default; return s.F1(ref t); } // 4 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(27, 79), // (28,70): error CS8347: Cannot use a result of 'S.F2(in T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // static R F32(out T t) { S s = default; t = default; return s.F2(in t); } // 5 Diagnostic(ErrorCode.ERR_EscapeCall, "s.F2(in t)").WithArguments("S.F2(in T)", "t").WithLocation(28, 70), - // (28,78): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (28,78): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static R F32(out T t) { S s = default; t = default; return s.F2(in t); } // 5 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(28, 78), // (29,70): error CS8347: Cannot use a result of 'S.F2(in T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // static R F33(out T t) { S s = default; t = default; return s.F2(t); } // 6 Diagnostic(ErrorCode.ERR_EscapeCall, "s.F2(t)").WithArguments("S.F2(in T)", "t").WithLocation(29, 70), - // (29,75): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (29,75): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static R F33(out T t) { S s = default; t = default; return s.F2(t); } // 6 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(29, 75), // (32,56): error CS8347: Cannot use a result of 'S.F1(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope @@ -1816,19 +1903,19 @@ class C // (25,45): error CS8347: Cannot use a result of 'C.F1(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // R F31(out T t) { t = default; return F1(ref t); } // 4 Diagnostic(ErrorCode.ERR_EscapeCall, "F1(ref t)").WithArguments("C.F1(ref T)", "t").WithLocation(25, 45), - // (25,52): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (25,52): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // R F31(out T t) { t = default; return F1(ref t); } // 4 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(25, 52), // (26,45): error CS8347: Cannot use a result of 'C.F2(in T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // R F32(out T t) { t = default; return F2(in t); } // 5 Diagnostic(ErrorCode.ERR_EscapeCall, "F2(in t)").WithArguments("C.F2(in T)", "t").WithLocation(26, 45), - // (26,51): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (26,51): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // R F32(out T t) { t = default; return F2(in t); } // 5 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(26, 51), // (27,45): error CS8347: Cannot use a result of 'C.F2(in T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // R F33(out T t) { t = default; return F2(t); } // 6 Diagnostic(ErrorCode.ERR_EscapeCall, "F2(t)").WithArguments("C.F2(in T)", "t").WithLocation(27, 45), - // (27,48): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (27,48): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // R F33(out T t) { t = default; return F2(t); } // 6 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(27, 48) }; @@ -2073,43 +2160,43 @@ ref struct R { } // (17,75): error CS8350: This combination of arguments to 'Program.F0(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'x' outside of their declaration scope // static ref T F10(ref scoped R x) { R y = default; return ref F0(ref x, ref y); } // 2 Diagnostic(ErrorCode.ERR_CallArgMixing, "F0(ref x, ref y)").WithArguments("Program.F0(ref R, ref R)", "x").WithLocation(17, 75), - // (17,82): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (17,82): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static ref T F10(ref scoped R x) { R y = default; return ref F0(ref x, ref y); } // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(17, 82), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(17, 82), // (18,75): error CS8347: Cannot use a result of 'Program.F1(ref R, ref R)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // static ref T F11(ref scoped R x) { R y = default; return ref F1(ref x, ref y); } // 3 Diagnostic(ErrorCode.ERR_EscapeCall, "F1(ref x, ref y)").WithArguments("Program.F1(ref R, ref R)", "x").WithLocation(18, 75), - // (18,82): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (18,82): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // static ref T F11(ref scoped R x) { R y = default; return ref F1(ref x, ref y); } // 3 Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(18, 82), // (19,75): error CS8350: This combination of arguments to 'Program.F2(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'x' outside of their declaration scope // static ref T F12(ref scoped R x) { R y = default; return ref F2(ref x, ref y); } // 4 Diagnostic(ErrorCode.ERR_CallArgMixing, "F2(ref x, ref y)").WithArguments("Program.F2(ref R, ref R)", "x").WithLocation(19, 75), - // (19,82): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (19,82): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static ref T F12(ref scoped R x) { R y = default; return ref F2(ref x, ref y); } // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(19, 82), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(19, 82), // (22,75): error CS8350: This combination of arguments to 'Program.F5(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'x' outside of their declaration scope // static ref T F15(ref scoped R x) { R y = default; return ref F5(ref x, ref y); } // 5 Diagnostic(ErrorCode.ERR_CallArgMixing, "F5(ref x, ref y)").WithArguments("Program.F5(ref R, ref R)", "x").WithLocation(22, 75), - // (22,82): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (22,82): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static ref T F15(ref scoped R x) { R y = default; return ref F5(ref x, ref y); } // 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(22, 82), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(22, 82), // (24,75): error CS8347: Cannot use a result of 'Program.F0(ref R, ref R)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // static ref T F20(scoped ref R x) { R y = default; return ref F0(ref x, ref y); } // 6 Diagnostic(ErrorCode.ERR_EscapeCall, "F0(ref x, ref y)").WithArguments("Program.F0(ref R, ref R)", "x").WithLocation(24, 75), - // (24,82): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (24,82): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // static ref T F20(scoped ref R x) { R y = default; return ref F0(ref x, ref y); } // 6 Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(24, 82), // (25,75): error CS8347: Cannot use a result of 'Program.F1(ref R, ref R)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // static ref T F21(scoped ref R x) { R y = default; return ref F1(ref x, ref y); } // 7 Diagnostic(ErrorCode.ERR_EscapeCall, "F1(ref x, ref y)").WithArguments("Program.F1(ref R, ref R)", "x").WithLocation(25, 75), - // (25,82): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (25,82): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // static ref T F21(scoped ref R x) { R y = default; return ref F1(ref x, ref y); } // 7 Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(25, 82), // (26,75): error CS8347: Cannot use a result of 'Program.F2(ref R, ref R)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // static ref T F22(scoped ref R x) { R y = default; return ref F2(ref x, ref y); } // 8 Diagnostic(ErrorCode.ERR_EscapeCall, "F2(ref x, ref y)").WithArguments("Program.F2(ref R, ref R)", "x").WithLocation(26, 75), - // (26,82): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (26,82): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // static ref T F22(scoped ref R x) { R y = default; return ref F2(ref x, ref y); } // 8 Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(26, 82)); } @@ -2141,21 +2228,21 @@ class Program // (11,61): error CS8347: Cannot use a result of 'Program.F0(R, R)' in this context because it may expose variables referenced by parameter 'y' outside of their declaration scope // static R F00(R x, int i) { var y = new R(ref i); return F0(x, y); } // 1 Diagnostic(ErrorCode.ERR_EscapeCall, "F0(x, y)").WithArguments("Program.F0(R, R)", "y").WithLocation(11, 61), - // (11,67): error CS8352: Cannot use local 'y' in this context because it may expose referenced variables outside of their declaration scope + // (11,67): error CS8352: Cannot use variable 'y' in this context because it may expose referenced variables outside of their declaration scope // static R F00(R x, int i) { var y = new R(ref i); return F0(x, y); } // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("y").WithLocation(11, 67), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("y").WithLocation(11, 67), // (15,68): error CS8347: Cannot use a result of 'Program.F0(R, R)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // static R F10(scoped R x, int i) { var y = new R(ref i); return F0(x, y); } // 2 Diagnostic(ErrorCode.ERR_EscapeCall, "F0(x, y)").WithArguments("Program.F0(R, R)", "x").WithLocation(15, 68), - // (15,71): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + // (15,71): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // static R F10(scoped R x, int i) { var y = new R(ref i); return F0(x, y); } // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("R").WithLocation(15, 71), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("R").WithLocation(15, 71), // (16,68): error CS8347: Cannot use a result of 'Program.F1(R, R)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // static R F11(scoped R x, int i) { var y = new R(ref i); return F1(x, y); } // 3 Diagnostic(ErrorCode.ERR_EscapeCall, "F1(x, y)").WithArguments("Program.F1(R, R)", "x").WithLocation(16, 68), - // (16,71): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + // (16,71): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // static R F11(scoped R x, int i) { var y = new R(ref i); return F1(x, y); } // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("R").WithLocation(16, 71)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("R").WithLocation(16, 71)); } [Fact] @@ -2213,39 +2300,39 @@ class Program // (13,48): error CS8350: This combination of arguments to 'R.F0(ref R)' is disallowed because it may expose variables referenced by parameter 'r' outside of their declaration scope // static void F10(ref R x, ref scoped R y) { x.F0(ref y); } // 1 Diagnostic(ErrorCode.ERR_CallArgMixing, "x.F0(ref y)").WithArguments("R.F0(ref R)", "r").WithLocation(13, 48), - // (13,57): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (13,57): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F10(ref R x, ref scoped R y) { x.F0(ref y); } // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(13, 57), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(13, 57), // (15,48): error CS8350: This combination of arguments to 'R.F2(ref R)' is disallowed because it may expose variables referenced by parameter 'r' outside of their declaration scope // static void F12(ref R x, ref scoped R y) { x.F2(ref y); } // 2 Diagnostic(ErrorCode.ERR_CallArgMixing, "x.F2(ref y)").WithArguments("R.F2(ref R)", "r").WithLocation(15, 48), - // (15,57): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (15,57): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F12(ref R x, ref scoped R y) { x.F2(ref y); } // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(15, 57), - // (21,48): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(15, 57), + // (21,48): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F30(ref scoped R x, ref R y) { x.F0(ref y); } // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(21, 48), - // (23,48): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(21, 48), + // (23,48): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F32(ref scoped R x, ref R y) { x.F2(ref y); } // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(23, 48), - // (29,55): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(23, 48), + // (29,55): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F50(ref scoped R x, scoped ref R y) { x.F0(ref y); } // 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(29, 55), - // (31,55): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(29, 55), + // (31,55): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F52(ref scoped R x, scoped ref R y) { x.F2(ref y); } // 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(31, 55), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(31, 55), // (37,55): error CS8350: This combination of arguments to 'R.F0(ref R)' is disallowed because it may expose variables referenced by parameter 'r' outside of their declaration scope // static void F70(scoped ref R x, ref scoped R y) { x.F0(ref y); } // 7 Diagnostic(ErrorCode.ERR_CallArgMixing, "x.F0(ref y)").WithArguments("R.F0(ref R)", "r").WithLocation(37, 55), - // (37,64): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (37,64): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F70(scoped ref R x, ref scoped R y) { x.F0(ref y); } // 7 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(37, 64), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(37, 64), // (39,55): error CS8350: This combination of arguments to 'R.F2(ref R)' is disallowed because it may expose variables referenced by parameter 'r' outside of their declaration scope // static void F72(scoped ref R x, ref scoped R y) { x.F2(ref y); } // 8 Diagnostic(ErrorCode.ERR_CallArgMixing, "x.F2(ref y)").WithArguments("R.F2(ref R)", "r").WithLocation(39, 55), - // (39,64): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (39,64): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F72(scoped ref R x, ref scoped R y) { x.F2(ref y); } // 8 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(39, 64)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(39, 64)); } [Fact] @@ -2311,39 +2398,39 @@ class Program // (20,48): error CS8350: This combination of arguments to 'Program.F0(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'b' outside of their declaration scope // static void F10(ref R x, ref scoped R y) { F0(ref x, ref y); } // 1 Diagnostic(ErrorCode.ERR_CallArgMixing, "F0(ref x, ref y)").WithArguments("Program.F0(ref R, ref R)", "b").WithLocation(20, 48), - // (20,62): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (20,62): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F10(ref R x, ref scoped R y) { F0(ref x, ref y); } // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(20, 62), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(20, 62), // (22,48): error CS8350: This combination of arguments to 'Program.F2(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'b' outside of their declaration scope // static void F12(ref R x, ref scoped R y) { F2(ref x, ref y); } // 2 Diagnostic(ErrorCode.ERR_CallArgMixing, "F2(ref x, ref y)").WithArguments("Program.F2(ref R, ref R)", "b").WithLocation(22, 48), - // (22,62): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (22,62): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F12(ref R x, ref scoped R y) { F2(ref x, ref y); } // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(22, 62), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(22, 62), // (25,48): error CS8350: This combination of arguments to 'Program.F5(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'b' outside of their declaration scope // static void F15(ref R x, ref scoped R y) { F5(ref x, ref y); } // 3 Diagnostic(ErrorCode.ERR_CallArgMixing, "F5(ref x, ref y)").WithArguments("Program.F5(ref R, ref R)", "b").WithLocation(25, 48), - // (25,62): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (25,62): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F15(ref R x, ref scoped R y) { F5(ref x, ref y); } // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(25, 62), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(25, 62), // (41,55): error CS8350: This combination of arguments to 'Program.F0(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'a' outside of their declaration scope // static void F40(ref scoped R x, scoped ref R y) { F0(ref x, ref y); } // 4 Diagnostic(ErrorCode.ERR_CallArgMixing, "F0(ref x, ref y)").WithArguments("Program.F0(ref R, ref R)", "a").WithLocation(41, 55), - // (41,62): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (41,62): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F40(ref scoped R x, scoped ref R y) { F0(ref x, ref y); } // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(41, 62), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(41, 62), // (43,55): error CS8350: This combination of arguments to 'Program.F2(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'a' outside of their declaration scope // static void F42(ref scoped R x, scoped ref R y) { F2(ref x, ref y); } // 5 Diagnostic(ErrorCode.ERR_CallArgMixing, "F2(ref x, ref y)").WithArguments("Program.F2(ref R, ref R)", "a").WithLocation(43, 55), - // (43,62): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (43,62): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F42(ref scoped R x, scoped ref R y) { F2(ref x, ref y); } // 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(43, 62), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(43, 62), // (46,55): error CS8350: This combination of arguments to 'Program.F5(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'a' outside of their declaration scope // static void F45(ref scoped R x, scoped ref R y) { F5(ref x, ref y); } // 6 Diagnostic(ErrorCode.ERR_CallArgMixing, "F5(ref x, ref y)").WithArguments("Program.F5(ref R, ref R)", "a").WithLocation(46, 55), - // (46,62): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (46,62): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F45(ref scoped R x, scoped ref R y) { F5(ref x, ref y); } // 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(46, 62)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(46, 62)); } [Fact] @@ -2402,39 +2489,39 @@ static void F(ref R x) // (26,9): error CS8350: This combination of arguments to 'Program.F0(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'b' outside of their declaration scope // F0(ref x, ref y); // 1 Diagnostic(ErrorCode.ERR_CallArgMixing, "F0(ref x, ref y)").WithArguments("Program.F0(ref R, ref R)", "b").WithLocation(26, 9), - // (26,23): error CS8352: Cannot use local 'y' in this context because it may expose referenced variables outside of their declaration scope + // (26,23): error CS8352: Cannot use variable 'y' in this context because it may expose referenced variables outside of their declaration scope // F0(ref x, ref y); // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("y").WithLocation(26, 23), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("y").WithLocation(26, 23), // (28,9): error CS8350: This combination of arguments to 'Program.F2(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'b' outside of their declaration scope // F2(ref x, ref y); // 2 Diagnostic(ErrorCode.ERR_CallArgMixing, "F2(ref x, ref y)").WithArguments("Program.F2(ref R, ref R)", "b").WithLocation(28, 9), - // (28,23): error CS8352: Cannot use local 'y' in this context because it may expose referenced variables outside of their declaration scope + // (28,23): error CS8352: Cannot use variable 'y' in this context because it may expose referenced variables outside of their declaration scope // F2(ref x, ref y); // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("y").WithLocation(28, 23), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("y").WithLocation(28, 23), // (31,9): error CS8350: This combination of arguments to 'Program.F5(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'b' outside of their declaration scope // F5(ref x, ref y); // 3 Diagnostic(ErrorCode.ERR_CallArgMixing, "F5(ref x, ref y)").WithArguments("Program.F5(ref R, ref R)", "b").WithLocation(31, 9), - // (31,23): error CS8352: Cannot use local 'y' in this context because it may expose referenced variables outside of their declaration scope + // (31,23): error CS8352: Cannot use variable 'y' in this context because it may expose referenced variables outside of their declaration scope // F5(ref x, ref y); // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("y").WithLocation(31, 23), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("y").WithLocation(31, 23), // (33,9): error CS8350: This combination of arguments to 'Program.F0(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'a' outside of their declaration scope // F0(ref y, ref x); // 4 Diagnostic(ErrorCode.ERR_CallArgMixing, "F0(ref y, ref x)").WithArguments("Program.F0(ref R, ref R)", "a").WithLocation(33, 9), - // (33,16): error CS8352: Cannot use local 'y' in this context because it may expose referenced variables outside of their declaration scope + // (33,16): error CS8352: Cannot use variable 'y' in this context because it may expose referenced variables outside of their declaration scope // F0(ref y, ref x); // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("y").WithLocation(33, 16), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("y").WithLocation(33, 16), // (35,9): error CS8350: This combination of arguments to 'Program.F2(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'a' outside of their declaration scope // F2(ref y, ref x); // 5 Diagnostic(ErrorCode.ERR_CallArgMixing, "F2(ref y, ref x)").WithArguments("Program.F2(ref R, ref R)", "a").WithLocation(35, 9), - // (35,16): error CS8352: Cannot use local 'y' in this context because it may expose referenced variables outside of their declaration scope + // (35,16): error CS8352: Cannot use variable 'y' in this context because it may expose referenced variables outside of their declaration scope // F2(ref y, ref x); // 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("y").WithLocation(35, 16), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("y").WithLocation(35, 16), // (38,9): error CS8350: This combination of arguments to 'Program.F5(ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'a' outside of their declaration scope // F5(ref y, ref x); // 6 Diagnostic(ErrorCode.ERR_CallArgMixing, "F5(ref y, ref x)").WithArguments("Program.F5(ref R, ref R)", "a").WithLocation(38, 9), - // (38,16): error CS8352: Cannot use local 'y' in this context because it may expose referenced variables outside of their declaration scope + // (38,16): error CS8352: Cannot use variable 'y' in this context because it may expose referenced variables outside of their declaration scope // F5(ref y, ref x); // 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("y").WithLocation(38, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("y").WithLocation(38, 16)); } [Fact] @@ -2443,6 +2530,82 @@ public void MethodArgumentsMustMatch_04() var source = @"ref struct R { } class Program +{ + static void F0(ref R x, in R y) => throw null; + static void F1(ref R x, in scoped R y) => throw null; + static void F2(ref R x, scoped in R y) => throw null; + + static void F00(ref R x, in R y) { F0(ref x, in y); } + static void F01(ref R x, in R y) { F1(ref x, in y); } + static void F02(ref R x, in R y) { F2(ref x, in y); } + static void F10(ref R x, in scoped R y) { F0(ref x, in y); } // 1 + static void F11(ref R x, in scoped R y) { F1(ref x, in y); } + static void F12(ref R x, in scoped R y) { F2(ref x, in y); } // 2 + static void F20(ref R x, scoped in R y) { F0(ref x, in y); } + static void F21(ref R x, scoped in R y) { F1(ref x, in y); } + static void F22(ref R x, scoped in R y) { F2(ref x, in y); } +}"; + var comp = CreateCompilation(source); + comp.VerifyEmitDiagnostics( + // (11,47): error CS8350: This combination of arguments to 'Program.F0(ref R, in R)' is disallowed because it may expose variables referenced by parameter 'y' outside of their declaration scope + // static void F10(ref R x, in scoped R y) { F0(ref x, in y); } // 1 + Diagnostic(ErrorCode.ERR_CallArgMixing, "F0(ref x, in y)").WithArguments("Program.F0(ref R, in R)", "y").WithLocation(11, 47), + // (11,60): error CS8352: Cannot use variable 'in R' in this context because it may expose referenced variables outside of their declaration scope + // static void F10(ref R x, in scoped R y) { F0(ref x, in y); } // 1 + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("in R").WithLocation(11, 60), + // (13,47): error CS8350: This combination of arguments to 'Program.F2(ref R, in R)' is disallowed because it may expose variables referenced by parameter 'y' outside of their declaration scope + // static void F12(ref R x, in scoped R y) { F2(ref x, in y); } // 2 + Diagnostic(ErrorCode.ERR_CallArgMixing, "F2(ref x, in y)").WithArguments("Program.F2(ref R, in R)", "y").WithLocation(13, 47), + // (13,60): error CS8352: Cannot use variable 'in R' in this context because it may expose referenced variables outside of their declaration scope + // static void F12(ref R x, in scoped R y) { F2(ref x, in y); } // 2 + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("in R").WithLocation(13, 60)); + } + + [Fact] + public void MethodArgumentsMustMatch_05() + { + var source = +@"ref struct R { } +class Program +{ + static void F0(ref R x, out R y) => throw null; + static void F1(ref R x, out scoped R y) => throw null; + static void F2(ref R x, scoped out R y) => throw null; + + static void F00(ref R x, out R y) { F0(ref x, out y); } + static void F01(ref R x, out R y) { F1(ref x, out y); } + static void F02(ref R x, out R y) { F2(ref x, out y); } + static void F10(ref R x, out scoped R y) { F0(ref x, out y); } // 1 + static void F11(ref R x, out scoped R y) { F1(ref x, out y); } + static void F12(ref R x, out scoped R y) { F2(ref x, out y); } // 2 + static void F20(ref R x, scoped out R y) { F0(ref x, out y); } + static void F21(ref R x, scoped out R y) { F1(ref x, out y); } + static void F22(ref R x, scoped out R y) { F2(ref x, out y); } +}"; + var comp = CreateCompilation(source); + // https://github.com/dotnet/roslyn/issues/62094: References within out parameter + // should not be considered escaping. + comp.VerifyEmitDiagnostics( + // (11,48): error CS8350: This combination of arguments to 'Program.F0(ref R, out R)' is disallowed because it may expose variables referenced by parameter 'y' outside of their declaration scope + // static void F10(ref R x, out scoped R y) { F0(ref x, out y); } // 1 + Diagnostic(ErrorCode.ERR_CallArgMixing, "F0(ref x, out y)").WithArguments("Program.F0(ref R, out R)", "y").WithLocation(11, 48), + // (11,62): error CS8352: Cannot use variable 'out R' in this context because it may expose referenced variables outside of their declaration scope + // static void F10(ref R x, out scoped R y) { F0(ref x, out y); } // 1 + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("out R").WithLocation(11, 62), + // (13,48): error CS8350: This combination of arguments to 'Program.F2(ref R, out R)' is disallowed because it may expose variables referenced by parameter 'y' outside of their declaration scope + // static void F12(ref R x, out scoped R y) { F2(ref x, out y); } // 2 + Diagnostic(ErrorCode.ERR_CallArgMixing, "F2(ref x, out y)").WithArguments("Program.F2(ref R, out R)", "y").WithLocation(13, 48), + // (13,62): error CS8352: Cannot use variable 'out R' in this context because it may expose referenced variables outside of their declaration scope + // static void F12(ref R x, out scoped R y) { F2(ref x, out y); } // 2 + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("out R").WithLocation(13, 62)); + } + + [Fact] + public void MethodArgumentsMustMatch_06() + { + var source = +@"ref struct R { } +class Program { static void F0(__arglist) { } static void F1(ref R a, __arglist) { } @@ -2465,31 +2628,29 @@ static void F1(ref R a, __arglist) { } // (9,48): error CS8350: This combination of arguments to 'Program.F0(__arglist)' is disallowed because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // static void F10(ref R x, ref scoped R y) { F0(__arglist(ref x, ref y)); } // 1 Diagnostic(ErrorCode.ERR_CallArgMixing, "F0(__arglist(ref x, ref y))").WithArguments("Program.F0(__arglist)", "__arglist").WithLocation(9, 48), - // (9,72): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (9,72): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F10(ref R x, ref scoped R y) { F0(__arglist(ref x, ref y)); } // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(9, 72), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(9, 72), // (10,48): error CS8350: This combination of arguments to 'Program.F1(ref R, __arglist)' is disallowed because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // static void F11(ref R x, ref scoped R y) { F1(ref x, __arglist(ref y)); } // 2 Diagnostic(ErrorCode.ERR_CallArgMixing, "F1(ref x, __arglist(ref y))").WithArguments("Program.F1(ref R, __arglist)", "__arglist").WithLocation(10, 48), - // (10,72): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (10,72): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F11(ref R x, ref scoped R y) { F1(ref x, __arglist(ref y)); } // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(10, 72), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(10, 72), // (15,55): error CS8350: This combination of arguments to 'Program.F0(__arglist)' is disallowed because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // static void F40(ref scoped R x, scoped ref R y) { F0(__arglist(ref x, ref y)); } // 3 Diagnostic(ErrorCode.ERR_CallArgMixing, "F0(__arglist(ref x, ref y))").WithArguments("Program.F0(__arglist)", "__arglist").WithLocation(15, 55), - // (15,72): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (15,72): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F40(ref scoped R x, scoped ref R y) { F0(__arglist(ref x, ref y)); } // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(15, 72), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(15, 72), // (16,55): error CS8350: This combination of arguments to 'Program.F1(ref R, __arglist)' is disallowed because it may expose variables referenced by parameter 'a' outside of their declaration scope // static void F41(ref scoped R x, scoped ref R y) { F1(ref x, __arglist(ref y)); } // 4 Diagnostic(ErrorCode.ERR_CallArgMixing, "F1(ref x, __arglist(ref y))").WithArguments("Program.F1(ref R, __arglist)", "a").WithLocation(16, 55), - // (16,62): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (16,62): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static void F41(ref scoped R x, scoped ref R y) { F1(ref x, __arglist(ref y)); } // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "x").WithArguments("ref R").WithLocation(16, 62)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "x").WithArguments("ref R").WithLocation(16, 62)); } - // PROTOTYPE: Test method-arguments-must-match with `out` and `in`, with and without `scoped`. - [Fact] public void NestedFieldAccessor() { @@ -2561,25 +2722,25 @@ static void M4(T t4) // (12,16): error CS8347: Cannot use a result of 'S.S(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // this = new S(ref t0); Diagnostic(ErrorCode.ERR_EscapeCall, "new S(ref t0)").WithArguments("S.S(ref T)", "t").WithLocation(12, 16), - // (12,29): error CS8166: Cannot return a parameter by reference 't0' because it is not a ref or out parameter + // (12,29): error CS8166: Cannot return a parameter by reference 't0' because it is not a ref parameter // this = new S(ref t0); Diagnostic(ErrorCode.ERR_RefReturnParameter, "t0").WithArguments("t0").WithLocation(12, 29), // (19,16): error CS8347: Cannot use a result of 'S.S(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // this = new S(ref t1); Diagnostic(ErrorCode.ERR_EscapeCall, "new S(ref t1)").WithArguments("S.S(ref T)", "t").WithLocation(19, 16), - // (19,29): error CS8166: Cannot return a parameter by reference 't1' because it is not a ref or out parameter + // (19,29): error CS8166: Cannot return a parameter by reference 't1' because it is not a ref parameter // this = new S(ref t1); Diagnostic(ErrorCode.ERR_RefReturnParameter, "t1").WithArguments("t1").WithLocation(19, 29), // (27,14): error CS8347: Cannot use a result of 'S.S(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // s2 = new S(ref t2); Diagnostic(ErrorCode.ERR_EscapeCall, "new S(ref t2)").WithArguments("S.S(ref T)", "t").WithLocation(27, 14), - // (27,27): error CS8166: Cannot return a parameter by reference 't2' because it is not a ref or out parameter + // (27,27): error CS8166: Cannot return a parameter by reference 't2' because it is not a ref parameter // s2 = new S(ref t2); Diagnostic(ErrorCode.ERR_RefReturnParameter, "t2").WithArguments("t2").WithLocation(27, 27), // (40,13): error CS8347: Cannot use a result of 'S.S(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // s = new S(ref t4); Diagnostic(ErrorCode.ERR_EscapeCall, "new S(ref t4)").WithArguments("S.S(ref T)", "t").WithLocation(40, 13), - // (40,26): error CS8166: Cannot return a parameter by reference 't4' because it is not a ref or out parameter + // (40,26): error CS8166: Cannot return a parameter by reference 't4' because it is not a ref parameter // s = new S(ref t4); Diagnostic(ErrorCode.ERR_RefReturnParameter, "t4").WithArguments("t4").WithLocation(40, 26)); } @@ -3017,7 +3178,6 @@ T P static ref readonly T GetRefReadonly() => throw null; }"; var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }); - // PROTOTYPE: Consider changing ERR_AssignReadonlyNotField to "Cannot take a writable 'ref' to a readonly variable". comp.VerifyEmitDiagnostics( // (7,9): error CS8374: Cannot ref-assign 'tValue' to 'F' because 'tValue' has a narrower escape scope than 'F'. // F = ref tValue; // 1 @@ -4543,22 +4703,20 @@ public void RefReturn() static ref readonly T F8(in T t) => ref t; }"; var comp = CreateCompilation(source); - // PROTOTYPE: Update ERR_RefReturnParameter message or report a distinct error, - // because the parameter (for F3 and F7) is an 'out' parameter. comp.VerifyEmitDiagnostics( - // (3,36): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (3,36): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static ref T F1(T t) => ref t; // 1 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(3, 36), - // (5,59): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (5,59): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static ref T F3(out T t) { t = default; return ref t; } // 2 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(5, 59), // (6,39): error CS8333: Cannot return variable 'in T' by writable reference because it is a readonly variable // static ref T F4(in T t) => ref t; // 3 Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "t").WithArguments("variable", "in T").WithLocation(6, 39), - // (7,45): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (7,45): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static ref readonly T F5(T t) => ref t; // 4 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(7, 45), - // (9,68): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (9,68): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static ref readonly T F7(out T t) { t = default; return ref t; } // 5 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(9, 68)); } @@ -5367,6 +5525,7 @@ static T ReadWrite2(ref T t) Diagnostic(ErrorCode.ERR_AssgLvalueExpected, "new S(1).F").WithLocation(15, 16)); } + [WorkItem(62122, "https://github.com/dotnet/roslyn/issues/62122")] [Fact] public void ReadAndDiscard() { @@ -5398,8 +5557,9 @@ static void ReadAndDiscard2(in S s) _ = s.F; } }"; - // PROTOTYPE: The dereference of `new S(...).F` should not be elided - // since the behavior may be observable as a NullReferenceException. + // https://github.com/dotnet/roslyn/issues/62122: The dereference of a ref field + // should be emitted to IL, even if the value is ignored, because the behavior + // may be observable as a NullReferenceException. var verifier = CompileAndVerify(source, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("")); verifier.VerifyIL("Program.ReadAndDiscard1", @"{ @@ -5580,10 +5740,8 @@ .maxstack 2 verifier.VerifyIL("Program.RefReadonlyReturn", expectedIL); } - // PROTOTYPE: Test with { ref readonly, readonly ref, readonly ref readonly }. - // PROTOTYPE: Test from constructor and from instance method. [Fact] - public void CompoundOperations() + public void CompoundOperations_01() { var source = @"using System; @@ -5597,8 +5755,7 @@ class Program static void Main() { int x = 42; - scoped var s = new S(); - s.F = ref x; + scoped var s = new S(ref x); Increment(s); Console.WriteLine(s.F); Console.WriteLine(x); @@ -5649,6 +5806,76 @@ .maxstack 3 }"); } + [Theory] + [InlineData("ref")] + [InlineData("readonly ref")] + public void CompoundOperations_02(string refKind) + { + var source = +$@"using System; +ref struct S +{{ + public {refKind} int F; + public S(ref int i) {{ F = ref i; }} + public void Increment() + {{ + F++; + }} + public void Subtract(int offset) + {{ + F -= offset; + }} +}} +class Program +{{ + static void Main() + {{ + int x = 42; + scoped var s = new S(ref x); + s.Increment(); + Console.WriteLine(s.F); + Console.WriteLine(x); + s.Subtract(10); + Console.WriteLine(s.F); + Console.WriteLine(x); + }} +}}"; + var verifier = CompileAndVerify(source, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput( +@"43 +43 +33 +33 +")); + verifier.VerifyIL("S.Increment", +@"{ + // Code size 17 (0x11) + .maxstack 3 + IL_0000: ldarg.0 + IL_0001: ldfld ""ref int S.F"" + IL_0006: ldarg.0 + IL_0007: ldfld ""ref int S.F"" + IL_000c: ldind.i4 + IL_000d: ldc.i4.1 + IL_000e: add + IL_000f: stind.i4 + IL_0010: ret +}"); + verifier.VerifyIL("S.Subtract", +@"{ + // Code size 17 (0x11) + .maxstack 3 + IL_0000: ldarg.0 + IL_0001: ldfld ""ref int S.F"" + IL_0006: ldarg.0 + IL_0007: ldfld ""ref int S.F"" + IL_000c: ldind.i4 + IL_000d: ldarg.1 + IL_000e: sub + IL_000f: stind.i4 + IL_0010: ret +}"); + } + [Fact] public void ConditionalOperator() { @@ -5917,7 +6144,11 @@ static void F2(S x2) var y2 = F1(ref x2); } }"; - var comp = CreateCompilation(source); + + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + comp.VerifyEmitDiagnostics(); + + comp = CreateCompilation(source); comp.VerifyEmitDiagnostics(); } @@ -5939,90 +6170,181 @@ static void F2(S x2, S y2) var z1 = F1(ref x2, ref y2); } }"; - var comp = CreateCompilation(source); - // PROTOTYPE: Should report 'x2' might escape. + + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + comp.VerifyEmitDiagnostics(); + + comp = CreateCompilation(source); comp.VerifyEmitDiagnostics(); } + [WorkItem(62098, "https://github.com/dotnet/roslyn/issues/62098")] [Fact] public void RefToContainingType() { var source = @"ref struct R { - public ref R F; + public ref R Next; } class Program { static void F(ref R r) { - r.F = ref r; + r.Next = ref r; } }"; var comp = CreateCompilation(source); - // PROTOTYPE: Should support ref field of containing type. + // https://github.com/dotnet/roslyn/issues/62098: Allow ref field of the containing type. comp.VerifyEmitDiagnostics( - // (3,21): error CS0523: Struct member 'R.F' of type 'R' causes a cycle in the struct layout - // public ref R F; - Diagnostic(ErrorCode.ERR_StructLayoutCycle, "F").WithArguments("R.F", "R").WithLocation(3, 21)); + // (3,21): error CS0523: Struct member 'R.Next' of type 'R' causes a cycle in the struct layout + // public ref R Next; + Diagnostic(ErrorCode.ERR_StructLayoutCycle, "Next").WithArguments("R.Next", "R").WithLocation(3, 21)); } + /// + /// Ref auto-properties are not supported. + /// [Fact] - public void RefAutoProperty() + public void RefAutoProperty_01() { var source = @"using System; ref struct S { - public ref T P { get; } - public ref readonly T Q { get; } + public ref T P0 { get; } + public ref T P1 { get; set; } + public ref T P2 { get; init; } public S(ref T t) { - P = ref t; - Q = ref t; + P0 = ref t; + P1 = ref t; + P2 = ref t; } } class Program { static void Main() { - int x = 1; + int x = 0; var s = new S(ref x); - s.P = 2; - Console.WriteLine(s.P); - Console.WriteLine(s.Q); - Console.WriteLine(x); - x = 3; - Console.WriteLine(s.P); - Console.WriteLine(s.Q); - Console.WriteLine(x); - s.P = ref x; - s.Q = ref x; + s.P0 = 0; + s.P1 = 1; + s.P2 = 2; + s.P0 = ref x; + s.P1 = ref x; + s.P2 = ref x; } }"; var comp = CreateCompilation(source); - // PROTOTYPE: Should this scenario be supported? Test all valid combinations of { get, set, init }. - // PROTOTYPE: Verify use of ref auto-property does not generate a LanguageVersion error - // (since we generally don't look at how properties are implemented). comp.VerifyEmitDiagnostics( // (4,18): error CS8145: Auto-implemented properties cannot return by reference - // public ref T P { get; } - Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "P").WithLocation(4, 18), + // public ref T P0 { get; } + Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "P0").WithLocation(4, 18), + // (5,18): error CS8145: Auto-implemented properties cannot return by reference + // public ref T P1 { get; set; } + Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "P1").WithLocation(5, 18), + // (5,28): error CS8147: Properties which return by reference cannot have set accessors + // public ref T P1 { get; set; } + Diagnostic(ErrorCode.ERR_RefPropertyCannotHaveSetAccessor, "set").WithLocation(5, 28), + // (6,18): error CS8145: Auto-implemented properties cannot return by reference + // public ref T P2 { get; init; } + Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "P2").WithLocation(6, 18), + // (6,28): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported + // public ref T P2 { get; init; } + Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "init").WithArguments("System.Runtime.CompilerServices.IsExternalInit").WithLocation(6, 28), + // (6,28): error CS8147: Properties which return by reference cannot have set accessors + // public ref T P2 { get; init; } + Diagnostic(ErrorCode.ERR_RefPropertyCannotHaveSetAccessor, "init").WithLocation(6, 28), + // (9,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // P0 = ref t; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "P0").WithLocation(9, 9), + // (10,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // P1 = ref t; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "P1").WithLocation(10, 9), + // (11,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // P2 = ref t; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "P2").WithLocation(11, 9), + // (23,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // s.P0 = ref x; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.P0").WithLocation(23, 9), + // (24,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // s.P1 = ref x; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.P1").WithLocation(24, 9), + // (25,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // s.P2 = ref x; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.P2").WithLocation(25, 9)); + } + + /// + /// Ref auto-properties are not supported. + /// + [Fact] + public void RefAutoProperty_02() + { + var source = +@"using System; +ref struct S +{ + public ref readonly T P0 { get; } + public ref readonly T P1 { get; set; } + public ref readonly T P2 { get; init; } + public S(ref T t) + { + P0 = ref t; + P1 = ref t; + P2 = ref t; + } +} +class Program +{ + static void Main() + { + int x = 0; + var s = new S(ref x); + s.P0 = ref x; + s.P1 = ref x; + s.P2 = ref x; + } +}"; + var comp = CreateCompilation(source); + comp.VerifyEmitDiagnostics( + // (4,27): error CS8145: Auto-implemented properties cannot return by reference + // public ref readonly T P0 { get; } + Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "P0").WithLocation(4, 27), // (5,27): error CS8145: Auto-implemented properties cannot return by reference - // public ref readonly T Q { get; } - Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "Q").WithLocation(5, 27), - // (8,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. - // P = ref t; - Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "P").WithLocation(8, 9), + // public ref readonly T P1 { get; set; } + Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "P1").WithLocation(5, 27), + // (5,37): error CS8147: Properties which return by reference cannot have set accessors + // public ref readonly T P1 { get; set; } + Diagnostic(ErrorCode.ERR_RefPropertyCannotHaveSetAccessor, "set").WithLocation(5, 37), + // (6,27): error CS8145: Auto-implemented properties cannot return by reference + // public ref readonly T P2 { get; init; } + Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "P2").WithLocation(6, 27), + // (6,37): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported + // public ref readonly T P2 { get; init; } + Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "init").WithArguments("System.Runtime.CompilerServices.IsExternalInit").WithLocation(6, 37), + // (6,37): error CS8147: Properties which return by reference cannot have set accessors + // public ref readonly T P2 { get; init; } + Diagnostic(ErrorCode.ERR_RefPropertyCannotHaveSetAccessor, "init").WithLocation(6, 37), // (9,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. - // Q = ref t; - Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "Q").WithLocation(9, 9), - // (26,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. - // s.P = ref x; - Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.P").WithLocation(26, 9), - // (27,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. - // s.Q = ref x; - Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.Q").WithLocation(27, 9)); + // P0 = ref t; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "P0").WithLocation(9, 9), + // (10,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // P1 = ref t; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "P1").WithLocation(10, 9), + // (11,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // P2 = ref t; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "P2").WithLocation(11, 9), + // (20,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // s.P0 = ref x; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.P0").WithLocation(20, 9), + // (21,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // s.P1 = ref x; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.P1").WithLocation(21, 9), + // (22,9): error CS8373: The left-hand side of a ref assignment must be a ref variable. + // s.P2 = ref x; + Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.P2").WithLocation(22, 9)); } [Fact] @@ -6120,19 +6442,19 @@ static ref int F2() }"; var comp = CreateCompilationWithSpanAndMemoryExtensions(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion)); comp.VerifyDiagnostics( - // (7,20): error CS8352: Cannot use local 's1' in this context because it may expose referenced variables outside of their declaration scope + // (7,20): error CS8352: Cannot use variable 's1' in this context because it may expose referenced variables outside of their declaration scope // return ref s1[1]; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "s1").WithArguments("s1").WithLocation(7, 20)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "s1").WithArguments("s1").WithLocation(7, 20)); } - // PROTOTYPE: Document breaking change in C#11: Cannot return an 'out' parameter by reference. + // Breaking change in C#11: Cannot return an 'out' parameter by reference. [Fact] public void BreakingChange_ReturnOutByRef() { var source = @"class Program { - static ref T F(out T t) + static ref T ReturnOutParamByRef(out T t) { t = default; return ref t; @@ -6144,12 +6466,12 @@ static ref T F(out T t) comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (6,20): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (6,20): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // return ref t; Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(6, 20)); } - // PROTOTYPE: Document breaking change in C#11: The rvalue from a method invocation that + // Breaking change in C#11: The rvalue from a method invocation that // returns a ref struct is safe-to-escape from ... the ref-safe-to-escape of all ref arguments. [Fact] public void BreakingChange_RefStructReturnFromRefArguments() @@ -6158,50 +6480,16 @@ public void BreakingChange_RefStructReturnFromRefArguments() @"ref struct R { } class Program { - static R F(ref int i) => default; - static void Main() + static R MayCaptureArg(ref int i) => new R(); + static R MayCaptureDefaultArg(in int i = 0) => new R(); + static R Create() { int i = 0; - R r; - r = F(ref i); - } -}"; - - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); - comp.VerifyDiagnostics( - // (9,13): error CS8347: Cannot use a result of 'Program.F(ref int)' in this context because it may expose variables referenced by parameter 'i' outside of their declaration scope - // r = F(ref i); - Diagnostic(ErrorCode.ERR_EscapeCall, "F(ref i)").WithArguments("Program.F(ref int)", "i").WithLocation(9, 13), - // (9,19): error CS8168: Cannot return local 'i' by reference because it is not a ref local - // r = F(ref i); - Diagnostic(ErrorCode.ERR_RefReturnLocal, "i").WithArguments("i").WithLocation(9, 19)); - } - - // PROTOTYPE: Document breaking change in C#11: Similar to above but - // extended to in arguments including default parameter values. - [Fact] - public void BreakingChange_RefStructReturnFromInArgumentsIncludingDefaults() - { - var source = -@"ref struct R { } -class Program -{ - static R F(in int i = 0) => default; - static R F0() - { - return F(); + return MayCaptureArg(ref i); } - static R F1() + static R CreateDefault() { - return F(1); - } - static R F2() - { - int i = 2; - return F(i); + return MayCaptureDefaultArg(); } }"; @@ -6210,24 +6498,18 @@ static R F2() comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (7,16): error CS8156: An expression cannot be used in this context because it may not be passed or returned by reference - // return F(); - Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "F()").WithLocation(7, 16), - // (7,16): error CS8347: Cannot use a result of 'Program.F(in int)' in this context because it may expose variables referenced by parameter 'i' outside of their declaration scope - // return F(); - Diagnostic(ErrorCode.ERR_EscapeCall, "F()").WithArguments("Program.F(in int)", "i").WithLocation(7, 16), - // (11,16): error CS8347: Cannot use a result of 'Program.F(in int)' in this context because it may expose variables referenced by parameter 'i' outside of their declaration scope - // return F(1); - Diagnostic(ErrorCode.ERR_EscapeCall, "F(1)").WithArguments("Program.F(in int)", "i").WithLocation(11, 16), - // (11,18): error CS8156: An expression cannot be used in this context because it may not be passed or returned by reference - // return F(1); - Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "1").WithLocation(11, 18), - // (16,16): error CS8347: Cannot use a result of 'Program.F(in int)' in this context because it may expose variables referenced by parameter 'i' outside of their declaration scope - // return F(i); - Diagnostic(ErrorCode.ERR_EscapeCall, "F(i)").WithArguments("Program.F(in int)", "i").WithLocation(16, 16), - // (16,18): error CS8168: Cannot return local 'i' by reference because it is not a ref local - // return F(i); - Diagnostic(ErrorCode.ERR_RefReturnLocal, "i").WithArguments("i").WithLocation(16, 18)); + // (9,16): error CS8347: Cannot use a result of 'Program.MayCaptureArg(ref int)' in this context because it may expose variables referenced by parameter 'i' outside of their declaration scope + // return MayCaptureArg(ref i); + Diagnostic(ErrorCode.ERR_EscapeCall, "MayCaptureArg(ref i)").WithArguments("Program.MayCaptureArg(ref int)", "i").WithLocation(9, 16), + // (9,34): error CS8168: Cannot return local 'i' by reference because it is not a ref local + // return MayCaptureArg(ref i); + Diagnostic(ErrorCode.ERR_RefReturnLocal, "i").WithArguments("i").WithLocation(9, 34), + // (13,16): error CS8156: An expression cannot be used in this context because it may not be passed or returned by reference + // return MayCaptureDefaultArg(); + Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "MayCaptureDefaultArg()").WithLocation(13, 16), + // (13,16): error CS8347: Cannot use a result of 'Program.MayCaptureDefaultArg(in int)' in this context because it may expose variables referenced by parameter 'i' outside of their declaration scope + // return MayCaptureDefaultArg(); + Diagnostic(ErrorCode.ERR_EscapeCall, "MayCaptureDefaultArg()").WithArguments("Program.MayCaptureDefaultArg(in int)", "i").WithLocation(13, 16)); } [Theory] @@ -6291,9 +6573,9 @@ static void F(ref R x) // (7,9): error CS8350: This combination of arguments to 'A.F2(ref R, ref R, ref R)' is disallowed because it may expose variables referenced by parameter 'y2' outside of their declaration scope // A.F2(ref x, ref y, ref y); Diagnostic(ErrorCode.ERR_CallArgMixing, "A.F2(ref x, ref y, ref y)").WithArguments("A.F2(ref R, ref R, ref R)", "y2").WithLocation(7, 9), - // (7,25): error CS8352: Cannot use local 'y' in this context because it may expose referenced variables outside of their declaration scope + // (7,25): error CS8352: Cannot use variable 'y' in this context because it may expose referenced variables outside of their declaration scope // A.F2(ref x, ref y, ref y); - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("y").WithLocation(7, 25)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("y").WithLocation(7, 25)); verify(comp); @@ -6603,13 +6885,51 @@ public void ParameterScope_07() @"ref struct R { } class Program { - static void F1(scoped scoped R r) { } - static void F2(ref scoped scoped R r) { } + static void F0(scoped scoped R r) { } + static void F1(ref scoped scoped R r) { } + static void F2(scoped ref scoped R r) { } static void F3(scoped scoped ref R r) { } + static void F4(in scoped scoped R r) { } + static void F5(scoped in scoped R r) { } + static void F6(scoped scoped in R r) { } + static void F7(out scoped scoped R r) { r = default; } + static void F8(scoped out scoped R r) { r = default; } + static void F9(scoped scoped out R r) { r = default; } }"; var comp = CreateCompilation(source); - // PROTOTYPE: Should report duplicate modifiers. - comp.VerifyEmitDiagnostics(); + comp.VerifyEmitDiagnostics( + // (4,27): error CS1107: A parameter can only have one 'scoped' modifier + // static void F0(scoped scoped R r) { } + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(4, 27), + // (5,31): error CS1107: A parameter can only have one 'scoped' modifier + // static void F1(ref scoped scoped R r) { } + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(5, 31), + // (7,27): error CS1107: A parameter can only have one 'scoped' modifier + // static void F3(scoped scoped ref R r) { } + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(7, 27), + // (8,30): error CS1107: A parameter can only have one 'scoped' modifier + // static void F4(in scoped scoped R r) { } + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(8, 30), + // (10,27): error CS1107: A parameter can only have one 'scoped' modifier + // static void F6(scoped scoped in R r) { } + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(10, 27), + // (11,31): error CS1107: A parameter can only have one 'scoped' modifier + // static void F7(out scoped scoped R r) { r = default; } + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(11, 31), + // (13,27): error CS1107: A parameter can only have one 'scoped' modifier + // static void F9(scoped scoped out R r) { r = default; } + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(13, 27)); + + VerifyParameterSymbol(comp.GetMember("Program.F0").Parameters[0], "scoped R r", RefKind.None, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F1").Parameters[0], "ref scoped R r", RefKind.Ref, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F2").Parameters[0], "ref scoped R r", RefKind.Ref, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F3").Parameters[0], "scoped ref R r", RefKind.Ref, DeclarationScope.RefScoped); + VerifyParameterSymbol(comp.GetMember("Program.F4").Parameters[0], "in scoped R r", RefKind.In, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F5").Parameters[0], "in scoped R r", RefKind.In, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F6").Parameters[0], "scoped in R r", RefKind.In, DeclarationScope.RefScoped); + VerifyParameterSymbol(comp.GetMember("Program.F7").Parameters[0], "out scoped R r", RefKind.Out, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F8").Parameters[0], "out scoped R r", RefKind.Out, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F9").Parameters[0], "out R r", RefKind.Out, DeclarationScope.RefScoped); } [Fact] @@ -6627,8 +6947,16 @@ static void Main() } }"; var comp = CreateCompilation(source); - // PROTOTYPE: Should report duplicate modifiers. - comp.VerifyEmitDiagnostics(); + comp.VerifyEmitDiagnostics( + // (6,26): error CS1107: A parameter can only have one 'scoped' modifier + // var f1 = (scoped scoped R r) => { }; + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(6, 26), + // (7,30): error CS1107: A parameter can only have one 'scoped' modifier + // var f2 = (ref scoped scoped R r) => { }; + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(7, 30), + // (8,26): error CS1107: A parameter can only have one 'scoped' modifier + // var f3 = (scoped scoped ref R r) => { }; + Diagnostic(ErrorCode.ERR_DupParamMod, "scoped").WithArguments("scoped").WithLocation(8, 26)); } [Fact] @@ -6638,7 +6966,17 @@ public void ParameterScope_09() @"ref struct scoped { } class Program { - static void F1(scoped scoped x, ref scoped y, ref scoped scoped z, scoped ref scoped w) { } + static void F0(scoped s) { } + static void F1(scoped scoped s) { } + static void F2(ref scoped s) { } + static void F3(ref scoped scoped s) { } + static void F4(scoped ref scoped s) { } + static void F5(in scoped s) { } + static void F6(in scoped scoped s) { } + static void F7(scoped in scoped s) { } + static void F8(out scoped s) { s = default; } + static void F9(out scoped scoped s) { s = default; } + static void FA(scoped out scoped s) { s = default; } }"; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( @@ -6646,11 +6984,17 @@ static void F1(scoped scoped x, ref scoped y, ref scoped scoped z, scoped ref sc // ref struct scoped { } Diagnostic(ErrorCode.WRN_LowerCaseTypeName, "scoped").WithArguments("scoped").WithLocation(1, 12)); - var method = comp.GetMember("Program.F1"); - VerifyParameterSymbol(method.Parameters[0], "scoped scoped x", RefKind.None, DeclarationScope.ValueScoped); - VerifyParameterSymbol(method.Parameters[1], "ref scoped y", RefKind.Ref, DeclarationScope.Unscoped); - VerifyParameterSymbol(method.Parameters[2], "ref scoped scoped z", RefKind.Ref, DeclarationScope.ValueScoped); - VerifyParameterSymbol(method.Parameters[3], "scoped ref scoped w", RefKind.Ref, DeclarationScope.RefScoped); + VerifyParameterSymbol(comp.GetMember("Program.F0").Parameters[0], "scoped s", RefKind.None, DeclarationScope.Unscoped); + VerifyParameterSymbol(comp.GetMember("Program.F1").Parameters[0], "scoped scoped s", RefKind.None, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F2").Parameters[0], "ref scoped s", RefKind.Ref, DeclarationScope.Unscoped); + VerifyParameterSymbol(comp.GetMember("Program.F3").Parameters[0], "ref scoped scoped s", RefKind.Ref, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F4").Parameters[0], "scoped ref scoped s", RefKind.Ref, DeclarationScope.RefScoped); + VerifyParameterSymbol(comp.GetMember("Program.F5").Parameters[0], "in scoped s", RefKind.In, DeclarationScope.Unscoped); + VerifyParameterSymbol(comp.GetMember("Program.F6").Parameters[0], "in scoped scoped s", RefKind.In, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F7").Parameters[0], "scoped in scoped s", RefKind.In, DeclarationScope.RefScoped); + VerifyParameterSymbol(comp.GetMember("Program.F8").Parameters[0], "out scoped s", RefKind.Out, DeclarationScope.RefScoped); + VerifyParameterSymbol(comp.GetMember("Program.F9").Parameters[0], "out scoped scoped s", RefKind.Out, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.FA").Parameters[0], "out scoped s", RefKind.Out, DeclarationScope.RefScoped); } [Fact] @@ -6694,8 +7038,39 @@ static void Main() VerifyParameterSymbol(method.Parameters[0], "R r", RefKind.None, DeclarationScope.Unscoped); } + [WorkItem(62080, "https://github.com/dotnet/roslyn/issues/62080")] [Fact] public void ParameterScope_11() + { + var source = +@"ref struct R { } +delegate R D1(R r); +delegate R D2(scoped R r); +class Program +{ + static void Main() + { + D1 d1 = r1 => r1; + D2 d2 = r2 => r2; + } +}"; + var comp = CreateCompilation(source); + // https://github.com/dotnet/roslyn/issues/62080: Lambda parameter r2 should be inferred as 'scoped R' rather than 'R'. + comp.VerifyEmitDiagnostics( + // (9,17): error CS8986: The 'scoped' modifier of parameter 'r2' doesn't match target 'D2'. + // D2 d2 = r2 => r2; + Diagnostic(ErrorCode.ERR_ScopedMismatchInParameterOfTarget, "r2 => r2").WithArguments("r2", "D2").WithLocation(9, 17)); + + var tree = comp.SyntaxTrees[0]; + var model = comp.GetSemanticModel(tree); + var lambdas = tree.GetRoot().DescendantNodes().OfType().Select(e => model.GetSymbolInfo(e).Symbol.GetSymbol()).ToArray(); + + VerifyParameterSymbol(lambdas[0].Parameters[0], "R r1", RefKind.None, DeclarationScope.Unscoped); + VerifyParameterSymbol(lambdas[1].Parameters[0], "R r2", RefKind.None, DeclarationScope.Unscoped); + } + + [Fact] + public void ParameterScope_12() { var source0 = @".class private System.Runtime.CompilerServices.LifetimeAnnotationAttribute extends [mscorlib]System.Attribute @@ -6791,8 +7166,50 @@ readonly void F2() { } VerifyParameterSymbol(comp.GetMember("R2.F2").ThisParameter, "scoped in R2 this", RefKind.In, DeclarationScope.RefScoped); } - // PROTOTYPE: Test 'scoped' with extension method 'this'. - // PROTOTYPE: Test 'scoped' with 'params'. + [Fact] + public void ExtensionThisScope() + { + var source = +@"ref struct R { } +static class Extensions +{ + static void F0(this R r) { } + static void F1(this scoped R r) { } + static void F2(scoped this R r) { } + static void F3(this scoped ref T t) where T : struct { } + static void F4(this ref scoped R r) { } +}"; + var comp = CreateCompilation(source); + comp.VerifyEmitDiagnostics(); + + VerifyParameterSymbol(comp.GetMember("Extensions.F0").Parameters[0], "R r", RefKind.None, DeclarationScope.Unscoped); + VerifyParameterSymbol(comp.GetMember("Extensions.F1").Parameters[0], "scoped R r", RefKind.None, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Extensions.F2").Parameters[0], "scoped R r", RefKind.None, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Extensions.F3").Parameters[0], "scoped ref T t", RefKind.Ref, DeclarationScope.RefScoped); + VerifyParameterSymbol(comp.GetMember("Extensions.F4").Parameters[0], "ref scoped R r", RefKind.Ref, DeclarationScope.ValueScoped); + } + + [Fact] + public void ParamsScope() + { + var source = +@"class Program +{ + static void F1(scoped params object[] args) { } + static void F2(params scoped object[] args) { } +}"; + var comp = CreateCompilation(source); + comp.VerifyEmitDiagnostics( + // (3,20): error CS8986: The 'scoped' modifier can be used for refs and ref struct values only. + // static void F1(scoped params object[] args) { } + Diagnostic(ErrorCode.ERR_ScopedRefAndRefStructOnly, "scoped params object[] args").WithLocation(3, 20), + // (4,20): error CS8986: The 'scoped' modifier can be used for refs and ref struct values only. + // static void F2(params scoped object[] args) { } + Diagnostic(ErrorCode.ERR_ScopedRefAndRefStructOnly, "params scoped object[] args").WithLocation(4, 20)); + + VerifyParameterSymbol(comp.GetMember("Program.F1").Parameters[0], "scoped params System.Object[] args", RefKind.None, DeclarationScope.ValueScoped); + VerifyParameterSymbol(comp.GetMember("Program.F2").Parameters[0], "scoped params System.Object[] args", RefKind.None, DeclarationScope.ValueScoped); + } [Theory] [InlineData(LanguageVersion.CSharp10)] @@ -6815,26 +7232,137 @@ static void Main() } }"; var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); - // PROTOTYPE: Should report errors for 'ref scoped' and 'ref readonly scoped' return types as well. comp.VerifyDiagnostics( - // (4,21): error CS0106: The modifier 'scoped' is not valid for this item - // static scoped R F1() => throw null; - Diagnostic(ErrorCode.ERR_BadMemberFlag, "F1").WithArguments("scoped").WithLocation(4, 21), - // (5,25): error CS0106: The modifier 'scoped' is not valid for this item - // static scoped ref R F2() => throw null; - Diagnostic(ErrorCode.ERR_BadMemberFlag, "F2").WithArguments("scoped").WithLocation(5, 25), - // (10,16): error CS0106: The modifier 'scoped' is not valid for this item - // static scoped R L1() => throw null; - Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(10, 16), - // (11,16): error CS0106: The modifier 'scoped' is not valid for this item - // static scoped ref readonly R L2() => throw null; - Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(11, 16)); + // (4,21): error CS0106: The modifier 'scoped' is not valid for this item + // static scoped R F1() => throw null; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "F1").WithArguments("scoped").WithLocation(4, 21), + // (5,25): error CS0106: The modifier 'scoped' is not valid for this item + // static scoped ref R F2() => throw null; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "F2").WithArguments("scoped").WithLocation(5, 25), + // (6,16): error CS0106: The modifier 'scoped' is not valid for this item + // static ref scoped R F3() => throw null; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(6, 16), + // (10,16): error CS0106: The modifier 'scoped' is not valid for this item + // static scoped R L1() => throw null; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(10, 16), + // (11,16): error CS0106: The modifier 'scoped' is not valid for this item + // static scoped ref readonly R L2() => throw null; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(11, 16), + // (12,29): error CS0106: The modifier 'scoped' is not valid for this item + // static ref readonly scoped R L3() => throw null; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(12, 29)); + } + + [Theory] + [InlineData(LanguageVersion.CSharp10)] + [InlineData(LanguageVersionFacts.CSharpNext)] + public void DelegateReturnTypeScope(LanguageVersion langVersion) + { + var source = +@"ref struct R { } +delegate ref scoped R D(); +"; + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + comp.VerifyEmitDiagnostics( + // (2,14): error CS0106: The modifier 'scoped' is not valid for this item + // delegate ref scoped R D(); + Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(2, 14)); + } + + [Theory] + [InlineData(LanguageVersion.CSharp10)] + [InlineData(LanguageVersionFacts.CSharpNext)] + public void TypeScopeModifier_01(LanguageVersion langVersion) + { + var source = +@"scoped struct A { } +scoped ref struct B { } +scoped readonly ref struct C { } +"; + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + comp.VerifyDiagnostics( + // (1,15): error CS0106: The modifier 'scoped' is not valid for this item + // scoped struct A { } + Diagnostic(ErrorCode.ERR_BadMemberFlag, "A").WithArguments("scoped").WithLocation(1, 15), + // (2,19): error CS0106: The modifier 'scoped' is not valid for this item + // scoped ref struct B { } + Diagnostic(ErrorCode.ERR_BadMemberFlag, "B").WithArguments("scoped").WithLocation(2, 19), + // (3,28): error CS0106: The modifier 'scoped' is not valid for this item + // scoped readonly ref struct C { } + Diagnostic(ErrorCode.ERR_BadMemberFlag, "C").WithArguments("scoped").WithLocation(3, 28)); + } + + [Theory] + [InlineData(LanguageVersion.CSharp10)] + [InlineData(LanguageVersionFacts.CSharpNext)] + public void TypeScopeModifier_02(LanguageVersion langVersion) + { + var source = +@"scoped record A { } +scoped readonly record struct B; +readonly scoped record struct C(); +"; + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + comp.VerifyDiagnostics( + // (1,15): error CS0106: The modifier 'scoped' is not valid for this item + // scoped record A { } + Diagnostic(ErrorCode.ERR_BadMemberFlag, "A").WithArguments("scoped").WithLocation(1, 15), + // (2,31): error CS0106: The modifier 'scoped' is not valid for this item + // scoped readonly record struct B; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "B").WithArguments("scoped").WithLocation(2, 31), + // (3,31): error CS0106: The modifier 'scoped' is not valid for this item + // readonly scoped record struct C(); + Diagnostic(ErrorCode.ERR_BadMemberFlag, "C").WithArguments("scoped").WithLocation(3, 31)); + } + + [Fact] + public void FieldTypeScope() + { + var source = +@"#pragma warning disable 169 +ref struct R1 { } +ref struct R2 +{ + scoped R1 F1; + ref scoped R1 F2; + scoped ref int F3; +}"; + + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (5,15): error CS0106: The modifier 'scoped' is not valid for this item + // scoped R1 F1; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "F1").WithArguments("scoped").WithLocation(5, 15), + // (6,5): error CS8652: The feature 'ref fields' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. + // ref scoped R1 F2; + Diagnostic(ErrorCode.ERR_FeatureInPreview, "ref scoped R1").WithArguments("ref fields").WithLocation(6, 5), + // (6,9): error CS0106: The modifier 'scoped' is not valid for this item + // ref scoped R1 F2; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(6, 9), + // (7,12): error CS8652: The feature 'ref fields' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. + // scoped ref int F3; + Diagnostic(ErrorCode.ERR_FeatureInPreview, "ref int").WithArguments("ref fields").WithLocation(7, 12), + // (7,20): error CS0106: The modifier 'scoped' is not valid for this item + // scoped ref int F3; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "F3").WithArguments("scoped").WithLocation(7, 20)); + + comp = CreateCompilation(source); + comp.VerifyDiagnostics( + // (5,15): error CS0106: The modifier 'scoped' is not valid for this item + // scoped R1 F1; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "F1").WithArguments("scoped").WithLocation(5, 15), + // (6,9): error CS0106: The modifier 'scoped' is not valid for this item + // ref scoped R1 F2; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(6, 9), + // (7,20): error CS0106: The modifier 'scoped' is not valid for this item + // scoped ref int F3; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "F3").WithArguments("scoped").WithLocation(7, 20)); } [Theory] [InlineData(LanguageVersion.CSharp10)] [InlineData(LanguageVersionFacts.CSharpNext)] - public void PropertyValueScope(LanguageVersion langVersion) + public void PropertyTypeScope(LanguageVersion langVersion) { var source = @"ref struct R1 { } @@ -6847,7 +7375,6 @@ scoped R1 P3 { set { } } scoped ref int P5 => throw null; }"; var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); - // PROTOTYPE: Should report error for 'scoped' on P4. comp.VerifyDiagnostics( // (4,15): error CS0106: The modifier 'scoped' is not valid for this item // scoped R1 P1 { get; } @@ -6858,6 +7385,9 @@ scoped R1 P3 { set { } } // (6,15): error CS0106: The modifier 'scoped' is not valid for this item // scoped R1 P3 { set { } } Diagnostic(ErrorCode.ERR_BadMemberFlag, "P3").WithArguments("scoped").WithLocation(6, 15), + // (7,9): error CS0106: The modifier 'scoped' is not valid for this item + // ref scoped R1 P4 => throw null; + Diagnostic(ErrorCode.ERR_BadMemberFlag, "scoped").WithArguments("scoped").WithLocation(7, 9), // (8,20): error CS0106: The modifier 'scoped' is not valid for this item // scoped ref int P5 => throw null; Diagnostic(ErrorCode.ERR_BadMemberFlag, "P5").WithArguments("scoped").WithLocation(8, 20)); @@ -7186,6 +7716,35 @@ public void LocalScope_05(LanguageVersion langVersion) VerifyLocalSymbol(locals[0], "System.Boolean scoped", RefKind.None, DeclarationScope.Unscoped); } + [Fact] + public void LocalScope_06() + { + var source = +@"ref struct R { } +class Program +{ + static void M(R r0) + { + scoped var r1 = new R(); + ref scoped var r2 = ref r1; + scoped ref var r3 = ref r0; + scoped ref scoped var r4 = ref r0; + } +}"; + var comp = CreateCompilation(source); + comp.VerifyDiagnostics(); + + var tree = comp.SyntaxTrees[0]; + var model = comp.GetSemanticModel(tree); + var decls = tree.GetRoot().DescendantNodes().OfType().ToArray(); + var locals = decls.Select(d => model.GetDeclaredSymbol(d).GetSymbol()).ToArray(); + + VerifyLocalSymbol(locals[0], "scoped R r1", RefKind.None, DeclarationScope.ValueScoped); + VerifyLocalSymbol(locals[1], "ref scoped R r2", RefKind.Ref, DeclarationScope.ValueScoped); + VerifyLocalSymbol(locals[2], "scoped ref R r3", RefKind.Ref, DeclarationScope.RefScoped); + VerifyLocalSymbol(locals[3], "ref scoped R r4", RefKind.Ref, DeclarationScope.ValueScoped); + } + [Fact] public void LocalScopeAndInitializer_01() { @@ -7215,9 +7774,9 @@ static void Refs(ref R r1, scoped ref R r2, ref scoped R r3) }"; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (18,32): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (18,32): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // scoped ref R r43 = ref r3; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r3").WithArguments("ref R").WithLocation(18, 32)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r3").WithArguments("ref R").WithLocation(18, 32)); var tree = comp.SyntaxTrees[0]; var model = comp.GetSemanticModel(tree); @@ -7255,9 +7814,9 @@ static R Refs(ref scoped R r3) }"; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (6,32): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (6,32): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // scoped ref R r43 = ref r3; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r3").WithArguments("ref R").WithLocation(6, 32)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r3").WithArguments("ref R").WithLocation(6, 32)); } private static void VerifyLocalSymbol(LocalSymbol local, string expectedDisplayString, RefKind expectedRefKind, DeclarationScope expectedScope) @@ -7333,18 +7892,18 @@ class Program }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (4,39): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + // (4,39): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // static R Implicit1(scoped R r) => r; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r").WithArguments("R").WithLocation(4, 39), - // (6,43): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r").WithArguments("R").WithLocation(4, 39), + // (6,43): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static R Implicit3(ref scoped R r) => r; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r").WithArguments("ref R").WithLocation(6, 43), - // (8,39): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r").WithArguments("ref R").WithLocation(6, 43), + // (8,39): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // static R Explicit1(scoped R r) => (R)r; - Diagnostic(ErrorCode.ERR_EscapeLocal, "(R)r").WithArguments("R").WithLocation(8, 39), - // (10,43): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "(R)r").WithArguments("R").WithLocation(8, 39), + // (10,43): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static R Explicit3(ref scoped R r) => (R)r; - Diagnostic(ErrorCode.ERR_EscapeLocal, "(R)r").WithArguments("ref R").WithLocation(10, 43)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "(R)r").WithArguments("ref R").WithLocation(10, 43)); } [Fact] @@ -8494,12 +9053,12 @@ class Program }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (4,53): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + // (4,53): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // static R F1(bool b, R x, scoped R y) => b ? x : y; - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("R").WithLocation(4, 53), - // (5,49): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("R").WithLocation(4, 53), + // (5,49): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // static R F2(bool b, R x, scoped R y) => b ? y : x; - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("R").WithLocation(5, 49)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("R").WithLocation(5, 49)); } [Fact] @@ -8517,15 +9076,15 @@ class Program // (4,61): error CS8351: Branches of a ref conditional operator cannot refer to variables with incompatible declaration scopes // static ref R F1(bool b, ref R x, ref scoped R y) => ref b ? ref x : ref y; Diagnostic(ErrorCode.ERR_MismatchedRefEscapeInTernary, "b ? ref x : ref y").WithLocation(4, 61), - // (4,77): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (4,77): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static ref R F1(bool b, ref R x, ref scoped R y) => ref b ? ref x : ref y; - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(4, 77), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(4, 77), // (5,61): error CS8351: Branches of a ref conditional operator cannot refer to variables with incompatible declaration scopes // static ref R F2(bool b, ref R x, ref scoped R y) => ref b ? ref y : ref x; Diagnostic(ErrorCode.ERR_MismatchedRefEscapeInTernary, "b ? ref y : ref x").WithLocation(5, 61), - // (5,69): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (5,69): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static ref R F2(bool b, ref R x, ref scoped R y) => ref b ? ref y : ref x; - Diagnostic(ErrorCode.ERR_EscapeLocal, "y").WithArguments("ref R").WithLocation(5, 69)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "y").WithArguments("ref R").WithLocation(5, 69)); } [Fact] @@ -8539,10 +9098,10 @@ public void BestCommonType_03() }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (3,75): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (3,75): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // static ref int F1(bool b, scoped ref int x, ref int y) => ref b ? ref x : ref y; Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(3, 75), - // (4,83): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref or out parameter + // (4,83): error CS8166: Cannot return a parameter by reference 'x' because it is not a ref parameter // static ref int F2(bool b, scoped ref int x, ref int y) => ref b ? ref y : ref x; Diagnostic(ErrorCode.ERR_RefReturnParameter, "x").WithArguments("x").WithLocation(4, 83)); } @@ -8616,13 +9175,13 @@ static void F3(ref int x3, scoped ref int y3) // (9,13): error CS8347: Cannot use a result of '.Invoke(R, R)' in this context because it may expose variables referenced by parameter '0' outside of their declaration scope // z = f(y1, x1); // 1 Diagnostic(ErrorCode.ERR_EscapeCall, "f(y1, x1)").WithArguments(".Invoke(R, R)", "0").WithLocation(9, 13), - // (9,15): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + // (9,15): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // z = f(y1, x1); // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "y1").WithArguments("R").WithLocation(9, 15), + Diagnostic(ErrorCode.ERR_EscapeVariable, "y1").WithArguments("R").WithLocation(9, 15), // (16,13): error CS8347: Cannot use a result of '.Invoke(ref R, ref R)' in this context because it may expose variables referenced by parameter '0' outside of their declaration scope // z = f(ref y2, ref x2); // 2 Diagnostic(ErrorCode.ERR_EscapeCall, "f(ref y2, ref x2)").WithArguments(".Invoke(ref R, ref R)", "0").WithLocation(16, 13), - // (16,19): error CS8166: Cannot return a parameter by reference 'y2' because it is not a ref or out parameter + // (16,19): error CS8166: Cannot return a parameter by reference 'y2' because it is not a ref parameter // z = f(ref y2, ref x2); // 2 Diagnostic(ErrorCode.ERR_RefReturnParameter, "y2").WithArguments("y2").WithLocation(16, 19)); @@ -8667,7 +9226,6 @@ static void Main() } }"; var comp = CreateCompilation(source); - // PROTOTYPE: Should we also report ERR_CannotInferDelegateType? comp.VerifyDiagnostics( // (21,18): error CS0121: The call is ambiguous between the following methods or properties: 'E1.F1(object, R)' and 'E2.F1(object, R)' // var d1 = o.F1; @@ -8842,9 +9400,9 @@ static void Main() }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (9,33): error CS8352: Cannot use local 'x1' in this context because it may expose referenced variables outside of their declaration scope + // (9,33): error CS8352: Cannot use variable 'x1' in this context because it may expose referenced variables outside of their declaration scope // scoped ref var x3 = ref x1; - Diagnostic(ErrorCode.ERR_EscapeLocal, "x1").WithArguments("x1").WithLocation(9, 33), + Diagnostic(ErrorCode.ERR_EscapeVariable, "x1").WithArguments("x1").WithLocation(9, 33), // (11,16): error CS8986: The 'scoped' modifier can be used for refs and ref struct values only. // scoped var y1 = new S(); // 1 Diagnostic(ErrorCode.ERR_ScopedRefAndRefStructOnly, "var").WithLocation(11, 16), @@ -8963,15 +9521,15 @@ class Program }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (5,43): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + // (5,43): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // static R F1(scoped R r1) => r1; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1").WithArguments("R").WithLocation(5, 43), - // (8,47): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1").WithArguments("R").WithLocation(5, 43), + // (8,47): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static R F4(ref scoped R r4) => r4; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r4").WithArguments("ref R").WithLocation(8, 47), - // (9,54): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r4").WithArguments("ref R").WithLocation(8, 47), + // (9,54): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static R F5(scoped ref scoped R r5) => r5; // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r5").WithArguments("ref R").WithLocation(9, 54)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r5").WithArguments("ref R").WithLocation(9, 54)); } [Fact] @@ -8990,19 +9548,19 @@ class Program }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (4,44): error CS8166: Cannot return a parameter by reference 'r0' because it is not a ref or out parameter + // (4,44): error CS8166: Cannot return a parameter by reference 'r0' because it is not a ref parameter // static ref R F0(R r0) => ref r0; // 1 Diagnostic(ErrorCode.ERR_RefReturnParameter, "r0").WithArguments("r0").WithLocation(4, 44), - // (5,51): error CS8166: Cannot return a parameter by reference 'r1' because it is not a ref or out parameter + // (5,51): error CS8166: Cannot return a parameter by reference 'r1' because it is not a ref parameter // static ref R F1(scoped R r1) => ref r1; // 2 Diagnostic(ErrorCode.ERR_RefReturnParameter, "r1").WithArguments("r1").WithLocation(5, 51), - // (7,55): error CS8166: Cannot return a parameter by reference 'r3' because it is not a ref or out parameter + // (7,55): error CS8166: Cannot return a parameter by reference 'r3' because it is not a ref parameter // static ref R F3(scoped ref R r3) => ref r3; // 3 Diagnostic(ErrorCode.ERR_RefReturnParameter, "r3").WithArguments("r3").WithLocation(7, 55), - // (8,55): error CS8166: Cannot return a parameter by reference 'r4' because it is not a ref or out parameter + // (8,55): error CS8166: Cannot return a parameter by reference 'r4' because it is not a ref parameter // static ref R F4(ref scoped R r4) => ref r4; // 4 Diagnostic(ErrorCode.ERR_RefReturnParameter, "r4").WithArguments("r4").WithLocation(8, 55), - // (9,62): error CS8166: Cannot return a parameter by reference 'r5' because it is not a ref or out parameter + // (9,62): error CS8166: Cannot return a parameter by reference 'r5' because it is not a ref parameter // static ref R F5(scoped ref scoped R r5) => ref r5; // 5 Diagnostic(ErrorCode.ERR_RefReturnParameter, "r5").WithArguments("r5").WithLocation(9, 62)); } @@ -9047,15 +9605,15 @@ static R F5(scoped ref scoped R r5) }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (12,16): error CS8352: Cannot use local 'l1' in this context because it may expose referenced variables outside of their declaration scope + // (12,16): error CS8352: Cannot use variable 'l1' in this context because it may expose referenced variables outside of their declaration scope // return l1; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l1").WithArguments("l1").WithLocation(12, 16), - // (27,16): error CS8352: Cannot use local 'l4' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l1").WithArguments("l1").WithLocation(12, 16), + // (27,16): error CS8352: Cannot use variable 'l4' in this context because it may expose referenced variables outside of their declaration scope // return l4; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l4").WithArguments("l4").WithLocation(27, 16), - // (32,16): error CS8352: Cannot use local 'l5' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l4").WithArguments("l4").WithLocation(27, 16), + // (32,16): error CS8352: Cannot use variable 'l5' in this context because it may expose referenced variables outside of their declaration scope // return l5; // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l5").WithArguments("l5").WithLocation(32, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "l5").WithArguments("l5").WithLocation(32, 16)); } [Fact] @@ -9158,24 +9716,24 @@ static R F5(scoped ref scoped R r5) }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (7,16): error CS8352: Cannot use local 'l0' in this context because it may expose referenced variables outside of their declaration scope + // (7,16): error CS8352: Cannot use variable 'l0' in this context because it may expose referenced variables outside of their declaration scope // return l0; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l0").WithArguments("l0").WithLocation(7, 16), - // (12,16): error CS8352: Cannot use local 'l1' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l0").WithArguments("l0").WithLocation(7, 16), + // (12,16): error CS8352: Cannot use variable 'l1' in this context because it may expose referenced variables outside of their declaration scope // return l1; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l1").WithArguments("l1").WithLocation(12, 16), - // (17,16): error CS8352: Cannot use local 'l2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l1").WithArguments("l1").WithLocation(12, 16), + // (17,16): error CS8352: Cannot use variable 'l2' in this context because it may expose referenced variables outside of their declaration scope // return l2; // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l2").WithArguments("l2").WithLocation(17, 16), - // (22,16): error CS8352: Cannot use local 'l3' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l2").WithArguments("l2").WithLocation(17, 16), + // (22,16): error CS8352: Cannot use variable 'l3' in this context because it may expose referenced variables outside of their declaration scope // return l3; // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l3").WithArguments("l3").WithLocation(22, 16), - // (27,16): error CS8352: Cannot use local 'l4' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l3").WithArguments("l3").WithLocation(22, 16), + // (27,16): error CS8352: Cannot use variable 'l4' in this context because it may expose referenced variables outside of their declaration scope // return l4; // 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l4").WithArguments("l4").WithLocation(27, 16), - // (32,16): error CS8352: Cannot use local 'l5' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l4").WithArguments("l4").WithLocation(27, 16), + // (32,16): error CS8352: Cannot use variable 'l5' in this context because it may expose referenced variables outside of their declaration scope // return l5; // 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l5").WithArguments("l5").WithLocation(32, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "l5").WithArguments("l5").WithLocation(32, 16)); } [Fact] @@ -9278,15 +9836,15 @@ static R F5(scoped ref scoped R r5) }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (12,16): error CS8352: Cannot use local 'l1' in this context because it may expose referenced variables outside of their declaration scope + // (12,16): error CS8352: Cannot use variable 'l1' in this context because it may expose referenced variables outside of their declaration scope // return l1; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l1").WithArguments("l1").WithLocation(12, 16), - // (27,16): error CS8352: Cannot use local 'l4' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l1").WithArguments("l1").WithLocation(12, 16), + // (27,16): error CS8352: Cannot use variable 'l4' in this context because it may expose referenced variables outside of their declaration scope // return l4; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l4").WithArguments("l4").WithLocation(27, 16), - // (32,16): error CS8352: Cannot use local 'l5' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l4").WithArguments("l4").WithLocation(27, 16), + // (32,16): error CS8352: Cannot use variable 'l5' in this context because it may expose referenced variables outside of their declaration scope // return l5; // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l5").WithArguments("l5").WithLocation(32, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "l5").WithArguments("l5").WithLocation(32, 16)); } [Fact] @@ -9386,15 +9944,15 @@ static R F5(scoped ref scoped R r5) }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (11,36): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + // (11,36): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // scoped ref R l1 = ref r1; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1").WithArguments("R").WithLocation(11, 36), - // (26,36): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1").WithArguments("R").WithLocation(11, 36), + // (26,36): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // scoped ref R l4 = ref r4; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r4").WithArguments("ref R").WithLocation(26, 36), - // (31,36): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r4").WithArguments("ref R").WithLocation(26, 36), + // (31,36): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // scoped ref R l5 = ref r5; // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r5").WithArguments("ref R").WithLocation(31, 36)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r5").WithArguments("ref R").WithLocation(31, 36)); } [Fact] @@ -9440,9 +9998,9 @@ static ref R F5(scoped ref scoped R r5) // (7,20): error CS8157: Cannot return 'l0' by reference because it was initialized to a value that cannot be returned by reference // return ref l0; // 1 Diagnostic(ErrorCode.ERR_RefReturnNonreturnableLocal, "l0").WithArguments("l0").WithLocation(7, 20), - // (11,36): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + // (11,36): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // scoped ref R l1 = ref r1; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1").WithArguments("R").WithLocation(11, 36), + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1").WithArguments("R").WithLocation(11, 36), // (12,20): error CS8157: Cannot return 'l1' by reference because it was initialized to a value that cannot be returned by reference // return ref l1; // 3 Diagnostic(ErrorCode.ERR_RefReturnNonreturnableLocal, "l1").WithArguments("l1").WithLocation(12, 20), @@ -9452,15 +10010,15 @@ static ref R F5(scoped ref scoped R r5) // (22,20): error CS8157: Cannot return 'l3' by reference because it was initialized to a value that cannot be returned by reference // return ref l3; // 5 Diagnostic(ErrorCode.ERR_RefReturnNonreturnableLocal, "l3").WithArguments("l3").WithLocation(22, 20), - // (26,36): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (26,36): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // scoped ref R l4 = ref r4; // 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r4").WithArguments("ref R").WithLocation(26, 36), + Diagnostic(ErrorCode.ERR_EscapeVariable, "r4").WithArguments("ref R").WithLocation(26, 36), // (27,20): error CS8157: Cannot return 'l4' by reference because it was initialized to a value that cannot be returned by reference // return ref l4; // 7 Diagnostic(ErrorCode.ERR_RefReturnNonreturnableLocal, "l4").WithArguments("l4").WithLocation(27, 20), - // (31,36): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (31,36): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // scoped ref R l5 = ref r5; // 8 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r5").WithArguments("ref R").WithLocation(31, 36), + Diagnostic(ErrorCode.ERR_EscapeVariable, "r5").WithArguments("ref R").WithLocation(31, 36), // (32,20): error CS8157: Cannot return 'l5' by reference because it was initialized to a value that cannot be returned by reference // return ref l5; // 9 Diagnostic(ErrorCode.ERR_RefReturnNonreturnableLocal, "l5").WithArguments("l5").WithLocation(32, 20)); @@ -9506,24 +10064,24 @@ static R F5(scoped ref scoped R r5) }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (7,16): error CS8352: Cannot use local 'l0' in this context because it may expose referenced variables outside of their declaration scope + // (7,16): error CS8352: Cannot use variable 'l0' in this context because it may expose referenced variables outside of their declaration scope // return l0; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l0").WithArguments("l0").WithLocation(7, 16), - // (12,16): error CS8352: Cannot use local 'l1' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l0").WithArguments("l0").WithLocation(7, 16), + // (12,16): error CS8352: Cannot use variable 'l1' in this context because it may expose referenced variables outside of their declaration scope // return l1; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l1").WithArguments("l1").WithLocation(12, 16), - // (17,16): error CS8352: Cannot use local 'l2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l1").WithArguments("l1").WithLocation(12, 16), + // (17,16): error CS8352: Cannot use variable 'l2' in this context because it may expose referenced variables outside of their declaration scope // return l2; // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l2").WithArguments("l2").WithLocation(17, 16), - // (22,16): error CS8352: Cannot use local 'l3' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l2").WithArguments("l2").WithLocation(17, 16), + // (22,16): error CS8352: Cannot use variable 'l3' in this context because it may expose referenced variables outside of their declaration scope // return l3; // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l3").WithArguments("l3").WithLocation(22, 16), - // (27,16): error CS8352: Cannot use local 'l4' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l3").WithArguments("l3").WithLocation(22, 16), + // (27,16): error CS8352: Cannot use variable 'l4' in this context because it may expose referenced variables outside of their declaration scope // return l4; // 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l4").WithArguments("l4").WithLocation(27, 16), - // (32,16): error CS8352: Cannot use local 'l5' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l4").WithArguments("l4").WithLocation(27, 16), + // (32,16): error CS8352: Cannot use variable 'l5' in this context because it may expose referenced variables outside of their declaration scope // return l5; // 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l5").WithArguments("l5").WithLocation(32, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "l5").WithArguments("l5").WithLocation(32, 16)); } [Fact] @@ -9626,24 +10184,24 @@ static R F5(scoped ref scoped R r5) }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (7,16): error CS8352: Cannot use local 'l0' in this context because it may expose referenced variables outside of their declaration scope + // (7,16): error CS8352: Cannot use variable 'l0' in this context because it may expose referenced variables outside of their declaration scope // return l0; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l0").WithArguments("l0").WithLocation(7, 16), - // (12,16): error CS8352: Cannot use local 'l1' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l0").WithArguments("l0").WithLocation(7, 16), + // (12,16): error CS8352: Cannot use variable 'l1' in this context because it may expose referenced variables outside of their declaration scope // return l1; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l1").WithArguments("l1").WithLocation(12, 16), - // (17,16): error CS8352: Cannot use local 'l2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l1").WithArguments("l1").WithLocation(12, 16), + // (17,16): error CS8352: Cannot use variable 'l2' in this context because it may expose referenced variables outside of their declaration scope // return l2; // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l2").WithArguments("l2").WithLocation(17, 16), - // (22,16): error CS8352: Cannot use local 'l3' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l2").WithArguments("l2").WithLocation(17, 16), + // (22,16): error CS8352: Cannot use variable 'l3' in this context because it may expose referenced variables outside of their declaration scope // return l3; // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l3").WithArguments("l3").WithLocation(22, 16), - // (27,16): error CS8352: Cannot use local 'l4' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l3").WithArguments("l3").WithLocation(22, 16), + // (27,16): error CS8352: Cannot use variable 'l4' in this context because it may expose referenced variables outside of their declaration scope // return l4; // 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l4").WithArguments("l4").WithLocation(27, 16), - // (32,16): error CS8352: Cannot use local 'l5' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "l4").WithArguments("l4").WithLocation(27, 16), + // (32,16): error CS8352: Cannot use variable 'l5' in this context because it may expose referenced variables outside of their declaration scope // return l5; // 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "l5").WithArguments("l5").WithLocation(32, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "l5").WithArguments("l5").WithLocation(32, 16)); } [Fact] @@ -9901,27 +10459,27 @@ class Program }}"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (12,55): error CS8352: Cannot use local 'R' in this context because it may expose referenced variables outside of their declaration scope + // (12,55): error CS8352: Cannot use variable 'R' in this context because it may expose referenced variables outside of their declaration scope // static ref T F4(scoped R r) => ref r.F; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r.F").WithArguments("R").WithLocation(12, 55), - // (16,59): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r.F").WithArguments("R").WithLocation(12, 55), + // (16,59): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static ref T F8(ref scoped R r) => ref r.F; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r.F").WithArguments("ref R").WithLocation(16, 59), - // (17,78): error CS8352: Cannot use local 'out R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r.F").WithArguments("ref R").WithLocation(16, 59), + // (17,78): error CS8352: Cannot use variable 'out R' in this context because it may expose referenced variables outside of their declaration scope // static ref T F9(out scoped R r) { r = default; return ref r.F; } // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r.F").WithArguments("out R").WithLocation(17, 78), - // (18,58): error CS8352: Cannot use local 'in R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r.F").WithArguments("out R").WithLocation(17, 78), + // (18,58): error CS8352: Cannot use variable 'in R' in this context because it may expose referenced variables outside of their declaration scope // static ref T FA(in scoped R r) => ref r.F; // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r.F").WithArguments("in R").WithLocation(18, 58), - // (19,66): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r.F").WithArguments("in R").WithLocation(18, 58), + // (19,66): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // static ref T FB(scoped ref scoped R r) => ref r.F; // 5 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r.F").WithArguments("ref R").WithLocation(19, 66), - // (20,85): error CS8352: Cannot use local 'out R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r.F").WithArguments("ref R").WithLocation(19, 66), + // (20,85): error CS8352: Cannot use variable 'out R' in this context because it may expose referenced variables outside of their declaration scope // static ref T FC(scoped out scoped R r) { r = default; return ref r.F; } // 6 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r.F").WithArguments("out R").WithLocation(20, 85), - // (21,65): error CS8352: Cannot use local 'in R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r.F").WithArguments("out R").WithLocation(20, 85), + // (21,65): error CS8352: Cannot use variable 'in R' in this context because it may expose referenced variables outside of their declaration scope // static ref T FD(scoped in scoped R r) => ref r.F; // 7 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r.F").WithArguments("in R").WithLocation(21, 65)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r.F").WithArguments("in R").WithLocation(21, 65)); } [Fact] @@ -9949,13 +10507,13 @@ static ref readonly T F2(scoped ref T t) }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (11,20): error CS8352: Cannot use local 'r1' in this context because it may expose referenced variables outside of their declaration scope + // (11,20): error CS8352: Cannot use variable 'r1' in this context because it may expose referenced variables outside of their declaration scope // return ref r1.F; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1.F").WithArguments("r1").WithLocation(11, 20), + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1.F").WithArguments("r1").WithLocation(11, 20), // (16,14): error CS8347: Cannot use a result of 'R.R(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // r2 = new R(ref t); // 2 Diagnostic(ErrorCode.ERR_EscapeCall, "new R(ref t)").WithArguments("R.R(ref T)", "t").WithLocation(16, 14), - // (16,27): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (16,27): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // r2 = new R(ref t); // 2 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(16, 27)); } @@ -9984,12 +10542,12 @@ static ref readonly T F2(scoped in T t) }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (11,20): error CS8352: Cannot use local 'r1' in this context because it may expose referenced variables outside of their declaration scope + // (11,20): error CS8352: Cannot use variable 'r1' in this context because it may expose referenced variables outside of their declaration scope // return ref r1.F; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1.F").WithArguments("r1").WithLocation(11, 20), - // (16,20): error CS8352: Cannot use local 'r2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1.F").WithArguments("r1").WithLocation(11, 20), + // (16,20): error CS8352: Cannot use variable 'r2' in this context because it may expose referenced variables outside of their declaration scope // return ref r2.F; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r2.F").WithArguments("r2").WithLocation(16, 20)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r2.F").WithArguments("r2").WithLocation(16, 20)); } [Fact] @@ -10009,24 +10567,23 @@ class Program static R F4(scoped out T t, T tValue) { t = tValue; return new R(ref t); } // 3 }"; var comp = CreateCompilation(source); - // PROTOTYPE: Update ERR_RefReturnParameter message or report a distinct error, because the parameter is an 'out' parameter. comp.VerifyDiagnostics( // (9,63): error CS8347: Cannot use a result of 'R.R(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // static R F2(out T t, T tValue) { t = tValue; return new R(ref t); } // 1 Diagnostic(ErrorCode.ERR_EscapeCall, "new R(ref t)").WithArguments("R.R(ref T)", "t").WithLocation(9, 63), - // (9,76): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (9,76): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static R F2(out T t, T tValue) { t = tValue; return new R(ref t); } // 1 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(9, 76), // (10,42): error CS8347: Cannot use a result of 'R.R(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // static R F3(scoped ref T t) => new R(ref t); // 2 Diagnostic(ErrorCode.ERR_EscapeCall, "new R(ref t)").WithArguments("R.R(ref T)", "t").WithLocation(10, 42), - // (10,55): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (10,55): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static R F3(scoped ref T t) => new R(ref t); // 2 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(10, 55), // (11,70): error CS8347: Cannot use a result of 'R.R(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // static R F4(scoped out T t, T tValue) { t = tValue; return new R(ref t); } // 3 Diagnostic(ErrorCode.ERR_EscapeCall, "new R(ref t)").WithArguments("R.R(ref T)", "t").WithLocation(11, 70), - // (11,83): error CS8166: Cannot return a parameter by reference 't' because it is not a ref or out parameter + // (11,83): error CS8166: Cannot return a parameter by reference 't' because it is not a ref parameter // static R F4(scoped out T t, T tValue) { t = tValue; return new R(ref t); } // 3 Diagnostic(ErrorCode.ERR_RefReturnParameter, "t").WithArguments("t").WithLocation(11, 83)); } @@ -10056,15 +10613,15 @@ class Program }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (14,44): error CS8352: Cannot use local 'R1' in this context because it may expose referenced variables outside of their declaration scope + // (14,44): error CS8352: Cannot use variable 'R1' in this context because it may expose referenced variables outside of their declaration scope // static R0 F1(scoped R1 r1) => r1.F1; // 1 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1.F1").WithArguments("R1").WithLocation(14, 44), - // (17,48): error CS8352: Cannot use local 'ref R1' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1.F1").WithArguments("R1").WithLocation(14, 44), + // (17,48): error CS8352: Cannot use variable 'ref R1' in this context because it may expose referenced variables outside of their declaration scope // static R0 F4(ref scoped R1 r4) => r4.F1; // 2 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r4.F1").WithArguments("ref R1").WithLocation(17, 48), - // (18,55): error CS8352: Cannot use local 'ref R1' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r4.F1").WithArguments("ref R1").WithLocation(17, 48), + // (18,55): error CS8352: Cannot use variable 'ref R1' in this context because it may expose referenced variables outside of their declaration scope // static R0 F5(scoped ref scoped R1 r5) => r5.F1; // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "r5.F1").WithArguments("ref R1").WithLocation(18, 55)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r5.F1").WithArguments("ref R1").WithLocation(18, 55)); } [Fact] @@ -10581,30 +11138,30 @@ static R F8() }"; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (16,16): error CS8352: Cannot use local 'r1' in this context because it may expose referenced variables outside of their declaration scope + // (16,16): error CS8352: Cannot use variable 'r1' in this context because it may expose referenced variables outside of their declaration scope // return r1; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1").WithArguments("r1").WithLocation(16, 16), - // (23,16): error CS8352: Cannot use local 'r2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1").WithArguments("r1").WithLocation(16, 16), + // (23,16): error CS8352: Cannot use variable 'r2' in this context because it may expose referenced variables outside of their declaration scope // return r2; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r2").WithArguments("r2").WithLocation(23, 16), + Diagnostic(ErrorCode.ERR_EscapeVariable, "r2").WithArguments("r2").WithLocation(23, 16), // (29,9): error CS8374: Cannot ref-assign 't' to 'F' because 't' has a narrower escape scope than 'F'. // r3.F = ref t; Diagnostic(ErrorCode.ERR_RefAssignNarrower, "r3.F = ref t").WithArguments("F", "t").WithLocation(29, 9), - // (39,16): error CS8352: Cannot use local 'r4' in this context because it may expose referenced variables outside of their declaration scope + // (39,16): error CS8352: Cannot use variable 'r4' in this context because it may expose referenced variables outside of their declaration scope // return r4; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r4").WithArguments("r4").WithLocation(39, 16), - // (46,16): error CS8352: Cannot use local 'r5' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r4").WithArguments("r4").WithLocation(39, 16), + // (46,16): error CS8352: Cannot use variable 'r5' in this context because it may expose referenced variables outside of their declaration scope // return r5; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r5").WithArguments("r5").WithLocation(46, 16), - // (53,16): error CS8352: Cannot use local 'r6' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r5").WithArguments("r5").WithLocation(46, 16), + // (53,16): error CS8352: Cannot use variable 'r6' in this context because it may expose referenced variables outside of their declaration scope // return r6; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r6").WithArguments("r6").WithLocation(53, 16), + Diagnostic(ErrorCode.ERR_EscapeVariable, "r6").WithArguments("r6").WithLocation(53, 16), // (59,9): error CS8374: Cannot ref-assign 't' to 'F' because 't' has a narrower escape scope than 'F'. // r7.F = ref t; Diagnostic(ErrorCode.ERR_RefAssignNarrower, "r7.F = ref t").WithArguments("F", "t").WithLocation(59, 9), - // (69,16): error CS8352: Cannot use local 'r8' in this context because it may expose referenced variables outside of their declaration scope + // (69,16): error CS8352: Cannot use variable 'r8' in this context because it may expose referenced variables outside of their declaration scope // return r8; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r8").WithArguments("r8").WithLocation(69, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r8").WithArguments("r8").WithLocation(69, 16)); } [Fact] @@ -10676,30 +11233,30 @@ static R F8(T t) }"; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (15,16): error CS8352: Cannot use local 'r1' in this context because it may expose referenced variables outside of their declaration scope + // (15,16): error CS8352: Cannot use variable 'r1' in this context because it may expose referenced variables outside of their declaration scope // return r1; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1").WithArguments("r1").WithLocation(15, 16), - // (21,16): error CS8352: Cannot use local 'r2' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1").WithArguments("r1").WithLocation(15, 16), + // (21,16): error CS8352: Cannot use variable 'r2' in this context because it may expose referenced variables outside of their declaration scope // return r2; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r2").WithArguments("r2").WithLocation(21, 16), + Diagnostic(ErrorCode.ERR_EscapeVariable, "r2").WithArguments("r2").WithLocation(21, 16), // (26,9): error CS8374: Cannot ref-assign 't' to 'F' because 't' has a narrower escape scope than 'F'. // r3.F = ref t; Diagnostic(ErrorCode.ERR_RefAssignNarrower, "r3.F = ref t").WithArguments("F", "t").WithLocation(26, 9), - // (35,16): error CS8352: Cannot use local 'r4' in this context because it may expose referenced variables outside of their declaration scope + // (35,16): error CS8352: Cannot use variable 'r4' in this context because it may expose referenced variables outside of their declaration scope // return r4; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r4").WithArguments("r4").WithLocation(35, 16), - // (41,16): error CS8352: Cannot use local 'r5' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r4").WithArguments("r4").WithLocation(35, 16), + // (41,16): error CS8352: Cannot use variable 'r5' in this context because it may expose referenced variables outside of their declaration scope // return r5; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r5").WithArguments("r5").WithLocation(41, 16), - // (47,16): error CS8352: Cannot use local 'r6' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r5").WithArguments("r5").WithLocation(41, 16), + // (47,16): error CS8352: Cannot use variable 'r6' in this context because it may expose referenced variables outside of their declaration scope // return r6; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r6").WithArguments("r6").WithLocation(47, 16), + Diagnostic(ErrorCode.ERR_EscapeVariable, "r6").WithArguments("r6").WithLocation(47, 16), // (52,9): error CS8374: Cannot ref-assign 't' to 'F' because 't' has a narrower escape scope than 'F'. // r7.F = ref t; Diagnostic(ErrorCode.ERR_RefAssignNarrower, "r7.F = ref t").WithArguments("F", "t").WithLocation(52, 9), - // (61,16): error CS8352: Cannot use local 'r8' in this context because it may expose referenced variables outside of their declaration scope + // (61,16): error CS8352: Cannot use variable 'r8' in this context because it may expose referenced variables outside of their declaration scope // return r8; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r8").WithArguments("r8").WithLocation(61, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r8").WithArguments("r8").WithLocation(61, 16)); } [Fact] @@ -10858,7 +11415,7 @@ static void M(R r) { } // (10,16): error CS8347: Cannot use a result of 'R.R(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // this = new R(ref t1); Diagnostic(ErrorCode.ERR_EscapeCall, "new R(ref t1)").WithArguments("R.R(ref T)", "t").WithLocation(10, 16), - // (10,29): error CS8166: Cannot return a parameter by reference 't1' because it is not a ref or out parameter + // (10,29): error CS8166: Cannot return a parameter by reference 't1' because it is not a ref parameter // this = new R(ref t1); Diagnostic(ErrorCode.ERR_RefReturnParameter, "t1").WithArguments("t1").WithLocation(10, 29), // (16,9): error CS8374: Cannot ref-assign 't2' to 'F' because 't2' has a narrower escape scope than 'F'. @@ -10867,7 +11424,7 @@ static void M(R r) { } // (21,16): error CS8347: Cannot use a result of 'R.Create(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // this = Create(ref t3); Diagnostic(ErrorCode.ERR_EscapeCall, "Create(ref t3)").WithArguments("R.Create(ref T)", "t").WithLocation(21, 16), - // (21,27): error CS8166: Cannot return a parameter by reference 't3' because it is not a ref or out parameter + // (21,27): error CS8166: Cannot return a parameter by reference 't3' because it is not a ref parameter // this = Create(ref t3); Diagnostic(ErrorCode.ERR_RefReturnParameter, "t3").WithArguments("t3").WithLocation(21, 27), // (27,9): error CS8374: Cannot ref-assign 't4' to 'F' because 't4' has a narrower escape scope than 'F'. @@ -10900,7 +11457,7 @@ static void M(R r) { } // (13,16): error CS8347: Cannot use a result of 'R.R(ref T)' in this context because it may expose variables referenced by parameter 't' outside of their declaration scope // this = new R(ref t2); Diagnostic(ErrorCode.ERR_EscapeCall, "new R(ref t2)").WithArguments("R.R(ref T)", "t").WithLocation(13, 16), - // (13,29): error CS8166: Cannot return a parameter by reference 't2' because it is not a ref or out parameter + // (13,29): error CS8166: Cannot return a parameter by reference 't2' because it is not a ref parameter // this = new R(ref t2); Diagnostic(ErrorCode.ERR_RefReturnParameter, "t2").WithArguments("t2").WithLocation(13, 29)); } @@ -10939,12 +11496,12 @@ static void M(R r) { } // (4,19): warning CS0169: The field 'R.F' is never used // private ref T F; Diagnostic(ErrorCode.WRN_UnreferencedField, "F").WithArguments("R.F").WithLocation(4, 19), - // (17,16): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + // (17,16): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // this = r3; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r3").WithArguments("ref R").WithLocation(17, 16), - // (22,16): error CS8352: Cannot use local 'ref R' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "r3").WithArguments("ref R").WithLocation(17, 16), + // (22,16): error CS8352: Cannot use variable 'ref R' in this context because it may expose referenced variables outside of their declaration scope // this = r4; - Diagnostic(ErrorCode.ERR_EscapeLocal, "r4").WithArguments("ref R").WithLocation(22, 16)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r4").WithArguments("ref R").WithLocation(22, 16)); } [Fact] @@ -10997,9 +11554,9 @@ static void F(out R r) }"; var comp = CreateCompilationWithSpanAndMemoryExtensions(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion)); comp.VerifyDiagnostics( - // (13,9): error CS8352: Cannot use local 'r1' in this context because it may expose referenced variables outside of their declaration scope + // (13,9): error CS8352: Cannot use variable 'r1' in this context because it may expose referenced variables outside of their declaration scope // r1.F(out r); - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1").WithArguments("r1").WithLocation(13, 9)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1").WithArguments("r1").WithLocation(13, 9)); } [Fact] @@ -11023,9 +11580,9 @@ static void F(out R r) }"; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (13,9): error CS8352: Cannot use local 'r1' in this context because it may expose referenced variables outside of their declaration scope + // (13,9): error CS8352: Cannot use variable 'r1' in this context because it may expose referenced variables outside of their declaration scope // r1.F(out r); - Diagnostic(ErrorCode.ERR_EscapeLocal, "r1").WithArguments("r1").WithLocation(13, 9)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "r1").WithArguments("r1").WithLocation(13, 9)); } [Theory] @@ -11053,19 +11610,53 @@ static void Main() // (12,9): error CS8350: This combination of arguments to 'R.F(out Span)' is disallowed because it may expose variables referenced by parameter 's' outside of their declaration scope // r.F(out s); Diagnostic(ErrorCode.ERR_CallArgMixing, "r.F(out s)").WithArguments("R.F(out System.Span)", "s").WithLocation(12, 9), - // (12,17): error CS8352: Cannot use local 's' in this context because it may expose referenced variables outside of their declaration scope + // (12,17): error CS8352: Cannot use variable 's' in this context because it may expose referenced variables outside of their declaration scope // r.F(out s); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s").WithArguments("s").WithLocation(12, 17)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "s").WithArguments("s").WithLocation(12, 17)); } - // PROTOTYPE: Test combinations of locals without initializers and later assignments where the local and the assignment value are { none, ref, scoped, ref scoped, scoped ref, scoped ref scoped }. - - // PROTOTYPE: Test with locals declared as { var, ref var, scoped var, ref scoped var, scoped ref var, scoped ref scoped var }. - - // PROTOTYPE: Test scope of 'in' argument when the argument is a literal or rvalue. F(new object()) for F(unscoped in object o) for instance. - - // PROTOTYPE: Test `const scoped int local = 0;`. Are there other invalid combinations of modifiers? + [Theory] + [InlineData(LanguageVersion.CSharp10)] + [InlineData(LanguageVersionFacts.CSharpNext)] + public void ReturnThis_01(LanguageVersion languageVersion) + { + var source = +@"ref struct R +{ + R F1() => this; + ref R F2() => ref this; + ref readonly R F3() => ref this; +}"; + var comp = CreateCompilationWithSpanAndMemoryExtensions(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion)); + comp.VerifyDiagnostics( + // (4,23): error CS8170: Struct members cannot return 'this' or other instance members by reference + // ref R F2() => ref this; + Diagnostic(ErrorCode.ERR_RefReturnStructThis, "this").WithLocation(4, 23), + // (5,32): error CS8170: Struct members cannot return 'this' or other instance members by reference + // ref readonly R F3() => ref this; + Diagnostic(ErrorCode.ERR_RefReturnStructThis, "this").WithLocation(5, 32)); + } - // PROTOTYPE: Test (ref-)safe-to-escape for `return this;` + [Theory] + [InlineData(LanguageVersion.CSharp10)] + [InlineData(LanguageVersionFacts.CSharpNext)] + public void ReturnThis_02(LanguageVersion languageVersion) + { + var source = +@"readonly ref struct R +{ + R F1() => this; + ref R F2() => ref this; + ref readonly R F3() => ref this; +}"; + var comp = CreateCompilationWithSpanAndMemoryExtensions(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion)); + comp.VerifyDiagnostics( + // (4,23): error CS8354: Cannot return 'this' by reference. + // ref R F2() => ref this; + Diagnostic(ErrorCode.ERR_RefReturnThis, "this").WithLocation(4, 23), + // (5,32): error CS8170: Struct members cannot return 'this' or other instance members by reference + // ref readonly R F3() => ref this; + Diagnostic(ErrorCode.ERR_RefReturnStructThis, "this").WithLocation(5, 32)); + } } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs index f8dc8a1c253f6..feafeb141960d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs @@ -1723,7 +1723,7 @@ ref char Test1(char arg1, S1 arg2) // (28,24): error CS8169: Cannot return a member of local 'l' by reference because it is not a ref local // return ref l.x; Diagnostic(ErrorCode.ERR_RefReturnLocal2, "l").WithArguments("l").WithLocation(28, 24), - // (37,24): error CS8166: Cannot return a parameter by reference 'arg1' because it is not a ref or out parameter + // (37,24): error CS8166: Cannot return a parameter by reference 'arg1' because it is not a ref parameter // return ref arg1; Diagnostic(ErrorCode.ERR_RefReturnParameter, "arg1").WithArguments("arg1").WithLocation(37, 24), // (46,24): error CS8167: Cannot return a member of parameter 'arg2' by reference because it is not a ref or out parameter @@ -3496,7 +3496,7 @@ static ref int M(D d, int i, int j, object o) "; CreateCompilationWithMscorlib46(text).VerifyDiagnostics( - // (8,26): error CS8166: Cannot return a parameter by reference 'i' because it is not a ref or out parameter + // (8,26): error CS8166: Cannot return a parameter by reference 'i' because it is not a ref parameter // return ref d(ref i, ref j, o); Diagnostic(ErrorCode.ERR_RefReturnParameter, "i").WithArguments("i").WithLocation(8, 26), // (8,20): error CS8347: Cannot use a result of 'D.Invoke(ref int, ref int, object)' in this context because it may expose variables referenced by parameter 'i' outside of their declaration scope diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs index 5e6168f6c8abb..b56dbc0bd280b 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs @@ -35,9 +35,9 @@ void M() } }"); comp.VerifyDiagnostics( - // (11,15): error CS8352: Cannot use local 's1' in this context because it may expose referenced variables outside of their declaration scope + // (11,15): error CS8352: Cannot use variable 's1' in this context because it may expose referenced variables outside of their declaration scope // s2 = (s1 = s2); - Diagnostic(ErrorCode.ERR_EscapeLocal, "s1 = s2").WithArguments("s1").WithLocation(11, 15)); + Diagnostic(ErrorCode.ERR_EscapeVariable, "s1 = s2").WithArguments("s1").WithLocation(11, 15)); } [Fact] @@ -1608,39 +1608,39 @@ static void M2(ref Span x, out Span y) y = default; } }").VerifyDiagnostics( - // (16,24): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (16,24): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s1, out s2); // one - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(16, 24), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(16, 24), // (16,9): error CS8350: This combination of arguments to 'C.M2(ref Span, out Span)' is disallowed because it may expose variables referenced by parameter 'y' outside of their declaration scope // M2(ref s1, out s2); // one Diagnostic(ErrorCode.ERR_CallArgMixing, "M2(ref s1, out s2)").WithArguments("C.M2(ref System.Span, out System.Span)", "y").WithLocation(16, 9), - // (17,16): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (17,16): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s2, out s1); // two - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(17, 16), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(17, 16), // (17,9): error CS8350: This combination of arguments to 'C.M2(ref Span, out Span)' is disallowed because it may expose variables referenced by parameter 'x' outside of their declaration scope // M2(ref s2, out s1); // two Diagnostic(ErrorCode.ERR_CallArgMixing, "M2(ref s2, out s1)").WithArguments("C.M2(ref System.Span, out System.Span)", "x").WithLocation(17, 9), - // (19,24): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (19,24): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s1, out s2); // three - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(19, 24), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(19, 24), // (19,9): error CS8350: This combination of arguments to 'C.M2(ref Span, out Span)' is disallowed because it may expose variables referenced by parameter 'y' outside of their declaration scope // M2(ref s1, out s2); // three Diagnostic(ErrorCode.ERR_CallArgMixing, "M2(ref s1, out s2)").WithArguments("C.M2(ref System.Span, out System.Span)", "y").WithLocation(19, 9), - // (20,16): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (20,16): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(ref s2, out s1); // four - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(20, 16), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(20, 16), // (20,9): error CS8350: This combination of arguments to 'C.M2(ref Span, out Span)' is disallowed because it may expose variables referenced by parameter 'x' outside of their declaration scope // M2(ref s2, out s1); // four Diagnostic(ErrorCode.ERR_CallArgMixing, "M2(ref s2, out s1)").WithArguments("C.M2(ref System.Span, out System.Span)", "x").WithLocation(20, 9), - // (22,19): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (22,19): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(y: out s2, x: ref s1); // five - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(22, 19), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(22, 19), // (22,9): error CS8350: This combination of arguments to 'C.M2(ref Span, out Span)' is disallowed because it may expose variables referenced by parameter 'y' outside of their declaration scope // M2(y: out s2, x: ref s1); // five Diagnostic(ErrorCode.ERR_CallArgMixing, "M2(y: out s2, x: ref s1)").WithArguments("C.M2(ref System.Span, out System.Span)", "y").WithLocation(22, 9), - // (23,30): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (23,30): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(y: out s1, x: ref s2); // six - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(23, 30), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(23, 30), // (23,9): error CS8350: This combination of arguments to 'C.M2(ref Span, out Span)' is disallowed because it may expose variables referenced by parameter 'x' outside of their declaration scope // M2(y: out s1, x: ref s2); // six Diagnostic(ErrorCode.ERR_CallArgMixing, "M2(y: out s1, x: ref s2)").WithArguments("C.M2(ref System.Span, out System.Span)", "x").WithLocation(23, 9)); @@ -1673,15 +1673,15 @@ static void M2(__arglist) { } }").VerifyDiagnostics( - // (16,34): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (16,34): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(__arglist(ref s1, ref s2)); // one - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(16, 34), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(16, 34), // (16,9): error CS8350: This combination of arguments to 'C.M2(__arglist)' is disallowed because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // M2(__arglist(ref s1, ref s2)); // one Diagnostic(ErrorCode.ERR_CallArgMixing, "M2(__arglist(ref s1, ref s2))").WithArguments("C.M2(__arglist)", "__arglist").WithLocation(16, 9), - // (17,26): error CS8352: Cannot use local 's2' in this context because it may expose referenced variables outside of their declaration scope + // (17,26): error CS8352: Cannot use variable 's2' in this context because it may expose referenced variables outside of their declaration scope // M2(__arglist(ref s2, ref s1)); // two - Diagnostic(ErrorCode.ERR_EscapeLocal, "s2").WithArguments("s2").WithLocation(17, 26), + Diagnostic(ErrorCode.ERR_EscapeVariable, "s2").WithArguments("s2").WithLocation(17, 26), // (17,9): error CS8350: This combination of arguments to 'C.M2(__arglist)' is disallowed because it may expose variables referenced by parameter '__arglist' outside of their declaration scope // M2(__arglist(ref s2, ref s1)); // two Diagnostic(ErrorCode.ERR_CallArgMixing, "M2(__arglist(ref s2, ref s1))").WithArguments("C.M2(__arglist)", "__arglist").WithLocation(17, 9)); @@ -1796,12 +1796,12 @@ public static Span GetSpan4(int x) // (21,18): error CS8353: A result of a stackalloc expression of type 'Span' cannot be used in this context because it may be exposed outside of the containing method // 0 => stackalloc byte[10], // 2 Diagnostic(ErrorCode.ERR_EscapeStackAlloc, "stackalloc byte[10]").WithArguments("System.Span").WithLocation(21, 18), - // (36,16): error CS8352: Cannot use local 'span' in this context because it may expose referenced variables outside of their declaration scope + // (36,16): error CS8352: Cannot use variable 'span' in this context because it may expose referenced variables outside of their declaration scope // return span; // 3 - Diagnostic(ErrorCode.ERR_EscapeLocal, "span").WithArguments("span").WithLocation(36, 16), - // (43,16): error CS8352: Cannot use local 'span' in this context because it may expose referenced variables outside of their declaration scope + Diagnostic(ErrorCode.ERR_EscapeVariable, "span").WithArguments("span").WithLocation(36, 16), + // (43,16): error CS8352: Cannot use variable 'span' in this context because it may expose referenced variables outside of their declaration scope // return span; // 4 - Diagnostic(ErrorCode.ERR_EscapeLocal, "span").WithArguments("span").WithLocation(43, 16) + Diagnostic(ErrorCode.ERR_EscapeVariable, "span").WithArguments("span").WithLocation(43, 16) ); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs index b9ed5f26b2844..1355a19ac9cb8 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs @@ -8621,9 +8621,9 @@ public void Span_02() ", options: TestOptions.DebugExe, parseOptions: DefaultParseOptions); comp.VerifyDiagnostics( - // (7,13): error CS8352: Cannot use local 'inner' in this context because it may expose referenced variables outside of their declaration scope + // (7,13): error CS8352: Cannot use variable 'inner' in this context because it may expose referenced variables outside of their declaration scope // outer = inner; - Diagnostic(ErrorCode.ERR_EscapeLocal, "inner").WithArguments("inner").WithLocation(7, 13) + Diagnostic(ErrorCode.ERR_EscapeVariable, "inner").WithArguments("inner").WithLocation(7, 13) ); } diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationScopeParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationScopeParsingTests.cs index 855aa651e5613..63e6920d5edd1 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationScopeParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationScopeParsingTests.cs @@ -2309,7 +2309,6 @@ scoped ref struct B { } EOF(); } - // PROTOTYPE: 'scoped' before type declaration should be an error. [Fact] public void Type_02() { @@ -2471,7 +2470,6 @@ public void Type_04(LanguageVersion langVersion) EOF(); } - // PROTOTYPE: Should `ref scoped` be a parse error in a return value? Or should plain `scoped` be parsed as a modifier as well? [Theory] [InlineData(LanguageVersion.CSharp10)] [InlineData(LanguageVersionFacts.CSharpNext)] diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/RefFieldParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/RefFieldParsingTests.cs index fe2205e610306..1c6274e164fb9 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/RefFieldParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/RefFieldParsingTests.cs @@ -414,7 +414,7 @@ public void ReadOnlyRefParameter(LanguageVersion languageVersion) EOF(); } - // PROTOTYPE: Should ref expressions be supported in object initializers? + // https://github.com/dotnet/roslyn/issues/62120: Support ref field assignment in object initializers. [Theory] [InlineData(LanguageVersion.CSharp10)] [InlineData(LanguageVersionFacts.CSharpNext)] diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs index 7b5b77c70a41f..606bd67a0825e 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs @@ -1352,5 +1352,19 @@ public void TestNormalizeNestedFixedUsingStatements1() TestNormalizeStatement("using(a)fixed(int* b = null)c;", "using (a)\r\n fixed (int* b = null)\r\n c;"); TestNormalizeStatement("fixed(int* b = null)using(a)c;", "fixed (int* b = null)\r\n using (a)\r\n c;"); } + + [Fact] + public void TestNormalizeScopedParameters() + { + TestNormalizeStatement("static void F ( scoped R x , scoped ref R y , ref scoped R z ) { }", "static void F(scoped R x, scoped ref R y, ref scoped R z)\r\n{\r\n}"); + } + + [Fact] + public void TestNormalizeScopedLocals() + { + TestNormalizeStatement("scoped R x ;", "scoped R x;"); + TestNormalizeStatement("scoped ref R y ;", "scoped ref R y;"); + TestNormalizeStatement("ref scoped R z ;", "ref scoped R z;"); + } } } diff --git a/src/Compilers/Test/Utilities/CSharp/LifetimeAnnotationAttributesVisitor.cs b/src/Compilers/Test/Utilities/CSharp/LifetimeAnnotationAttributesVisitor.cs index 0997e00bf4b6c..6b967d09b0193 100644 --- a/src/Compilers/Test/Utilities/CSharp/LifetimeAnnotationAttributesVisitor.cs +++ b/src/Compilers/Test/Utilities/CSharp/LifetimeAnnotationAttributesVisitor.cs @@ -14,7 +14,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Test.Utilities { - // PROTOTYPE: Share common base class with NativeIntegerAttributesVisitor. internal sealed class LifetimeAnnotationAttributesVisitor : CSharpSymbolVisitor { internal static string GetString(PEModuleSymbol module) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/MemberRefMetadataDecoder.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/MemberRefMetadataDecoder.vb index c3851cf52f8e7..a1aaf1c031212 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/MemberRefMetadataDecoder.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/MemberRefMetadataDecoder.vb @@ -129,8 +129,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Private Shared Function FindFieldBySignature(targetTypeSymbol As TypeSymbol, targetMemberName As String, customModifiers As ImmutableArray(Of ModifierInfo(Of TypeSymbol)), type As TypeSymbol) As FieldSymbol For Each member In targetTypeSymbol.GetMembers(targetMemberName) Dim field = TryCast(member, FieldSymbol) - ' PROTOTYPE: Need to record RefKind and RefCustomModifiers on PEFieldSymbol - ' to differentiate fields that differ by RefKind or RefCustomModifiers here. + ' https://github.com/dotnet/roslyn/issues/62121: Record RefKind and RefCustomModifiers on + ' PEFieldSymbol to differentiate fields that differ by RefKind or RefCustomModifiers here. ' See RefFieldTests.MemberRefMetadataDecoder_FindFieldBySignature(). If field IsNot Nothing AndAlso TypeSymbol.Equals(field.Type, type, TypeCompareKind.AllIgnoreOptionsForVB) AndAlso diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEFieldSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEFieldSymbol.vb index a5042690d6130..235cf07de7c88 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEFieldSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEFieldSymbol.vb @@ -350,7 +350,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Dim fieldInfo As FieldInfo(Of TypeSymbol) = New MetadataDecoder(moduleSymbol, _containingType).DecodeFieldSignature(_handle) Dim type As TypeSymbol = fieldInfo.Type - ' PROTOTYPE: Report use-site diagnostic if fieldInfo.IsByRef. + ' https://github.com/dotnet/roslyn/issues/62121: Report use-site diagnostic if fieldInfo.IsByRef. type = TupleTypeDecoder.DecodeTupleTypesIfApplicable(type, _handle, moduleSymbol) diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/RefFieldTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/RefFieldTests.vb index a3ec47e364646..291b2da675598 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Semantics/RefFieldTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/RefFieldTests.vb @@ -44,7 +44,7 @@ BC30668: 'S(Of Integer)' is obsolete: 'Types with embedded references are not su ~~~~~~~~~~~~~ ) - ' PROTOTYPE: RefKind should be RefKind.Ref, or a use-site diagnostic should be generated, or both. + ' https://github.com/dotnet/roslyn/issues/62121: RefKind should be RefKind.Ref, or a use-site diagnostic should be generated, or both. Dim field = compB.GetMember(Of FieldSymbol)("S.F") VerifyFieldSymbol(field, "S(Of T).F As T", Microsoft.CodeAnalysis.RefKind.None, {}) Assert.Null(field.GetUseSiteErrorInfo()) @@ -73,11 +73,10 @@ Module Program End Module" Dim comp = CreateCompilation(sourceB, references:={refA}) - ' PROTOTYPE: A use-site diagnostic should be generated. + ' https://github.com/dotnet/roslyn/issues/62121: RefKind should be RefKind.Ref, or a use-site diagnostic should be generated, or both. comp.AssertTheseDiagnostics() - ' PROTOTYPE: RefKind should be RefKind.Ref and RefCustomModifiers should contain two items, - ' or a use-site diagnostic should be generated, or both. + ' https://github.com/dotnet/roslyn/issues/62121: RefKind should be RefKind.Ref, or a use-site diagnostic should be generated, or both. Dim field = comp.GetMember(Of FieldSymbol)("A.F") VerifyFieldSymbol(field, "A(Of T).F As T", Microsoft.CodeAnalysis.RefKind.None, {}) Assert.Null(field.GetUseSiteErrorInfo()) @@ -143,7 +142,7 @@ End Module" } AssertEx.Equal(expectedMembers, fieldMembers.Select(Function(f) f.ToTestDisplayString())) - ' PROTOTYPE: Not differentiating fields that differ by RefKind or RefCustomModifiers. + ' https://github.com/dotnet/roslyn/issues/62121: Not differentiating fields that differ by RefKind or RefCustomModifiers. ' See MemberRefMetadataDecoder.FindFieldBySignature(). Dim expectedReferences = {