From e45bce1a64bd30c462abf51ab3b4eec69d5346aa Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Mon, 12 Dec 2016 21:03:30 +0100 Subject: [XamlC] Box valueTypes on Add() (#624) This doesn't happen often, and I haven't found any valid XAML file out there requiring this, but in the case of 49307, it at least generates valid IL, which then fails with a NRE as this is the nature of callvirt. --- Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs | 2 + Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml | 7 ++++ .../Issues/Bz49307.xaml.cs | 47 ++++++++++++++++++++++ .../Xamarin.Forms.Xaml.UnitTests.csproj | 6 +++ .../Xamarin.Forms.Xaml.Xamlc.csproj | 2 +- 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml.cs diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs index 67c345ff..6a7a3bef 100644 --- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs +++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs @@ -1034,6 +1034,8 @@ namespace Xamarin.Forms.Build.Tasks yield return Instruction.Create(OpCodes.Ldloc, vardef); if (implicitOperator != null) yield return Instruction.Create(OpCodes.Call, module.Import(implicitOperator)); + if (implicitOperator == null && vardef.VariableType.IsValueType && !childType.IsValueType) + yield return Instruction.Create(OpCodes.Box, vardef.VariableType); yield return Instruction.Create(OpCodes.Callvirt, adderRef); if (adderRef.ReturnType.FullName != "System.Void") yield return Instruction.Create(OpCodes.Pop); diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml new file mode 100644 index 00000000..3bb6e203 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml @@ -0,0 +1,7 @@ + + + + + #c2d1d3 + + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml.cs new file mode 100644 index 00000000..166706af --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz49307 : Application + { + public Bz49307() + { + InitializeComponent(); + } + + public Bz49307(bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [SetUp] + public void Setup() + { + Device.PlatformServices = new MockPlatformServices(); + } + + [TearDown] + public void TearDown() + { + Device.PlatformServices = null; + } + + [TestCase(true)] + [TestCase(false)] + public void ThrowOnMissingDictionary(bool useCompiledXaml) + { + if (useCompiledXaml) + Assert.Throws(() => new Bz49307(useCompiledXaml)); + else + Assert.Throws(new XamlParseExceptionConstraint(5, 4), () => new Bz49307(useCompiledXaml)); + } + } + } +} \ 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 2234c7f9..4f14fd36 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -403,6 +403,9 @@ I8.xaml + + Bz49307.xaml + @@ -727,6 +730,9 @@ MSBuild:UpdateDesignTimeXaml + + MSBuild:UpdateDesignTimeXaml + diff --git a/Xamarin.Forms.Xaml.Xamlc/Xamarin.Forms.Xaml.Xamlc.csproj b/Xamarin.Forms.Xaml.Xamlc/Xamarin.Forms.Xaml.Xamlc.csproj index 1ac2b944..4380fd30 100644 --- a/Xamarin.Forms.Xaml.Xamlc/Xamarin.Forms.Xaml.Xamlc.csproj +++ b/Xamarin.Forms.Xaml.Xamlc/Xamarin.Forms.Xaml.Xamlc.csproj @@ -17,7 +17,7 @@ prompt 4 true - -r "../../../Xamarin.Forms.Controls/bin/Debug/" -p "../../../Xamarin.Forms.Xaml.UnitTest/bin/Debug/;/Library/Frameworks/Mono.framework/Versions/3.12.1/lib/mono/4.5;/Library/Frameworks/Mono.framework/Versions/3.12.1/lib/mono/4.5/Facades/" --keep -v 4 -d ../../../Xamarin.Forms.Xaml.UnitTests/bin/Debug/Xamarin.Forms.Xaml.UnitTests.dll + -r "../../../Xamarin.Forms.Controls/bin/Debug/" -p "../../../Xamarin.Forms.Xaml.UnitTest/bin/Debug/;/Library/Frameworks/Mono.framework/Versions/3.12.1/lib/mono/4.5;/Library/Frameworks/Mono.framework/Versions/3.12.1/lib/mono/4.5/Facades/" --keep -v 4 ../../../Xamarin.Forms.Xaml.UnitTests/bin/Debug/Xamarin.Forms.Xaml.UnitTests.dll xamlc true -- cgit v1.2.3