Skip to content

x == default is valid object equality for reference types#38853

Merged
jcouv merged 2 commits intodotnet:masterfrom
jcouv:default-comparison
Sep 25, 2019
Merged

x == default is valid object equality for reference types#38853
jcouv merged 2 commits intodotnet:masterfrom
jcouv:default-comparison

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Sep 25, 2019

Since we've received significant feedback on part of the compat break we took in 16.4p1, we're making a refinement to reduce the negative impact.
t == default for unconstrained types will remain an error (introduced in 16.4p1), but x == default will be re-allowed for reference types (could bind as object equality).

Fixes #38643
Relates to #37596 (16.4p1 breaking changes)

@jcouv jcouv added this to the 16.4.P2 milestone Sep 25, 2019
@jcouv jcouv self-assigned this Sep 25, 2019
@jcouv jcouv force-pushed the default-comparison branch from b1a0aa8 to 87cf923 Compare September 25, 2019 18:17
@jcouv jcouv force-pushed the default-comparison branch from 87cf923 to f765887 Compare September 25, 2019 20:19
@jcouv jcouv marked this pull request as ready for review September 25, 2019 20:25
@jcouv jcouv requested a review from a team as a code owner September 25, 2019 20:25
Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM

// SPEC: operand to the type of the other operand. Or:
// SPEC: (2) One operand is a value of type T where T is a type-parameter and the other operand is
// SPEC: the literal null. Furthermore T does not have the value type constraint.
// SPEC: (3) One operand is the literal default and the other operand is a reference-type.
Copy link
Member

Choose a reason for hiding this comment

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

Did the spec actually change?

Copy link
Member Author

Choose a reason for hiding this comment

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

It hasn't yet, but I want to record the proposed spec change. I don't know a better way to keep the code and comment in sync...

return false;
}

// If at least one side is null or default then clearly a conversion exists.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 25, 2019

Choose a reason for hiding this comment

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

// If at least one side is null or default then clearly a conversion exists. [](start = 12, length = 76)

Is there a benefit in allowing null == default? Is it always true? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Thanks
I'll keep as disallowed as it doesn't seem useful.


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

";

var comp = CreateCompilation(source, parseOptions: TestOptions.Regular7_1);
comp.VerifyDiagnostics();
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 25, 2019

Choose a reason for hiding this comment

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

comp.VerifyDiagnostics(); [](start = 12, length = 25)

For success cases, I think we would want to run the code and observe that they behaves per spec. #Resolved

// || default != x;
Diagnostic(ErrorCode.ERR_BadBinaryOps, "default != x").WithArguments("!=", "default", "C").WithLocation(9, 16)
);
comp.VerifyDiagnostics();
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 25, 2019

Choose a reason for hiding this comment

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

comp.VerifyDiagnostics(); [](start = 12, length = 25)

For success cases, I think we would want to run the code and observe that they behaves per spec. #Resolved

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 1), modulo suggested tests strengthening and pending successful CI result.

@jcouv jcouv merged commit 6082529 into dotnet:master Sep 25, 2019
@jcouv jcouv deleted the default-comparison branch September 25, 2019 23:28
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.4.0 Compiler Toolset does not allow comparing to "default"

4 participants