Skip to content
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

Operator False(C#) and IsFalse(VB) are not generated as IOperation #9309

Closed
genlu opened this issue Feb 29, 2016 · 2 comments
Closed

Operator False(C#) and IsFalse(VB) are not generated as IOperation #9309

genlu opened this issue Feb 29, 2016 · 2 comments

Comments

@genlu
Copy link
Member

genlu commented Feb 29, 2016

For example, x in the expression x && y inthe following C# code should be equivalent to x.IsFalse(), but it's not generate as an operation.

public struct S
{
    private int value;
    public S(int v)
    {
        value = v;
    }
    public static S operator &(S x, S y)
    {
        return new S(x.value + y.value);    
    }
    public static bool operator true(S x)
    {
        return x.value > 0;
    }
    public static bool operator false(S x)
    {
        return x.value <= 0;
    }
}

class C
{
    public void M()
    {
        var x = new S(-1);
        var y = new S(1);
        if (x && y) { }
    }
}

Here's VB code for this issue:

Module Module1
    Structure S8
        Public Shared Narrowing Operator CType(x As S8) As Boolean
            System.Console.WriteLine("Narrowing Operator CType(x As S8) As Boolean")
            Return Nothing
        End Operator

        Public Shared Operator IsTrue(x As S8) As Boolean
            System.Console.WriteLine("IsTrue(x As S8) As Boolean")
            Return False
        End Operator

        Public Shared Operator IsFalse(x As S8) As Boolean
            System.Console.WriteLine("IsFalse(x As S8) As Boolean")
            Return False
        End Operator

        Public Shared Operator And(x As S8, y As S8) As S8
            Return New S8()
        End Operator
    End Structure

    Sub Main()
        Dim x As New S8
        Dim y As New S8

        If x AndAlso y Then
        End If
    End Sub
End Module
@genlu genlu added this to the 1.3 milestone Feb 29, 2016
@ManishJayaswal ManishJayaswal modified the milestones: 1.3, 2.0 (RC) May 31, 2016
@ManishJayaswal ManishJayaswal modified the milestones: 2.0 (Preview 5), 2.1 Sep 13, 2016
@jinujoseph jinujoseph modified the milestone: 15.1 Mar 10, 2017
@jinujoseph jinujoseph added this to the 15.5 milestone Jul 4, 2017
@tmat tmat modified the milestones: 15.5, 15.later Sep 6, 2017
@jinujoseph jinujoseph modified the milestones: 15.later, Unknown Sep 29, 2017
@jinujoseph
Copy link
Contributor

dupe of userdefinedConditionallogicalbinaryoperator

@mavasani
Copy link
Contributor

Dupe of #19925

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants