summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-12 20:03:30 (GMT)
committerGitHub <noreply@github.com>2016-12-12 20:03:30 (GMT)
commite45bce1a64bd30c462abf51ab3b4eec69d5346aa (patch)
tree1f0169edfc221b241f92d1588221fd9fcaa009ad
parent8257753d1b48de0e81d5bd431604f60d2065b6cc (diff)
downloadxamarin-forms-e45bce1a64bd30c462abf51ab3b4eec69d5346aa.zip
xamarin-forms-e45bce1a64bd30c462abf51ab3b4eec69d5346aa.tar.gz
xamarin-forms-e45bce1a64bd30c462abf51ab3b4eec69d5346aa.tar.bz2
[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.
-rw-r--r--Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs2
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml7
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml.cs47
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj6
-rw-r--r--Xamarin.Forms.Xaml.Xamlc/Xamarin.Forms.Xaml.Xamlc.csproj2
5 files changed, 63 insertions, 1 deletions
diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
index 67c345f..6a7a3be 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 0000000..3bb6e20
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz49307.xaml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Xamarin.Forms.Xaml.UnitTests.Bz49307">
+ <Application.Resources>
+ <!-- Application resource dictionary -->
+ <Color x:Key="MyColor">#c2d1d3</Color>
+ </Application.Resources>
+</Application>
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 0000000..166706a
--- /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<NullReferenceException>(() => 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 2234c7f..4f14fd3 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 @@
<Compile Include="I8.xaml.cs">
<DependentUpon>I8.xaml</DependentUpon>
</Compile>
+ <Compile Include="Issues\Bz49307.xaml.cs">
+ <DependentUpon>Bz49307.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -727,6 +730,9 @@
<EmbeddedResource Include="I8.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="Issues\Bz49307.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
diff --git a/Xamarin.Forms.Xaml.Xamlc/Xamarin.Forms.Xaml.Xamlc.csproj b/Xamarin.Forms.Xaml.Xamlc/Xamarin.Forms.Xaml.Xamlc.csproj
index 1ac2b94..4380fd3 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 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
- <Commandlineparameters>-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</Commandlineparameters>
+ <Commandlineparameters>-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</Commandlineparameters>
<AssemblyName>xamlc</AssemblyName>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>