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 @@ -249,7 +249,7 @@ ConcurrentDictionary<string, Lazy<Regex>> regexCache
// [PatternString] requires the assigned value to be a compile-time
// constant so that we can evaluate it here.
Optional<object?> constant = valueOperation.ConstantValue;
if( !constant.HasValue ) {
if( !constant.HasValue || constant.Value is null ) {
context.ReportDiagnostic(
Diagnostic.Create(
descriptor: Diagnostics.PatternStringMustBeConstant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,19 @@ void SinglePatternTests() {
}

void NonConstantValuesAreFlagged() {

#region Non-constant values are flagged as needing to be constant
string variable = "123";

#region Non-constant values are flagged as needing to be constant
Digits _ = new( /* PatternStringMustBeConstant() */ variable /**/ );
Digits _ = /* PatternStringMustBeConstant() */ variable /**/;
_ = (Digits)/* PatternStringMustBeConstant() */ variable /**/;
#endregion

#region null is treated as non-constant
Digits _ = new( /* PatternStringMustBeConstant() */ null /**/ );
Digits _ = /* PatternStringMustBeConstant() */ null /**/;
_ = (Digits)/* PatternStringMustBeConstant() */ null /**/;
#endregion
}

void MultiplePatternTests() {
Expand Down
Loading