From eacbc1acf4cc2b95b98099d069e7bfa31c89f4f8 Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Thu, 2 Feb 2017 15:19:03 +0100 Subject: [Xaml[C]] check for compatible types on op_implicit (#715) * [Xaml[C]] check for compatible types on op_implicit * fix merge issue --- .../TypeReferenceExtensions.cs | 6 +-- Xamarin.Forms.Xaml.UnitTests/Issues/Bz45891.xaml | 17 +++++++ .../Issues/Bz45891.xaml.cs | 54 ++++++++++++++++++++++ .../Xamarin.Forms.Xaml.UnitTests.csproj | 6 +++ .../XamlC/TypeReferenceExtensionsTests.cs | 1 + Xamarin.Forms.Xaml/TypeConversionExtensions.cs | 4 +- 6 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Bz45891.xaml create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Bz45891.xaml.cs diff --git a/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs b/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs index 3b69bfd5..f862de3e 100644 --- a/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs +++ b/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs @@ -157,7 +157,7 @@ namespace Xamarin.Forms.Build.Tasks var typeDef = typeRef.Resolve(); if (TypeRefComparer.Default.Equals(typeDef, baseClass.Resolve())) return true; - if (typeDef.Interfaces.Any(ir => TypeRefComparer.Default.Equals(ir.InterfaceType, baseClass))) + if (typeDef.Interfaces.Any(ir => TypeRefComparer.Default.Equals(ir.InterfaceType.ResolveGenericParameters(typeRef), baseClass))) return true; if (typeDef.BaseType == null) return false; @@ -257,10 +257,8 @@ namespace Xamarin.Forms.Build.Tasks var returnType = castDef.ReturnType; if (returnType.IsGenericParameter) returnType = ((GenericInstanceType)opDeclTypeRef).GenericArguments [((GenericParameter)returnType).Position]; - if (returnType.FullName == toType.FullName && - cast.Parameters [0].ParameterType.Name == fromType.Name) { + if (returnType.InheritsFromOrImplements(toType)) return castDef; - } } } return null; diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz45891.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz45891.xaml new file mode 100644 index 00000000..7a1adf67 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz45891.xaml @@ -0,0 +1,17 @@ + + + + + + + Foo + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz45891.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz45891.xaml.cs new file mode 100644 index 00000000..4284dde7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz45891.xaml.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz45891 : ContentPage + { + public Bz45891() + { + InitializeComponent(); + } + + public Bz45891(bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + public static readonly BindableProperty ListProperty = + BindableProperty.Create("List", typeof(IEnumerable), typeof(Bz45891), default(IEnumerable)); + + public IEnumerable List { + get { return (IEnumerable)GetValue(ListProperty); } + set { SetValue(ListProperty, value); } + } + + [TestFixture] + class Tests + { + [SetUp] + public void Setup() + { + Device.PlatformServices = new MockPlatformServices(); + } + + [TearDown] + public void TearDown() + { + Device.PlatformServices = null; + } + + [TestCase(true)] + [TestCase(false)] + public void LookForInheritanceOnOpImplicit(bool useCompiledXaml) + { + var p = new Bz45891(useCompiledXaml); + Assert.AreEqual("Foo", p.List.First()); + } + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj index 47b941b0..efbd9aab 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -436,6 +436,9 @@ Bz43694.xaml + + Bz45891.xaml + @@ -793,6 +796,9 @@ MSBuild:UpdateDesignTimeXaml + + MSBuild:UpdateDesignTimeXaml + diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlC/TypeReferenceExtensionsTests.cs b/Xamarin.Forms.Xaml.UnitTests/XamlC/TypeReferenceExtensionsTests.cs index 9aa03b9e..1064166f 100644 --- a/Xamarin.Forms.Xaml.UnitTests/XamlC/TypeReferenceExtensionsTests.cs +++ b/Xamarin.Forms.Xaml.UnitTests/XamlC/TypeReferenceExtensionsTests.cs @@ -48,6 +48,7 @@ namespace Xamarin.Forms.Xaml.XamlcUnitTests [TestCase(typeof(bool), typeof(BindableObject), ExpectedResult = false)] [TestCase(typeof(Dictionary), typeof(BindableObject), ExpectedResult = false)] [TestCase(typeof(List), typeof(BindableObject), ExpectedResult = false)] + [TestCase(typeof(List), typeof(IEnumerable), ExpectedResult = true)] [TestCase(typeof(List