-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't hoist ref locals #43463
Don't hoist ref locals #43463
Changes from 2 commits
5732dc4
f24c58a
00687ac
64f47e7
0e7f69f
bffb0cf
3025613
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5606,5 +5606,60 @@ static async Task Main() | |
var comp = CSharpTestBase.CreateCompilation(source, options: TestOptions.ReleaseExe); | ||
CompileAndVerify(comp, expectedOutput: "StructAwaitable"); | ||
} | ||
|
||
[Fact, WorkItem(40251, "https://github.com/dotnet/roslyn/issues/40251")] | ||
public void AssignRefAfterAwait() | ||
{ | ||
const string source = @" | ||
using System.Threading.Tasks; | ||
|
||
class IntCode | ||
{ | ||
public async Task Step(int i, Task t) | ||
{ | ||
await t; | ||
ReadMemory() = i switch | ||
{ | ||
_ => throw null | ||
}; | ||
} | ||
|
||
private ref long ReadMemory() => throw null; | ||
} | ||
"; | ||
|
||
var comp = CreateCompilation(source, options: TestOptions.DebugDll); | ||
comp.VerifyEmitDiagnostics(); | ||
comp = CreateCompilation(source, options: TestOptions.ReleaseDll); | ||
comp.VerifyEmitDiagnostics(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here as well. #Closed |
||
} | ||
|
||
[Fact, WorkItem(40251, "https://github.com/dotnet/roslyn/issues/40251")] | ||
public void AssignRefWithAwait() | ||
{ | ||
const string source = @" | ||
using System.Threading.Tasks; | ||
|
||
class IntCode | ||
{ | ||
public async Task Step(Task<int> t) | ||
{ | ||
ReadMemory() = await t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a test where we have a ReadMemory() += await t; |
||
} | ||
|
||
private ref long ReadMemory() => throw null; | ||
} | ||
"; | ||
var expected = new[] | ||
{ | ||
// (8,9): error CS8178: 'await' cannot be used in an expression containing a call to 'IntCode.ReadMemory()' because it returns by reference | ||
// ReadMemory() = await t; | ||
Diagnostic(ErrorCode.ERR_RefReturningCallAndAwait, "ReadMemory()").WithArguments("IntCode.ReadMemory()").WithLocation(8, 9) | ||
}; | ||
var comp = CreateCompilation(source, options: TestOptions.DebugDll); | ||
comp.VerifyEmitDiagnostics(expected); | ||
comp = CreateCompilation(source, options: TestOptions.ReleaseDll); | ||
comp.VerifyEmitDiagnostics(expected); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider running the scenario and observing expected behavior at runtime. #Closed