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

Initializer (InitializerExpressionSyntax) is ignored for value types #243

Closed
adrianoc opened this issue Jul 18, 2023 · 2 comments
Closed
Labels
🐛 bug Something isn't working

Comments

@adrianoc
Copy link
Owner

No code is generated for the object initializer ( { Name = "A", Value = 42 })

using System;

var x = new Bar { Name = "A", Value = 42 } );

struct Bar
{
      public string Name {get; set;}
      public int Value {get; set;}
}
@adrianoc adrianoc added the 🐛 bug Something isn't working label Jul 18, 2023
adrianoc added a commit that referenced this issue Aug 6, 2023
adrianoc added a commit that referenced this issue Aug 6, 2023
…ss value type instantiation (#243)

this uncovered a bunch of scenarios in which simple instantition of parameterless value type is not working. These will be fixed in a future commit and
handling of ObjectInitializerExpression for those in a follow up one
adrianoc added a commit that referenced this issue Aug 6, 2023
…n in tests accordingly

this issue was discovered while working on #243
@adrianoc
Copy link
Owner Author

adrianoc commented Aug 6, 2023

add extra tests to cover the following scenarios:

struct S
{
	public int Value { get; set; }
	public static bool operator>(in S l, in S r) => false;
	public static bool operator<(in S l, in S r) => false;
}

class Foo
{
	S TernaryOperators(int i) =>  i == 2 ? new S { Value = i } : new S { Value = i };

	S GetArrow() => new S { Value = 42 };
	S GetReturn() { return new S { Value = 42 }; }

	int X(int[] a) => a[ new S { Value = 1 } .Value ];
	
	bool P(int i) => new S { Value = 2} < new S { Value = 3 };
}

@adrianoc
Copy link
Owner Author

adrianoc commented Aug 9, 2023

Ternary operator handling may be affected by #248

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