Skip to content

Commit b6cfbdf

Browse files
authored
Merge pull request #44475 from dotnet/merges/release/dev16.7-preview2-to-release/dev16.7-preview2-vs-deps
Merge release/dev16.7-preview2 to release/dev16.7-preview2-vs-deps
2 parents 205504d + 645c401 commit b6cfbdf

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

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

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

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

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

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

+36
Original file line numberDiff line numberDiff line change
@@ -5501,5 +5501,41 @@ 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+
}
55045540
}
55055541
}

0 commit comments

Comments
 (0)