[Mono-bugs] [Bug 371561] New: vbnc: Allows access to instance members from a static context
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Sun Mar 16 11:22:23 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=371561
Summary: vbnc: Allows access to instance members from a static
context
Product: Mono: Compilers
Version: 1.2.6
Platform: Other
OS/Version: Other
Status: NEW
Severity: Normal
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: ---
All types of instance members can be accessed from a non-instance context.
Applies to fields, methods etc including creating a delegate.
The following should report twelve instances of BC30369 "Cannot refer to an
instance member of a class from within a shared method or shared member
initializer without an explicit instance of the class.", but no errors are
reported. The app fails at runtime.
(In fact, rather than reporting twelve BC30369, MSFT’s vbc reports ten
BC30369, and two BC30518 for the get_Bar lines -- but their root cause is also
BC30369).
[[
Option Strict On
Option Explicit On
Public Class StaticCreateDelegateToSharedMethod
Public Shared Sub Main()
' All lines here should fail with BC30369:
' "Cannot refer to an instance member of a class from within a shared
method or shared member initializer without an explicit instance of the class."
Console.WriteLine(m_foo)
Console.WriteLine(Foo())
Dim eh As New EventHandler(AddressOf InstanceMethodA)
AddHandler WizBangChanged, eh
Bar = 100
' This causes a very wierd error in MSFT's vbc, it reports overload
resolution
' failed on WriteLine, but reports each overload alongwith the message
from BC30369
Console.WriteLine(Bar)
End Sub
'
' A selection of instance members
'
Public Sub InstanceMethodA(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("curious!")
End Sub
Public Function Foo() As int32
Return &H45
End Function
Public Property Bar() As int32
Get
Return m_bar
End Get
Set(ByVal value As int32)
m_bar = value
End Set
End Property
Public Event WizBangChanged As EventHandler
Private m_bar As Integer
Public m_foo As Int32 = 99
Public m_here As String = "here"
End Class
Class AnyDifferenceWhenAccessFromAnotherClass
Sub Accesses()
' As above.
Console.WriteLine(StaticCreateDelegateToSharedMethod.m_foo)
Console.WriteLine(StaticCreateDelegateToSharedMethod.Foo())
Dim eh As New EventHandler(AddressOf
StaticCreateDelegateToSharedMethod.InstanceMethodA)
AddHandler StaticCreateDelegateToSharedMethod.WizBangChanged, eh
StaticCreateDelegateToSharedMethod.Bar = 100
Console.WriteLine(StaticCreateDelegateToSharedMethod.Bar)
End Sub
End Class
]]
--
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