Skip to content

Roslyn doesn't produce warnings/errors for [Obsolete] implicit conversions in tuple equality (C# 7.3) #27047

@TessenR

Description

@TessenR

Version Used:

Microsoft Visual Studio Professional 2017 Preview (2)
Version 15.8.0 Preview 1.1
VisualStudio.15.Preview/15.8.0-pre.1.1+27705.2000
Microsoft .NET Framework
Version 4.7.03056

Steps to Reproduce:

Compile the following code:

public class C
{
    public void M((C, C) t) 
    {
      bool b1 = t == t;
      bool b2 = t != t;
    }

    [System.Obsolete("", error: true)]
    public static extern implicit operator bool(C c);
    public static extern C operator ==(C c1, C c2);
    public static extern C operator !=(C c1, C c2);
}

Expected Behavior:
error CS0619: 'C.implicit operator bool(C)' is obsolete: ''

Actual Behavior:
Code compiles without errors.

Notes

  1. The compiler does emit calls to the obsolete operator:
    IL_0016: call bool C::op_Implicit(class C)
  2. The compiler produces warnings/errors for obsolete implicit conversions in other scenarios, e.g. the line
    bool b3 = t.Item1 == t.Item2;
    won't be compiled in the example above as well as manually lowered version of the tuple comparison
    bool flag = (bool)(t.Item1 == t.Item1) && (bool)(t.Item2 == t.Item2);
  3. The compiler produces warnings/errors for other obsolete operators used in tuple equality e.g. components' == and != operators as well as true/false operators, i.e. the following code won't be compiled:
public class C
{
    public void M((C, C) t) 
    {
      bool b1 = t == t;
      bool b2 = t == t;
    }

    [System.Obsolete("", error: true)] public static extern C operator ==(C c1, C c2);
    [System.Obsolete("", error: true)] public static extern C operator !=(C c1, C c2);
    [System.Obsolete("", error: true)] public static extern bool operator true(C c);
    [System.Obsolete("", error: true)] public static extern bool operator false(C c);
}

with these errors:

    error CS0619: 'C.operator false(C)' is obsolete: ''
    error CS0619: 'C.operator ==(C, C)' is obsolete: ''
    error CS0619: 'C.operator false(C)' is obsolete: ''
    error CS0619: 'C.operator ==(C, C)' is obsolete: ''
    error CS0619: 'C.operator false(C)' is obsolete: ''
    error CS0619: 'C.operator ==(C, C)' is obsolete: ''
    error CS0619: 'C.operator false(C)' is obsolete: ''`

/cc @jcouv

Metadata

Metadata

Assignees

Labels

Area-CompilersResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions