Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/BinderFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal enum BinderFlags : uint
SuppressObsoleteChecks = 1 << 1,
ConstructorInitializer = 1 << 2,
FieldInitializer = 1 << 3,
// Previously used, can be reused in the future
InFixedStatement = 1 << 4, // body or initializer of a 'fixed' statement (used to disallow 'await')
CollectionInitializerAddMethod = 1 << 5, // used for collection initializer add method overload resolution diagnostics
AttributeArgument = 1 << 6,
GenericConstraintsClause = 1 << 7, // "where" clause (used for cycle checking)
Expand Down Expand Up @@ -120,6 +120,6 @@ internal enum BinderFlags : uint

// Groups

AllClearedAtExecutableCodeBoundary = InLockBody | InCatchBlock | InCatchFilter | InFinallyBlock | InTryBlockOfTryCatch | InNestedFinallyBlock,
AllClearedAtExecutableCodeBoundary = InLockBody | InCatchBlock | InCatchFilter | InFinallyBlock | InTryBlockOfTryCatch | InNestedFinallyBlock | InFixedStatement,
}
}
12 changes: 10 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Await.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,12 @@ private bool ReportBadAwaitWithoutAsync(SyntaxNodeOrToken nodeOrToken, BindingDi
/// <returns>True if errors were found.</returns>
private bool ReportBadAwaitContext(SyntaxNodeOrToken nodeOrToken, BindingDiagnosticBag diagnostics)
{
if (this.InUnsafeRegion && !this.Flags.Includes(BinderFlags.AllowAwaitInUnsafeContext))
// Better error location than `nodeOrToken` but using it only for new diagnostics to avoid test churn.
var awaitNodeOrToken = nodeOrToken.AsNode() is AwaitExpressionSyntax awaitExpression ? awaitExpression.AwaitKeyword : nodeOrToken;

if (this.Flags.Includes(BinderFlags.InFixedStatement) && !this.Flags.Includes(BinderFlags.AllowAwaitInUnsafeContext))
{
Error(diagnostics, ErrorCode.ERR_AwaitInUnsafeContext, nodeOrToken.GetLocation()!);
Error(diagnostics, ErrorCode.ERR_BadAwaitInFixed, awaitNodeOrToken);
return true;
}
else if (this.Flags.Includes(BinderFlags.InLockBody))
Expand All @@ -233,6 +236,11 @@ private bool ReportBadAwaitContext(SyntaxNodeOrToken nodeOrToken, BindingDiagnos
Error(diagnostics, ErrorCode.ERR_BadAwaitInCatchFilter, nodeOrToken.GetLocation()!);
return true;
}
else if (this.InUnsafeRegion && !this.Flags.Includes(BinderFlags.AllowAwaitInUnsafeContext) &&
!CheckFeatureAvailability(awaitNodeOrToken, MessageID.IDS_FeatureUnsafeEvolution, diagnostics))
{
return true;
}
else if (this.Flags.Includes(BinderFlags.InFinallyBlock) &&
(nodeOrToken.SyntaxTree as CSharpSyntaxTree)?.Options?.IsFeatureEnabled(MessageID.IDS_AwaitInCatchAndFinally) == false)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2819,6 +2819,8 @@ protected AssemblySymbol GetForwardedToAssembly(string name, int arity, ref Name
}

#nullable enable
internal static bool CheckFeatureAvailability(SyntaxNodeOrToken syntax, MessageID feature, BindingDiagnosticBag diagnostics, Location? location = null)
=> CheckFeatureAvailability(syntax.SyntaxTree!, feature, diagnostics.DiagnosticBag, (location, syntax), static tuple => tuple.location ?? tuple.syntax.GetLocation()!);

internal static bool CheckFeatureAvailability(SyntaxNode syntax, MessageID feature, BindingDiagnosticBag diagnostics, Location? location = null)
=> CheckFeatureAvailability(syntax, feature, diagnostics.DiagnosticBag, location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal sealed class FixedStatementBinder : LocalScopeBinder
private readonly FixedStatementSyntax _syntax;

public FixedStatementBinder(Binder enclosing, FixedStatementSyntax syntax)
: base(enclosing)
: base(enclosing, enclosing.Flags | BinderFlags.InFixedStatement)
Comment thread
jjonescz marked this conversation as resolved.
Resolved
{
Debug.Assert(syntax != null);
_syntax = syntax;
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3831,8 +3831,8 @@ Give the compiler some way to differentiate the methods. For example, you can gi
<data name="ERR_BadAwaitInStaticVariableInitializer" xml:space="preserve">
<value>The 'await' operator cannot be used in a static script variable initializer.</value>
</data>
<data name="ERR_AwaitInUnsafeContext" xml:space="preserve">
<value>Cannot await in an unsafe context</value>
<data name="ERR_BadAwaitInFixed" xml:space="preserve">
<value>Cannot await in the body or the initializer of a 'fixed' statement</value>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot await in the body or the initializer of a 'fixed' statement

Not blocking, but I would go with: "Cannot await in context of a 'fixed' statement"

</data>
<data name="ERR_BadAsyncLacksBody" xml:space="preserve">
<value>The 'async' modifier can only be used in methods that have a body.</value>
Expand Down
3 changes: 2 additions & 1 deletion src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ internal enum ErrorCode
ERR_BadAwaitArgIntrinsic = 4001,
// 4002 unused
ERR_BadAwaitAsIdentifier = 4003,
ERR_AwaitInUnsafeContext = 4004,
// ERR_AwaitInUnsafeContext = 4004, // replaced with a langversion error
Comment thread
jjonescz marked this conversation as resolved.
Resolved
ERR_UnsafeAsyncArgType = 4005,
ERR_VarargsAsync = 4006,
ERR_ByRefTypeAndAwait = 4007,
Expand Down Expand Up @@ -2505,6 +2505,7 @@ internal enum ErrorCode
ERR_NoBreakId = 9393,
ERR_NoContinueId = 9394,
ERR_ClosedBadDerivedTypesProperty = 9395,
ERR_BadAwaitInFixed = 9396,

// Note: you will need to do the following after adding errors:
// 1) Update ErrorFacts.IsBuildOnlyDiagnostic (src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs)
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ or ErrorCode.WRN_CLS_BadInterface
or ErrorCode.FTL_BadChecksumAlgorithm
or ErrorCode.ERR_BadAwaitArgIntrinsic
or ErrorCode.ERR_BadAwaitAsIdentifier
or ErrorCode.ERR_AwaitInUnsafeContext
or ErrorCode.ERR_BadAwaitInFixed
or ErrorCode.ERR_UnsafeAsyncArgType
or ErrorCode.ERR_VarargsAsync
or ErrorCode.ERR_BadAwaitArgVoidCall
Expand Down
10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading