From 2b370fc402cb7c1769cfef34e2ac59645b31dbd7 Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Wed, 24 Oct 2018 21:05:35 +0200 Subject: [PATCH] [XamlC] fix the argument match check for events (#4134) Well, it looks like the order of arguments of InheritOrImplements was reversed... a totally fine and normal Friday so far - fixes #4130 --- .../SetPropertiesVisitor.cs | 3 +- .../Issues/Gh4130.xaml | 9 +++ .../Issues/Gh4130.xaml.cs | 64 +++++++++++++++++++ .../Xamarin.Forms.Xaml.UnitTests.csproj | 7 ++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Gh4130.xaml create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Gh4130.xaml.cs diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs index 2317a8e12..94b722590 100644 --- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs +++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs @@ -879,8 +879,9 @@ namespace Xamarin.Forms.Build.Tasks throw new XamlParseException($"Signature (number of arguments) of EventHandler \"{context.Body.Method.DeclaringType.FullName}.{value}\" doesn't match the event type", iXmlLineInfo); if (!invoke.ContainsGenericParameter) for (var i = 0; i < invoke.Parameters.Count;i++) - if (!handler.Parameters[i].ParameterType.InheritsFromOrImplements(invoke.Parameters[i].ParameterType)) + if (!invoke.Parameters[i].ParameterType.InheritsFromOrImplements(handler.Parameters[i].ParameterType)) throw new XamlParseException($"Signature (parameter {i}) of EventHandler \"{context.Body.Method.DeclaringType.FullName}.{value}\" doesn't match the event type", iXmlLineInfo); + //TODO check generic parameters if any if (handler.IsVirtual) { yield return Create(Ldarg_0); diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4130.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4130.xaml new file mode 100644 index 000000000..fb88133c5 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4130.xaml @@ -0,0 +1,9 @@ + + + + + + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4130.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4130.xaml.cs new file mode 100644 index 000000000..7c6958bec --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4130.xaml.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Gh4130Control:ContentView + { + public delegate void TextChangedEventHandler(object sender, TextChangedEventArgs args); +#pragma warning disable 067 + public event TextChangedEventHandler TextChanged; +#pragma warning restore 067 + public void FireEvent() + { + TextChanged?.Invoke(this, new TextChangedEventArgs(null, null)); + } + } + + public partial class Gh4130 : ContentPage + { + public Gh4130() + { + InitializeComponent(); + var c = new Gh4130Control(); + } + + public Gh4130(bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + void OnTextChanged(object sender, EventArgs e) + { + Assert.Pass(); + } + + [TestFixture] + class Tests + { + [SetUp] + public void Setup() + { + Device.PlatformServices = new MockPlatformServices(); + } + + [TearDown] + public void TearDown() + { + Device.PlatformServices = null; + } + + [TestCase(false),TestCase(true)] + public void NonGenericEventHanlders(bool useCompiledXaml) + { + var layout = new Gh4130(useCompiledXaml); + var control = layout.Content as Gh4130Control; + control.FireEvent(); + Assert.Fail(); + } + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj index 406404e0c..bac02bef6 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -655,6 +655,9 @@ Gh4099.xaml + + Gh4130.xaml + @@ -1207,6 +1210,10 @@ MSBuild:UpdateDesignTimeXaml Designer + + Designer + MSBuild:UpdateDesignTimeXaml +