Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da690cf

Browse files
authored
Any have metadata value when empty Fixes #5113 (#8603)
Previously, when we saw the Item was empty, we'd jump out early. Fortunately, we already special-cased Count, and it turns out we can do the same with AnyHaveMetadataValue. Fixes #5113.
1 parent ea90db2 commit da690cf

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

documentation/wiki/ChangeWaves.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t
2828
- [Eliminate project string cache](https://github.com/dotnet/msbuild/pull/7965)
2929
- [Log an error when no provided search path for an import exists](https://github.com/dotnet/msbuild/pull/8095)
3030
- [Log assembly loads](https://github.com/dotnet/msbuild/pull/8316)
31+
- [AnyHaveMetadataValue returns false when passed an empty list](https://github.com/dotnet/msbuild/pull/8603)
3132

3233
### 17.4
3334
- [Respect deps.json when loading assemblies](https://github.com/dotnet/msbuild/pull/7520)

src/Build.UnitTests/Evaluation/Expander_Tests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ public void ExpandItemVectorFunctionsAnyHaveMetadataValue()
222222
Assert.Equal("false", itemsFalse[0].EvaluatedInclude);
223223
}
224224

225+
[Fact]
226+
public void ExpandEmptyItemVectorFunctionWithAnyHaveMetadataValue()
227+
{
228+
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
229+
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = CreateItemFunctionExpander();
230+
ProjectItemInstanceFactory itemFactory = new ProjectItemInstanceFactory(project, "i");
231+
232+
IList<ProjectItemInstance> itemsEmpty = expander.ExpandIntoItemsLeaveEscaped("@(unsetItem->AnyHaveMetadataValue('Metadatum', 'value'))", itemFactory, ExpanderOptions.ExpandItems, MockElementLocation.Instance);
233+
ProjectItemInstance pii = itemsEmpty.ShouldHaveSingleItem<ProjectItemInstance>();
234+
pii.EvaluatedInclude.ShouldBe("false");
235+
}
236+
225237
/// <summary>
226238
/// Expand an item vector function Metadata()->DirectoryName()->Distinct()
227239
/// </summary>

src/Build/Evaluation/Expander.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,11 +1946,16 @@ internal static bool ExpandExpressionCapture<S>(
19461946
// If there are no items of the given type, then bail out early
19471947
if (itemsOfType.Count == 0)
19481948
{
1949-
// .. but only if there isn't a function "Count()", since that will want to return something (zero) for an empty list
1949+
// ... but only if there isn't a function "Count", since that will want to return something (zero) for an empty list
19501950
if (expressionCapture.Captures?.Any(capture => string.Equals(capture.FunctionName, "Count", StringComparison.OrdinalIgnoreCase)) != true)
19511951
{
1952-
itemsFromCapture = new List<Pair<string, S>>();
1953-
return false;
1952+
// ...or a function "AnyHaveMetadataValue", since that will want to return false for an empty list.
1953+
if (!ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_6) ||
1954+
expressionCapture.Captures?.Any(capture => string.Equals(capture.FunctionName, "AnyHaveMetadataValue", StringComparison.OrdinalIgnoreCase)) != true)
1955+
{
1956+
itemsFromCapture = new List<Pair<string, S>>();
1957+
return false;
1958+
}
19541959
}
19551960
}
19561961

0 commit comments

Comments
 (0)