Skip to content

Commit c9166ba

Browse files
authored
Revert "Make boolean value factory resilient in the face of errors. (#44441)"
This reverts commit 645c401.
1 parent 645c401 commit c9166ba

File tree

2 files changed

+2
-37
lines changed

2 files changed

+2
-37
lines changed

src/Compilers/CSharp/Portable/Utilities/ValueSetFactory.BoolValueSetFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public IValueSet<bool> Related(BinaryOperatorKind relation, bool value)
4949

5050
IValueSet IValueSetFactory.Related(BinaryOperatorKind relation, ConstantValue value)
5151
{
52-
return value.IsBad ? BoolValueSet.AllValues : Related(relation, value.BooleanValue);
52+
Debug.Assert(value.IsBoolean);
53+
return Related(relation, value.BooleanValue);
5354
}
5455

5556
bool IValueSetFactory.Related(BinaryOperatorKind relation, ConstantValue left, ConstantValue right)

src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests3.cs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,41 +5501,5 @@ static void Main()
55015501
);
55025502
var compVerifier = CompileAndVerify(compilation, expectedOutput: expectedOutput);
55035503
}
5504-
5505-
[Fact, WorkItem(44398, "https://github.com/dotnet/roslyn/issues/44398")]
5506-
public void MismatchedExpressionPattern()
5507-
{
5508-
var source =
5509-
@"class C
5510-
{
5511-
static void M(int a)
5512-
{
5513-
if (a is a is > 0 and < 500) { }
5514-
if (true is < 0) { }
5515-
if (true is 0) { }
5516-
}
5517-
}";
5518-
var compilation = CreateCompilation(source, parseOptions: TestOptions.RegularWithPatternCombinators);
5519-
compilation.VerifyDiagnostics(
5520-
// (5,18): error CS0150: A constant value is expected
5521-
// if (a is a is > 0 and < 500) { }
5522-
Diagnostic(ErrorCode.ERR_ConstantExpected, "a").WithLocation(5, 18),
5523-
// (5,25): error CS0029: Cannot implicitly convert type 'int' to 'bool'
5524-
// if (a is a is > 0 and < 500) { }
5525-
Diagnostic(ErrorCode.ERR_NoImplicitConv, "0").WithArguments("int", "bool").WithLocation(5, 25),
5526-
// (5,33): error CS0029: Cannot implicitly convert type 'int' to 'bool'
5527-
// if (a is a is > 0 and < 500) { }
5528-
Diagnostic(ErrorCode.ERR_NoImplicitConv, "500").WithArguments("int", "bool").WithLocation(5, 33),
5529-
// (6,21): error CS8781: Relational patterns may not be used for a value of type 'bool'.
5530-
// if (true is < 0) { }
5531-
Diagnostic(ErrorCode.ERR_UnsupportedTypeForRelationalPattern, "< 0").WithArguments("bool").WithLocation(6, 21),
5532-
// (6,23): error CS0029: Cannot implicitly convert type 'int' to 'bool'
5533-
// if (true is < 0) { }
5534-
Diagnostic(ErrorCode.ERR_NoImplicitConv, "0").WithArguments("int", "bool").WithLocation(6, 23),
5535-
// (7,21): error CS0029: Cannot implicitly convert type 'int' to 'bool'
5536-
// if (true is 0) { }
5537-
Diagnostic(ErrorCode.ERR_NoImplicitConv, "0").WithArguments("int", "bool").WithLocation(7, 21)
5538-
);
5539-
}
55405504
}
55415505
}

0 commit comments

Comments
 (0)