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

Assignment of NewObjectExpression of value type to by ref parameter generates invalid code #246

Closed
adrianoc opened this issue Aug 5, 2023 · 0 comments
Labels
🐛 bug Something isn't working

Comments

@adrianoc
Copy link
Owner

adrianoc commented Aug 5, 2023

struct Bar
{
	public Bar(int i) {}
}

class Foo
{
	static void Main()
	{
		Bar b = new Bar(1); // Works
		M(ref b);
	}

	static void M(ref Bar b) => 
		b = new Bar(2); // Generates invalid code
}

generates something like:

//Parameters of 'static void M(ref Bar b) => ...'
il_M_11.Emit(OpCodes.Ldarg_0);
il_M_11.Emit(OpCodes.Ldc_I4, 2);
il_M_11.Emit(OpCodes.Newobj, ctor_Bar_1);
il_M_11.Emit(OpCodes.Stobj); // <-- missing the type `st_Bar_0`
il_M_11.Emit(OpCodes.Ret);
@adrianoc adrianoc added the 🐛 bug Something isn't working label Aug 5, 2023
adrianoc added a commit that referenced this issue Aug 12, 2023
also updates some incorrect expectations related to the same issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant