-
Notifications
You must be signed in to change notification settings - Fork 4k
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
CR feedback on fixing constructor lookup when tuple created via "new" #10875
Conversation
@dotnet/roslyn-compiler - please review |
{ | ||
static void Main() | ||
{ | ||
var x = new (int a, int b)(1, 2); |
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.
Would it also be useful to test constructor initializer? var x = new (int a, int b)(1, 2) { a = 3; b = 4 };
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.
why not? :-)
Thanks
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.
Turns out we did not support constructor initializers for tuples at all.
Added positive/negative tests
LGTM |
|
||
var comp = CreateCompilationWithMscorlib(source, parseOptions: TestOptions.Regular.WithTuplesFeature()); | ||
comp.VerifyDiagnostics( | ||
// (6,22): error CS1729: 'ValueTuple<int, int>' does not contain a constructor that takes 3 arguments |
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.
Should we be using tuple notation for the type in the error message?
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.
Possibly.
Technically ctor belongs to the underlying type, so the error is correct - it tells exactly what type is missing a constructor.
I can see, however, how a custom error "this tuple cannot be constructed with N elements" could be more helpful.
Captured in #10874
@dotnet-bot test prtest/win/dbg/unit32 please |
@dotnet-bot test prtest/win/dbg/unit32 please |
Recognizing this is a temporary solution that prevents a crash and this area is being reworked, LGTM. I suspect we may want to change the expected behavior of these tests after LDM review. |
CR feedback on fixing constructoir lookup when tuple created via "new"
see also
#10874
#10891