On 05/15/2009 11:40 PM, John Lenz wrote:
> On 04/17/2009 09:25 AM, John Lenz wrote:
>> On 04/17/2009 03:09 AM, Rolf Bjarne Kvinge wrote:
>>> Hi,
>>>
>>>> When attempting to compile a large vb.net project here at work with
>>>> mono, I got a really weird error.  I was able to strip it down to the
>>>> attached file, the error comes about when there are two private
>>>> subclasses of some class.
>>>>
>>>> I am using the mono-basic code from Mono 2.4, and I get the following
>>>> error.   The file compiles without errors in Visual Studio.  As I
>>>> mention
>>>> in the comment, changing Bar to a public class makes the file compile
>>>> without any errors.
>>>>
>>>>
>>>> Visual Basic.Net Compiler version 0.0.0.5914 (Mono 2.4 - r) Copyright
>>>> (C) 2004-2008 Rolf Bjarne Kvinge. All rights reserved.
>>>>
>>>> /home/john/test.vb (28,26) : Error VBNC30390: 'Bar.Testing' is not
>>> accessible because it is 'Public'.
>>>
>>> Yes, this is really weird.
>>>
>>> However you seem to have forgotten to attach the file ;-)
>>>
> The following patch against mono-basic-2.4 fixes the problem for me.
> 

The patch I just sent introduces a new error for code like

Public Class Foo
   Public Class Bar
      Private Structure Baz
        Public Member As Integer
      End Structure

      Public Sub Test()
         Dim b As New Baz
         b.Member = 12
      End Sub
   End Class
End Class

(it needs three levels of nesting).  I introduced the error because
moving the check for IsNestedPrivate inside the loop removed the initial
check since the hierarchy starts at CallerType.DeclaringType instead of
CallerType.

The following patch fixes the original problem and still works for the
above example.

Index: mono-basic-2.4/vbnc/vbnc/source/General/Helper.vb
===================================================================
--- mono-basic-2.4.orig/vbnc/vbnc/source/General/Helper.vb      2009-05-16 
00:04:57.000000000 -0500
+++ mono-basic-2.4/vbnc/vbnc/source/General/Helper.vb   2009-05-16 
00:20:51.000000000 -0500
@@ -1981,8 +1981,14 @@

         'If the called type is not a nested type it is accessible.
         If CalledType.DeclaringType Is Nothing Then Return True
-        'If the called type is a private nested type it is inaccessible
-        If CalledType.IsNestedPrivate Then Return 
Helper.CompareType(CalledType.DeclaringType, CallerType)
+
+        'The caller can descend once into a private type, check if that is the 
case
+        If CalledType.IsNestedPrivate Then
+            'don't fail here, because could be the private nesting is further 
up the hierarchy
+            If Helper.CompareType(CalledType.DeclaringType, CallerType) Then
+                Return True
+            End If
+        End If

         'Add all the surrounding types of the caller type to a list.
         Dim callerHierarchy As New Generic.List(Of Type)
@@ -1996,6 +2002,10 @@
         Do Until tmpCaller Is Nothing
             If callerHierarchy.Contains(tmpCaller) Then
                 'We've reached a common surrounding type.
+
+                'The caller can descend once into a private type, check that 
here.
+                If CalledType.IsNestedPrivate Then Return 
Helper.CompareType(CalledType.DeclaringType, tmpCaller)
+
                 'No matter what accessibility level this type has
                 'it is accessible.
                 Return True
@@ -2007,6 +2017,9 @@
             tmpCaller = tmpCaller.DeclaringType
         Loop

+        'If the called type is a private nested type and the above checks 
failed, it is inaccessible
+        If CalledType.IsNestedPrivate Then Return 
Helper.CompareType(CalledType.DeclaringType, CallerType)
+
         'There is no common surrounding type, and the access level of all
         'surrounding types of the called types are non-private, so the type
         'is accessible.
_______________________________________________
Mono-vb mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-vb

Reply via email to