Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bgen] Avoid a NullReferenceException when reporting multiple attributes on a type. Fixes #10310. #10311

Merged
merged 1 commit into from Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/generator-attribute-manager.cs
Expand Up @@ -466,6 +466,8 @@ public static bool HasAttribute (ICustomAttributeProvider provider, string type_
if (provider is ParameterInfo) {
var pi = (ParameterInfo) provider;
name = $"the method {pi.Member.DeclaringType.FullName}.{pi.Member.Name}'s parameter #{pi.Position} ({pi.Name})";
} else if (provider is Type type) {
name = $"the type {type.FullName}";
} else if (provider is MemberInfo) {
var mi = (MemberInfo) provider;
name = $"the member {mi.DeclaringType.FullName}.{mi.Name}";
Expand Down
10 changes: 10 additions & 0 deletions tests/generator/ErrorTests.cs
Expand Up @@ -203,6 +203,16 @@ public void BI1050_protocol ()
bgen.AssertError (1050, "[BindAs] cannot be used inside Protocol or Model types. Type: MyFooClass");
}

[Test]
public void BI1059 ()
{
var bgen = new BGenTool ();
bgen.Profile = Profile.iOS;
bgen.CreateTemporaryBinding (File.ReadAllText (Path.Combine (Configuration.SourceRoot, "tests", "generator", "bi1059.cs")));
bgen.AssertExecuteError ("build");
bgen.AssertError (1059, "Found 2 Foundation.PreserveAttribute attributes on the member the type BI1059. At most one was expected.");
}

[Test]
public void BI1060 ()
{
Expand Down
6 changes: 6 additions & 0 deletions tests/generator/bi1059.cs
@@ -0,0 +1,6 @@
using Foundation;

[Protocol]
[Preserve (AllMembers = true)]
[Preserve (AllMembers = true)]
partial interface BI1059 {}