[Mono-bugs] [Bug 369049] New: vbnc: miscompile passing valuetype to ByRef Object parameter
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Tue Mar 11 06:11:51 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=369049
Summary: vbnc: miscompile passing valuetype to ByRef Object
parameter
Product: Mono: Compilers
Version: 1.2.6
Platform: Other
OS/Version: Other
Status: NEW
Severity: Minor
Priority: P5 - None
Component: Basic
AssignedTo: rkvinge at novell.com
ReportedBy: andyhume32 at yahoo.co.uk
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Passing a value type to a ByRef Object parameter is accepted but miscompiled
currently.
Code of the form:
[[
Option Strict On ' Or Off, see text
Option Explicit On
Public Structure SomeStruct
Public x As Integer
Public y As Integer
End Structure
Public Class ByRefValueType
Shared Sub Main()
Dim ss As SomeStruct
ss.x = 111
MethodSomeStructByRef(ss)
Console.WriteLine(ss.x)
End Sub
Shared Sub MethodSomeStructByRef(ByRef obj As Object)
Console.WriteLine(FooIsNull(obj))
Console.WriteLine("'{0}'", obj)
Console.WriteLine(obj.GetType())
Dim ss As SomeStruct = DirectCast(obj, SomeStruct)
'Console.WriteLine(ss.x)
ss.x = 99999
obj = ss
End Sub
Shared Function FooIsNull(ByVal o As Object) As Boolean
Return o Is Nothing
End Function
End Class
]]
This currently fails with the following when run:
[[
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object
at (wrapper stelemref) System.Object:stelemref (object,intptr,object)
at System.String.Format (System.String format, System.Object arg0) [0x00000]
in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.2.6\mcs\class\corlib\System\String.cs:1397
at System.IO.TextWriter.Write (System.String format, System.Object arg0)
[0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.2.6\mcs\class\corlib\System.IO\TextWriter.cs:198
at System.IO.TextWriter.WriteLine (System.String format, System.Object arg0)
[0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.2.6\mcs\class\corlib\System.IO\TextWriter.cs:312
at System.IO.SynchronizedWriter.WriteLine (System.String format,
System.Object value) [0x00008] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.2.6\mcs\class\corlib\System.IO\TextWriter.cs:605
at System.Console.WriteLine (System.String format, System.Object arg0)
[0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.2.6\mcs\class\corlib\System\Console.cs:418
at VtToByrefObject.MethodSomeStructByRef (System.Object& obj) [0x0000c] in
D:\Documents and Settings\alan\My
Documents\Suppliers\Mono\vbnc\VtToByrefObject.vb:20
at VtToByrefObject.Main () [0x00009] in D:\Documents and Settings\alan\My
Documents\Suppliers\Mono\vbnc\VtToByrefObject.vb:14
]]
With Strict=On, MSFT disallows the code with:
[[
C:\VtToByrefObject.vb(12) : error BC32029: Option Strict On disallows narrowing
from type 'Object' to type 'SomeStruct' in copying the value of 'ByRef'
parameter 'obj' back to the matching argument.
MethodSomeStructByRef(ss)
~~
]]
As implied by the expected error message above, when using the code with
Strict=Off, then the value type has to be boxed into the call, and on return
has to be unboxed and copied back onto the variable. The correct result is
thus seen, on return ss.x contains 99999. I guess that's as covered by the
second paragraph in vbls80.doc section 11.8.3.
Minor as very rare case. Perhaps we just need to block such code??
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list