Skip to content
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

crash on assigning result of a switch expression to a constant #75353

Closed
thalber opened this issue Sep 28, 2024 · 2 comments · Fixed by #75371
Closed

crash on assigning result of a switch expression to a constant #75353

thalber opened this issue Sep 28, 2024 · 2 comments · Fixed by #75371
Assignees
Milestone

Comments

@thalber
Copy link

thalber commented Sep 28, 2024

Environment data

dotnet --info output: info.txt

VS Code version: 1.93.1
C# Extension version: 2.45.25, 2.39.29, presumably others

OmniSharp log

4-C#.log

Steps to reproduce

  1. Open any .cs file in the editor that contains following code:
const float //this is where i forgot to write the rest of the line lol
angVel = (firstChunk.vel.magnitude, angVel, firstChunk.ContactPoint.x, firstChunk.contactPoint.y) switch
{
	( <= 1f, _, _, _) => 0f,
	( >= 1f, 0f, not 0, 0) => Random.Range(5, 10f) * Mathf.Sign(firstChunk.vel.x),
	( >= 1f, _, not 0, -1) => 1f,
	_ => angVel,
};
rot = Mathf.LerpAngle(rot, rot + angVel, 1f);

Expected behavior

A compiler error is displayed for assigning a non-static expression to a const value.

Actual behavior

microsoft.codeanalysis.languageserver.exe crashes with a stack overflow
image

This causes the LSP to implode. the compiler exhibits similar behavior
image

Additional context

Bug is seemingly context-independent as it occurs even if i paste the snippet into a completely blank project. Doesn't show up for shorter switches.

@thalber
Copy link
Author

thalber commented Oct 1, 2024

i just had an Idea and narrowed it down to this

const float angVel = angVel switch
{
	_ => 0f,
};

@dibarbet
Copy link
Member

dibarbet commented Oct 2, 2024

Can repro, and can repro on the CLI, so likely a compiler bug. Transferring over to Roslyn

@dibarbet dibarbet transferred this issue from dotnet/vscode-csharp Oct 2, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 2, 2024
@jjonescz jjonescz self-assigned this Oct 3, 2024
@jcouv jcouv assigned jcouv and jjonescz and unassigned jjonescz and jcouv Oct 3, 2024
@jcouv jcouv self-assigned this Oct 3, 2024
@jcouv jcouv added this to the 17.13 milestone Oct 3, 2024
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Oct 3, 2024
@jaredpar jaredpar added the Bug label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants