[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
This commit is contained in:
Stephane Delcroix 2018-10-24 21:05:35 +02:00 коммит произвёл Shane Neuville
Родитель b379a9a11b
Коммит 2b370fc402
4 изменённых файлов: 82 добавлений и 1 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -0,0 +1,9 @@
<?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:local="using:Xamarin.Forms.Xaml.UnitTests"
x:Class="Xamarin.Forms.Xaml.UnitTests.Gh4130">
<ContentPage.Content>
<local:Gh4130Control TextChanged="OnTextChanged" />
</ContentPage.Content>
</ContentPage>

Просмотреть файл

@ -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();
}
}
}
}

Просмотреть файл

@ -655,6 +655,9 @@
<Compile Include="Issues\Gh4099.xaml.cs">
<DependentUpon>Gh4099.xaml</DependentUpon>
</Compile>
<Compile Include="Issues\Gh4130.xaml.cs">
<DependentUpon>Gh4130.xaml</DependentUpon>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
@ -1207,6 +1210,10 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Issues\Gh4130.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />