Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public IValueSet<bool> Related(BinaryOperatorKind relation, bool value)

IValueSet IValueSetFactory.Related(BinaryOperatorKind relation, ConstantValue value)
{
Debug.Assert(value.IsBoolean);
return Related(relation, value.BooleanValue);
return value.IsBad ? BoolValueSet.AllValues : Related(relation, value.BooleanValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value.IsBad [](start = 23, length = 11)

Are there other implementations of IValueSetFactory.Related() that need similar checks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the other ones have the check.

}

bool IValueSetFactory.Related(BinaryOperatorKind relation, ConstantValue left, ConstantValue right)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5501,5 +5501,41 @@ static void Main()
);
var compVerifier = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}

[Fact, WorkItem(44398, "https://github.com/dotnet/roslyn/issues/44398")]
public void MismatchedExpressionPattern()
{
var source =
@"class C
{
static void M(int a)
{
if (a is a is > 0 and < 500) { }
if (true is < 0) { }
if (true is 0) { }
}
}";
var compilation = CreateCompilation(source, parseOptions: TestOptions.RegularWithPatternCombinators);
compilation.VerifyDiagnostics(
// (5,18): error CS0150: A constant value is expected
// if (a is a is > 0 and < 500) { }
Diagnostic(ErrorCode.ERR_ConstantExpected, "a").WithLocation(5, 18),
// (5,25): error CS0029: Cannot implicitly convert type 'int' to 'bool'
// if (a is a is > 0 and < 500) { }
Diagnostic(ErrorCode.ERR_NoImplicitConv, "0").WithArguments("int", "bool").WithLocation(5, 25),
// (5,33): error CS0029: Cannot implicitly convert type 'int' to 'bool'
// if (a is a is > 0 and < 500) { }
Diagnostic(ErrorCode.ERR_NoImplicitConv, "500").WithArguments("int", "bool").WithLocation(5, 33),
// (6,21): error CS8781: Relational patterns may not be used for a value of type 'bool'.
// if (true is < 0) { }
Diagnostic(ErrorCode.ERR_UnsupportedTypeForRelationalPattern, "< 0").WithArguments("bool").WithLocation(6, 21),
// (6,23): error CS0029: Cannot implicitly convert type 'int' to 'bool'
// if (true is < 0) { }
Diagnostic(ErrorCode.ERR_NoImplicitConv, "0").WithArguments("int", "bool").WithLocation(6, 23),
// (7,21): error CS0029: Cannot implicitly convert type 'int' to 'bool'
// if (true is 0) { }
Diagnostic(ErrorCode.ERR_NoImplicitConv, "0").WithArguments("int", "bool").WithLocation(7, 21)
);
}
}
}