From 66a25bb6efcb496e27e20a377298d5932a562354 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 4 Jul 2017 20:07:15 +0200 Subject: [PATCH] [mtouch] Minor adjustments to get error messages right. --- src/ObjCRuntime/Registrar.cs | 8 ++++--- tests/mtouch/RegistrarTest.cs | 39 ++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/ObjCRuntime/Registrar.cs b/src/ObjCRuntime/Registrar.cs index f48eddfc4e..8c7f2c337a 100644 --- a/src/ObjCRuntime/Registrar.cs +++ b/src/ObjCRuntime/Registrar.cs @@ -2327,9 +2327,11 @@ namespace XamCore.Registrar { } else { signature.Append (ToSignature (type, member, ref success)); } - if (!success) - throw CreateException (4136, Method, "The registrar cannot marshal the parameter type '{0}' of the parameter '{1}' in the method '{2}.{3}'", - GetTypeFullName (type), GetParameterName (Method, i), GetTypeFullName (DeclaringType), GetDescriptiveMethodName (Method)); + if (!success) { + var mi = Method ?? method.Method; + throw CreateException (4136, mi, "The registrar cannot marshal the parameter type '{0}' of the parameter '{1}' in the method '{2}.{3}'", + GetTypeFullName (GetParameters (mi) [i]), GetParameterName (mi, i), GetTypeFullName (DeclaringType), GetDescriptiveMethodName (mi)); + } } } return signature.ToString (); diff --git a/tests/mtouch/RegistrarTest.cs b/tests/mtouch/RegistrarTest.cs index 3576c1e91b..3767652d7d 100644 --- a/tests/mtouch/RegistrarTest.cs +++ b/tests/mtouch/RegistrarTest.cs @@ -1071,15 +1071,25 @@ class Open : NSObject public void GenericType_WithInvalidParameterTypes () { var code = @" + using System.Collections.Generic; + using Foundation; class Open : NSObject where U: NSObject { [Export (""bar:"")] public void Bar (List arg) {} // Not OK, can't marshal lists. } + class C { static void Main () {} } "; - Verify (R.Static, code, false, - ".*Test.cs.*: error MT4136: The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1)'"); + using (var mtouch = new MTouchTool ()) { + mtouch.CreateTemporaryCacheDirectory (); + mtouch.CreateTemporaryApp (code: code, extraArg: "-debug:full"); + mtouch.Registrar = MTouchRegistrar.Static; + mtouch.Linker = MTouchLinker.DontLink; // faster test + mtouch.AssertExecuteFailure (MTouchAction.BuildSim, "build"); + mtouch.AssertError (4136, "The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1)'", "testApp.cs", 7); + mtouch.AssertErrorCount (1); + } } [Test] @@ -1192,6 +1202,7 @@ class GenericMethodClass : NSObject { public void GenericMethods2 () { var str1 = @" +using Foundation; class NullableGenericTestClass : NSObject where T: struct { [Export (""init:"")] @@ -1231,15 +1242,23 @@ class NullableGenericTestClass : NSObject where T: struct throw new System.NotImplementedException (); } } +class C { static void Main () {} } "; - Verify (R.Static, str1, false, - ".*Test.cs.*: error MT4113: The registrar found a generic method: 'NullableGenericTestClass`1.Z1(System.Nullable`1)'. Exporting generic methods is not supported, and will lead to random behavior and/or crashes", - ".*Test.cs.*: error MT4113: The registrar found a generic method: 'NullableGenericTestClass`1.Z2()'. Exporting generic methods is not supported, and will lead to random behavior and/or crashes", - ".*Test.cs.*: error MT4113: The registrar found a generic method: 'NullableGenericTestClass`1.Z3(Z)'. Exporting generic methods is not supported, and will lead to random behavior and/or crashes", - ".*Test.cs.*: error MT4128: The registrar found an invalid generic parameter type 'T' in the parameter foo of the method 'NullableGenericTestClass`1.T1(T)'. The generic parameter must have an 'NSObject' constraint.", - ".*Test.cs.*: error MT4128: The registrar found an invalid generic parameter type 'System.Nullable`1' in the parameter foo of the method 'NullableGenericTestClass`1.T2(System.Nullable`1)'. The generic parameter must have an 'NSObject' constraint.", - ".*Test.cs.*: error MT4129: The registrar found an invalid generic return type 'T' in the method 'NullableGenericTestClass`1.T3()'. The generic return type must have an 'NSObject' constraint.", - ".*Test.cs.*: error MT4136: The registrar cannot marshal the parameter type 'System.Nullable`1' of the parameter 'foo' in the method 'NullableGenericTestClass`1..ctor(System.Nullable`1)'"); + using (var mtouch = new MTouchTool ()) { + mtouch.CreateTemporaryCacheDirectory (); + mtouch.CreateTemporaryApp (code: str1, extraArg: "-debug:full"); + mtouch.Registrar = MTouchRegistrar.Static; + mtouch.Linker = MTouchLinker.DontLink; // faster test + mtouch.AssertExecuteFailure (MTouchAction.BuildSim, "build"); + mtouch.AssertError (4113, "The registrar found a generic method: 'NullableGenericTestClass`1.Z1(System.Nullable`1)'. Exporting generic methods is not supported, and will lead to random behavior and/or crashes", "testApp.cs", 12); + mtouch.AssertError (4113, "The registrar found a generic method: 'NullableGenericTestClass`1.Z2()'. Exporting generic methods is not supported, and will lead to random behavior and/or crashes", "testApp.cs", 17); + mtouch.AssertError (4113, "The registrar found a generic method: 'NullableGenericTestClass`1.Z3(Z)'. Exporting generic methods is not supported, and will lead to random behavior and/or crashes", "testApp.cs", 23); + mtouch.AssertError (4128, "The registrar found an invalid generic parameter type 'T' in the parameter foo of the method 'NullableGenericTestClass`1.T1(T)'. The generic parameter must have an 'NSObject' constraint.", "testApp.cs", 28); + mtouch.AssertError (4128, "The registrar found an invalid generic parameter type 'System.Nullable`1' in the parameter foo of the method 'NullableGenericTestClass`1.T2(System.Nullable`1)'. The generic parameter must have an 'NSObject' constraint.", "testApp.cs", 33); + mtouch.AssertError (4129, "The registrar found an invalid generic return type 'T' in the method 'NullableGenericTestClass`1.T3()'. The generic return type must have an 'NSObject' constraint.", "testApp.cs", 38); + mtouch.AssertError (4136, "The registrar cannot marshal the parameter type 'System.Nullable`1' of the parameter 'foo' in the method 'NullableGenericTestClass`1..ctor(System.Nullable`1)'", "testApp.cs", 6); + mtouch.AssertErrorCount (7); + } } [Test]