[Generator] Ensure the correct error is raised when an Export is missing on a Property. (#4604)
The generator had a small bug in which we would get a NRE when a property missed a Export attribute and had no WrapAttr. The issue is due to the fact that an || is being used and does not shortcut when the attribute is missing. In that case, the first Get check would pass and a second attempt would happen with the set. In the case the set is missing, we would get a NRE. The correct way is to ensure that we do have the get and the set BEFORE the attr is checked. The added test shows an example of the issue.
This commit is contained in:
Родитель
f471f9b591
Коммит
41fe079f9b
|
@ -2300,7 +2300,12 @@ public partial class Generator : IMemberGatherer {
|
||||||
if (AttributeManager.HasAttribute<CoreImageFilterPropertyAttribute> (pi))
|
if (AttributeManager.HasAttribute<CoreImageFilterPropertyAttribute> (pi))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (AttributeManager.HasAttribute<WrapAttribute> (pi.GetGetMethod ()) || AttributeManager.HasAttribute<WrapAttribute> (pi.GetSetMethod ()))
|
// Ensure there's a [Wrap] on either (or both) the getter and setter - since we already know there's no [Export]
|
||||||
|
var getMethod = pi.GetGetMethod ();
|
||||||
|
var hasWrapGet = getMethod != null && AttributeManager.HasAttribute<WrapAttribute> (getMethod);
|
||||||
|
var setMethod = pi.GetSetMethod ();
|
||||||
|
var hasWrapSet = setMethod != null && AttributeManager.HasAttribute<WrapAttribute> (setMethod);
|
||||||
|
if (hasWrapGet || hasWrapSet)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
throw new BindingException (1018, true, "No [Export] attribute on property {0}.{1}", t.FullName, pi.Name);
|
throw new BindingException (1018, true, "No [Export] attribute on property {0}.{1}", t.FullName, pi.Name);
|
||||||
|
|
|
@ -679,5 +679,19 @@ namespace BI1063Tests {
|
||||||
bgen.AssertNoWarnings ();
|
bgen.AssertNoWarnings ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[TestCase (Profile.iOS)]
|
||||||
|
[TestCase (Profile.macOSFull)]
|
||||||
|
[TestCase (Profile.macOSMobile)]
|
||||||
|
public void MissingExportOnProperty (Profile profile)
|
||||||
|
{
|
||||||
|
var bgen = new BGenTool ();
|
||||||
|
bgen.Profile = profile;
|
||||||
|
bgen.Defines = BGenTool.GetDefaultDefines (profile);
|
||||||
|
bgen.CreateTemporaryBinding (File.ReadAllText (Path.Combine (Configuration.SourceRoot, "tests", "generator", "missing-export-property.cs")));
|
||||||
|
bgen.AssertExecuteError ("build");
|
||||||
|
bgen.AssertError (1018, "No [Export] attribute on property Test.NSTextInputClient.SelectedRange");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
using Foundation;
|
||||||
|
|
||||||
|
namespace Test
|
||||||
|
{
|
||||||
|
[BaseType (typeof (NSObject))]
|
||||||
|
[Protocol, Model]
|
||||||
|
public interface NSTextInputClient
|
||||||
|
{
|
||||||
|
// missing [Export ("selectRange")] should report an error
|
||||||
|
NSRange SelectedRange { get; }
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче