From 54acfa91222787ae9170f94ddf8ee94192d1a1a5 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Thu, 20 Jun 2019 18:37:42 +0900 Subject: [PATCH] [XamlC] Do not try to set a value to bound source property if unavailable (#6564) --- Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs | 19 ++++++++++++++++++- Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml | 1 + Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml.cs | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs index 3c49d2f..d63cf8d 100644 --- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs +++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs @@ -665,7 +665,13 @@ namespace Xamarin.Forms.Build.Tasks else il.Emit(Ldarg_0); var locs = new Dictionary(); - il.Append(DigProperties(properties.Take(properties.Count - 1), locs, null, node as IXmlLineInfo, module)); + Instruction pop = null; + il.Append(DigProperties(properties.Take(properties.Count - 1), locs, () => { + if (pop == null) + pop = Instruction.Create(Pop); + + return pop; + }, node as IXmlLineInfo, module)); foreach (var loc in locs.Values) setter.Body.Variables.Add(loc); @@ -681,6 +687,12 @@ namespace Xamarin.Forms.Build.Tasks il.Emit(Stloc, loc); il.Emit(Ldloca, loc); + } else { + if (pop == null) + pop = Instruction.Create(Pop); + + il.Emit(Dup); + il.Emit(Brfalse, pop); } if (lastIndexArg != null) { @@ -703,6 +715,11 @@ namespace Xamarin.Forms.Build.Tasks il.Emit(Ret); + if (pop != null) { + il.Append(pop); + il.Emit(Ret); + } + context.Body.Method.DeclaringType.Methods.Add(setter); // IL_0024: ldnull diff --git a/Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml b/Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml index 3794705..6b5796e 100644 --- a/Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml +++ b/Xamarin.Forms.Xaml.UnitTests/BindingsCompiler.xaml @@ -16,6 +16,7 @@