diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2017-02-02 15:19:03 +0100 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-03-24 13:18:41 +0900 |
commit | f001684556f104a7d847d7b276164e5f0246f06f (patch) | |
tree | 517119bf5a706214a057ba511b1c45becb4c93b4 | |
parent | fc482ef2eb128dae25342613a3e6d6d0f676419a (diff) | |
download | xamarin-forms-f001684556f104a7d847d7b276164e5f0246f06f.tar.gz xamarin-forms-f001684556f104a7d847d7b276164e5f0246f06f.tar.bz2 xamarin-forms-f001684556f104a7d847d7b276164e5f0246f06f.zip |
[Xaml[C]] check for compatible types on op_implicit (#715)
* [Xaml[C]] check for compatible types on op_implicit
* fix merge issue
5 files changed, 76 insertions, 6 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:sys="clr-namespace:System;assembly=mscorlib" + xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" + xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests" + x:Class="Xamarin.Forms.Xaml.UnitTests.Bz45891"> + <local:Bz45891.List> + <OnPlatform x:TypeArguments="scg:List(sys:String)"> + <OnPlatform.iOS> + <scg:List x:TypeArguments="sys:String"> + <x:String>Foo</x:String> + </scg:List> + </OnPlatform.iOS> + </OnPlatform> + </local:Bz45891.List> +</ContentPage>
\ 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<string>), typeof(Bz45891), default(IEnumerable<string>)); + + public IEnumerable<string> List { + get { return (IEnumerable<string>)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/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<string, string>), typeof(BindableObject), ExpectedResult = false)] [TestCase(typeof(List<string>), typeof(BindableObject), ExpectedResult = false)] + [TestCase(typeof(List<string>), typeof(IEnumerable<string>), ExpectedResult = true)] [TestCase(typeof(List<Button>), typeof(BindableObject), ExpectedResult = false)] [TestCase(typeof(Queue<KeyValuePair<string, string>>), typeof(BindableObject), ExpectedResult = false)] [TestCase(typeof(double), typeof(double), ExpectedResult = true)] diff --git a/Xamarin.Forms.Xaml/TypeConversionExtensions.cs b/Xamarin.Forms.Xaml/TypeConversionExtensions.cs index 15a66f5d..da8e7117 100644 --- a/Xamarin.Forms.Xaml/TypeConversionExtensions.cs +++ b/Xamarin.Forms.Xaml/TypeConversionExtensions.cs @@ -176,7 +176,7 @@ namespace Xamarin.Forms.Xaml if (!mi.IsSpecialName) continue; if (mi.Name != "op_Implicit") continue; if (!mi.IsPublic) continue; - if (mi.ReturnType != toType) continue; + if (!toType.IsAssignableFrom(mi.ReturnType)) continue; var parameters = mi.GetParameters(); if (parameters.Length != 1) continue; if (parameters[0].ParameterType != value.GetType()) continue; @@ -188,7 +188,7 @@ namespace Xamarin.Forms.Xaml if (!mi.IsSpecialName) continue; if (mi.Name != "op_Implicit") continue; if (!mi.IsPublic) continue; - if (mi.ReturnType != toType) continue; + if (!toType.IsAssignableFrom(mi.ReturnType)) continue; var parameters = mi.GetParameters(); if (parameters.Length != 1) continue; if (parameters[0].ParameterType != value.GetType()) continue; |