Skip to content

Give default literals a type in tuple comparisons#25327

Merged
jcouv merged 4 commits intodotnet:features/tuple-equalityfrom
jcouv:tuple-default
Mar 9, 2018
Merged

Give default literals a type in tuple comparisons#25327
jcouv merged 4 commits intodotnet:features/tuple-equalityfrom
jcouv:tuple-default

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Mar 7, 2018

Note:
Only the last two commits in this PR are new. The rest is the work to compute converted left/right in tuple equality (from PR #25297).

The second-to-last commit handles default being compared to a tuple (or nullable tuple).

Examples:

  • (0, 0) == default \\ true, same as default((int, int))
  • (null, 0) == (null, default) \\ true
  • (int, int)? nullableTuple; nullableTuple == default \\ same as default( (int, int)? )

The last commit blocks tuple binops in expression trees.

@jcouv jcouv added this to the 15.7 milestone Mar 7, 2018
@jcouv jcouv self-assigned this Mar 7, 2018
@jcouv jcouv requested a review from a team as a code owner March 7, 2018 22:21
@jcouv jcouv assigned gafter and jcouv and unassigned jcouv Mar 8, 2018
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binary operator [](start = 54, length = 15)

" == or != operator" ? For precision and consistency with other messages #Closed

Copy link
Contributor

@AlekseyTs AlekseyTs Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return expr; [](start = 20, length = 12)

Should we still convert if we have convertedType? #Closed

Copy link
Member Author

@jcouv jcouv Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll be fixed shortly in the PR related to semantic model and converted types. If there is a converted type for the tuple, we just apply that (and not do the element-wise conversions). #Resolved

Copy link
Contributor

@AlekseyTs AlekseyTs Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERR_AmbigBinaryOps [](start = 45, length = 18)

ERR_AmbigBinaryOps [](start = 45, length = 18)

It is not obvious why we consider the operator ambiguous in this case. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case here is really that we weren't able to give default a tuple type.
But I wanted to write the condition a bit more broadly, so that the code below can clearly move ahead with assumption that we either have a tuple literal (which may be typeless) or a typed expression (on both sides).

I could add a comment or use a new error code if that feels more appropriate.


In reply to: 173291602 [](ancestors = 173291602)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I wanted to write the condition a bit more broadly

Consider if you can add an assert with more narrow condition that would verify your assumption.


In reply to: 173310337 [](ancestors = 173310337,173291602)

Copy link
Contributor

@AlekseyTs AlekseyTs Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal [](start = 8, length = 8)

Do you expect this method to be used outside of the Binder type? #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it


In reply to: 173292507 [](ancestors = 173292507)

Copy link
Contributor

@AlekseyTs AlekseyTs Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default [](start = 49, length = 7)

Do we have a test against nullable non-tuple? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added below.

Note that there is a known bug with S? s; used in s == default, when S has operator ==(S, int). This is not specific to tuple equality. Filed #25318


In reply to: 173294618 [](ancestors = 173294618)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Mar 8, 2018

Done with review pass (iteration 6) #Closed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return [](start = 12, length = 6)

Nit: empty space missing before.

Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Contributor

@AlekseyTs AlekseyTs Mar 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestNestedDefaultWithNullableNonTupleType [](start = 20, length = 41)

Do we have a test where default is paired with null? #Closed

Copy link
Member Author

@jcouv jcouv Mar 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's covered in TestTypelessTupleAndTupleOfDefaults at line 1041.
System.Console.Write((null, () => 1) == (default, default)); #Resolved

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Mar 9, 2018

Iteration 7 looks good, but I assume some re-basing should happen after the other PR is merged. How do you plan to handle this? #Closed

@jcouv
Copy link
Member Author

jcouv commented Mar 9, 2018

Since not too many comments, my plan is to merge the earlier PR first then rebase this one on top. #Resolved

@jcouv
Copy link
Member Author

jcouv commented Mar 9, 2018

Rebased. I'll address the two remaining comments tonight. Thanks!

@jcouv
Copy link
Member Author

jcouv commented Mar 9, 2018

test windows_debug_unit32_prtest please

@jcouv
Copy link
Member Author

jcouv commented Mar 9, 2018

@AlekseyTs I've narrowed the check and added assert. Good to go?

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (iteration 4)

@jcouv jcouv merged commit 2f89389 into dotnet:features/tuple-equality Mar 9, 2018
@jcouv jcouv deleted the tuple-default branch March 9, 2018 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants