[Mono-bugs] [Bug 70808][Wis] New - mcs issues CS0121 and CS8006 for a supposedly ambiguous function call (but it works in csc)

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 25 Dec 2004 23:57:19 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by adamm@san.rr.com.

http://bugzilla.ximian.com/show_bug.cgi?id=70808

--- shadow/70808	2004-12-25 23:57:19.000000000 -0500
+++ shadow/70808.tmp.9379	2004-12-25 23:57:19.000000000 -0500
@@ -0,0 +1,71 @@
+Bug#: 70808
+Product: Mono: Compilers
+Version: unspecified
+OS: All
+OS Details: tested on mono 1.05 for GNU/Linux and Windows
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: adamm@san.rr.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: mcs issues CS0121 and CS8006 for a supposedly ambiguous function call (but it works in csc)
+
+Description of Problem:
+With two (or more) functions having similar argument lists, and a call that
+passes values that can be implicitly converted to both functions, mcs
+issues an error even if a cast expression is used to disambiguate the call.
+
+This code reproduces the problem:
+
+  using System.Runtime.InteropServices;
+  class Test
+  { 
+    // same function, but with overridden argument list
+    [DllImport("SomeLibrary")]
+    static extern void lowLevelCall(byte[] data);
+    [DllImport("SomeLibrary")]
+    static extern void lowLevelCall(ushort[] data);
+    [DllImport("SomeLibrary")]
+    static extern void lowLevelCall(uint[] data);
+    [DllImport("SomeLibrary")]
+    static unsafe extern void lowLevelCall(void* data);
+  
+    unsafe void Func()
+    { lowLevelCall((void*)null); // CS0121 & CS8006 in mcs
+    }
+  }
+
+Actual Results:
+$ mcs --unsafe -t:library test.cs
+test.cs(11) error CS0121: Ambiguous call when selecting function due to
+implicit casts
+test.cs(11) error CS8006: Could not find any applicable function for this
+argument list
+Compilation failed: 2 error(s), 0 warnings
+
+C:\>csc /unsafe /t:library test.cs
+Microsoft (R) Visual C# .NET Compiler version 7.10.6001.4
+for Microsoft (R) .NET Framework version 1.1.4322
+Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.
+[successful compilation]
+
+Expected Results:
+I would expect mcs to take cast expressions into account when selecting a
+function to call, such that the above code compiles correctly.
+
+How often does this happen? 
+Consistently.
+
+Additional Information:
+The reason for the multiple declarations of the same external function is
+for convenience. The low-level function takes a void*, but it's actually
+expected to be a byte, ushort, or uint array. So the multiple declarations
+provide a "managed" interface for code that uses byte (etc) arrays, and an
+unmanaged interface that matches the original function. The null value is
+convertible to all of those types, but the cast should disambiguate the call.