From 5d2598af695c41c32712cd136d02c0e8cdfcac5e Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Fri, 29 May 2020 15:43:29 -0400 Subject: [PATCH] [generator] Move optimization that skips required (warning) checks (#8712) We're getting out of `GenerateArgumentChecks` too fast when `null_allowed_override` is `true` so we miss the warning check for exposing a `[Model]` type instead of the protocol/interface. Sadly this uncovered a few mistakes in our existing bindings... ``` warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStartHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStopHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). CSC [watch] Xamarin.WatchOS.dll warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStartHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStopHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). warning BI1106: bgen: The parameter shadable in the method SceneKit.SCNBufferBindingHandler.Invoke exposes a model (SceneKit.SCNShadable). Please expose the corresponding protocol type instead (SceneKit.ISCNShadable). CSC [tvos] Xamarin.TVOS.dll STRIP Xamarin.WatchOS.dll CSC [watch] MonoTouch.NUnitLite.pdb warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStartHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStopHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). warning BI1106: bgen: The parameter shadable in the method SceneKit.SCNBufferBindingHandler.Invoke exposes a model (SceneKit.SCNShadable). Please expose the corresponding protocol type instead (SceneKit.ISCNShadable). warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStartHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStopHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). warning BI1106: bgen: The parameter shadable in the method SceneKit.SCNBufferBindingHandler.Invoke exposes a model (SceneKit.SCNShadable). Please expose the corresponding protocol type instead (SceneKit.ISCNShadable). CSC [mac/mobile-64] Xamarin.Mac.dll CSC [mac/full-64] Xamarin.Mac.dll warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStartHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). warning BI1106: bgen: The parameter receiver in the method SceneKit.SCNAnimationDidStopHandler.Invoke exposes a model (SceneKit.SCNAnimatable). Please expose the corresponding protocol type instead (SceneKit.ISCNAnimatable). warning BI1106: bgen: The parameter shadable in the method SceneKit.SCNBufferBindingHandler.Invoke exposes a model (SceneKit.SCNShadable). Please expose the corresponding protocol type instead (SceneKit.ISCNShadable). ``` Those are fixed in a separate PR https://github.com/xamarin/xamarin-macios/pull/8716 --- src/generator.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/generator.cs b/src/generator.cs index 271324e1a9..4280b82a68 100644 --- a/src/generator.cs +++ b/src/generator.cs @@ -4160,23 +4160,27 @@ public partial class Generator : IMemberGatherer { void GenerateArgumentChecks (MethodInfo mi, bool null_allowed_override, PropertyInfo propInfo = null) { - if (null_allowed_override) - return; - if (AttributeManager.HasAttribute (mi)) ErrorHelper.Show (new BindingException (1118, false, mi)); foreach (var pi in mi.GetParameters ()) { + if (!BindThirdPartyLibrary) { + if (!mi.IsSpecialName && IsModel (pi.ParameterType) && !Protocolize (pi)) { + // don't warn on obsoleted API, there's likely a new version that fix this + // any no good reason for using the obsolete API anyway + if (!AttributeManager.HasAttribute (mi) && !AttributeManager.HasAttribute (mi.DeclaringType)) + ErrorHelper.Warning (1106, + mi.DeclaringType, mi.Name, pi.Name, pi.ParameterType, pi.ParameterType.Namespace, pi.ParameterType.Name); + } + } + + if (null_allowed_override) + continue; + var needs_null_check = ParameterNeedsNullCheck (pi, mi, propInfo); if (!needs_null_check) continue; - if (!BindThirdPartyLibrary) { - if (!mi.IsSpecialName && IsModel (pi.ParameterType) && !Protocolize (pi)) - ErrorHelper.Warning (1106, - mi.DeclaringType, mi.Name, pi.Name, pi.ParameterType, pi.ParameterType.Namespace, pi.ParameterType.Name); - } - var safe_name = pi.Name.GetSafeParamName (); if (Protocolize (pi)) {