Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs (C#)

Code before:
              IL_000e:  ldsfld     "System.Action Outer.A"
              IL_0013:  stloc.1
              IL_0014:  br.s       IL_0016
              IL_0016:  ldc.i4.1
              IL_0017:  brtrue.s   IL_001a
              IL_0019:  nop
              IL_001a:  ldloc.0
              IL_001b:  ldloc.1
              IL_001c:  stfld      "System.Action Outer.Inner"
              IL_0021:  ldarg.0
              IL_0022:  ldfld      "System.Action Outer.Inner"
              IL_0027:  call       "void System.Console.Write(object)"
              IL_002c:  nop
              IL_002d:  ret
            }
            """);
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/80326")]
        public void InterfaceOrNull()
        {
            var source = """
                #nullable enable
                using System;

                Console.WriteLine(M1(null));
                Console.WriteLine(M2(null));
                Console.WriteLine(M3(null));
                Console.WriteLine(M4(null));
                Console.WriteLine(M5(null));
                Console.WriteLine(M6(null));

                bool M1(A? a) => a is I or null;
                bool M2(A? a) => a is null or I;
                bool M3(A? a) => a is I || a is null;
                bool M4(A? a) => a is A or null;
                bool M5(A? a) => a is I or (null and null);
                bool M6(A? a) => a is (I or null) and var x;

                interface I;
                class A : I;
                """;
            CompileAndVerify(source, expectedOutput: """
                True
                True
                True
                True
                True
                True
                """).VerifyDiagnostics(
                // (11,18): warning CS8794: An expression of type 'A' always matches the provided pattern.

Review comment (suggestion):
>null [](http://example.com/codeflow?start=37&length=4)

Consider testing with not `null` input as well #Closed

Code after:
              IL_000e:  ldsfld     "System.Action Outer.A"
              IL_0013:  stloc.1
              IL_0014:  br.s       IL_0016
              IL_0016:  ldc.i4.1
              IL_0017:  brtrue.s   IL_001a
              IL_0019:  nop
              IL_001a:  ldloc.0
              IL_001b:  ldloc.1
              IL_001c:  stfld      "System.Action Outer.Inner"
              IL_0021:  ldarg.0
              IL_0022:  ldfld      "System.Action Outer.Inner"
              IL_0027:  call       "void System.Console.Write(object)"
              IL_002c:  nop
              IL_002d:  ret
            }
            """);
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/80326")]
        public void InterfaceOrNull()
        {
            var source = """
                #nullable enable
                using System;

                Console.WriteLine(M1(null));
                Console.WriteLine(M2(null));
                Console.WriteLine(M3(null));
                Console.WriteLine(M4(null));
                Console.WriteLine(M5(null));
                Console.WriteLine(M6(null));
                Console.WriteLine("---");
                var a = new A();
                Console.WriteLine(M1(a));
                Console.WriteLine(M2(a));
                Console.WriteLine(M3(a));
                Console.WriteLine(M4(a));
                Console.WriteLine(M5(a));
                Console.WriteLine(M6(a));

                bool M1(A? a) => a is I or null;
                bool M2(A? a) => a is null or I;
                bool M3(A? a) => a is I || a is null;
                bool M4(A? a) => a is A or null;
                bool M5(A? a) => a is I or (null and null);
                bool M6(A? a)
                {
                    if (a is (I or null) and var x)
                    {
                        x?.M();
                        return true;