Skip to content

Commit 037ae97

Browse files
[XSG] double cast on Add (#31367)
fixes 3 failing tests related to OnPlatform
1 parent 98128ef commit 037ae97

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

src/Controls/src/SourceGen/Visitors/SetPropertiesVisitor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,13 @@ static void Add(IndentedTextWriter writer, LocalVariable parentVar, XmlName prop
618618
if (receiverType is not null && !propertyType!.Equals(receiverType, SymbolEqualityComparer.Default))
619619
parentObj = $"(({receiverType.ToFQDisplayString()}){parentObj})";
620620

621+
//look for intermediate implicit casts
622+
string cast = string.Empty;
623+
if (HasDoubleImplicitConversion(context.Variables[valueNode].Type, itemType, context, out var conv))
624+
cast = "(" + conv!.ReturnType.ToFQDisplayString() + ")";
625+
621626
using (PrePost.NewLineInfo(writer, (IXmlLineInfo)valueNode, context.FilePath))
622-
writer.WriteLine($"{parentObj}.Add(({itemType.ToFQDisplayString()}){context.Variables[valueNode].Name});");
627+
writer.WriteLine($"{parentObj}.Add(({itemType.ToFQDisplayString()}){cast}{context.Variables[valueNode].Name});");
623628
}
624629

625630
static void AddToResourceDictionary(IndentedTextWriter writer, LocalVariable parentVar, IElementNode node, SourceGenContext context)

src/Controls/tests/Xaml.UnitTests/Issues/Maui24900.xaml.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ public void TearDown()
3737
}
3838

3939
[Test]
40-
#if FIXME_BEFORE_PUBLIC_RELEASE
41-
public void OnPlatformDoesNotThrow([Values(XamlInflator.XamlC, XamlInflator.Runtime)] XamlInflator inflator)
42-
#else
4340
public void OnPlatformDoesNotThrow([Values] XamlInflator inflator)
44-
#endif
4541
{
4642
mockDeviceInfo.Platform = DevicePlatform.WinUI;
4743
Assert.DoesNotThrow(() => new Maui24900(inflator));

src/Controls/tests/Xaml.UnitTests/Issues/Maui4509.xaml.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,15 @@ public void TearDown()
2121
}
2222

2323
[Test]
24-
#if FIXME_BEFORE_PUBLIC_RELEASE
25-
public void OnPlatformAsCollectionElementiOS([Values(XamlInflator.XamlC, XamlInflator.Runtime)] XamlInflator inflator)
26-
#else
2724
public void OnPlatformAsCollectionElementiOS([Values] XamlInflator inflator)
28-
#endif
2925
{
3026
DeviceInfo.SetCurrent(new MockDeviceInfo(platform: DevicePlatform.iOS));
3127
var page = new Maui4509(inflator);
3228
Assert.That(page.layout.Children.Count, Is.EqualTo(2));
3329
}
3430

3531
[Test]
36-
#if FIXME_BEFORE_PUBLIC_RELEASE
37-
public void OnPlatformAsCollectionElementAndroid([Values(XamlInflator.XamlC, XamlInflator.Runtime)] XamlInflator inflator)
38-
#else
3932
public void OnPlatformAsCollectionElementAndroid([Values] XamlInflator inflator)
40-
#endif
4133
{
4234
DeviceInfo.SetCurrent(new MockDeviceInfo(platform: DevicePlatform.Android));
4335
var page = new Maui4509(inflator);

0 commit comments

Comments
 (0)