Skip to content

Bug: Generic Default Value Literal with == operator #36492

@avin-kavish

Description

@avin-kavish

Version Used: 7.3

Steps to Reproduce:

  1. Attempt to compile the following
public void Foo<T>(T value){

    if (value == default)
}

Expected Behavior: Compile error similar to value == default(T)

public void Foo<T>(T value){

    if (value == default(T)) // <--- compile error as expected
}

Actual Behavior: compiles into a null check for all types including value types and leads to situations where when T is int and value=0, value == default evaluates to false.

Metadata

Metadata

Assignees

Labels

4 - In ReviewA fix for the issue is submitted for review.Area-CompilersBugResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions