Bug 313368 (MONO52146) - [PATCH] MCS does not respect private ctors
Summary: [PATCH] MCS does not respect private ctors
Status: RESOLVED FIXED
Alias: MONO52146
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Minor
Target Milestone: V1
Assignee: Raja R Harinath
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2003-12-14 01:33 UTC by Ben Maurer
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
patch (798 bytes, patch)
2004-04-27 16:01 UTC, Thomas Wiest
Details | Diff
updated patch (1.04 KB, patch)
2004-04-27 21:07 UTC, Thomas Wiest
Details | Diff
new patch (1.03 KB, patch)
2004-04-28 13:08 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 18:21:54 UTC


---- Reported by bmaurer@users.sf.net 2003-12-13 18:33:05 MST ----

Description of Problem:
If a class has a private ctor, it cant be used.


Steps to reproduce the problem:
class A { A () {}}
class T : A {
	static void Main () { T t = new T (); }
}

Actual Results:
Compile

Expected Results:
No compile.

Additional Information:
Is it also a runtime bug that this program runs?



---- Additional Comments From miguel@ximian.com 2003-12-14 10:35:21 MST ----

We should basically check things on the class base declaration:

A.A() is inaccessible due to its protection level



---- Additional Comments From pcgod@gmx.net 2004-04-27 09:01:30 MST ----

Created an attachment (id=165313)
patch




---- Additional Comments From bmaurer@users.sf.net 2004-04-27 11:33:23 MST ----

parent_constructor.IsAssembly needs to be complemented with a check 
that the class and its base are in the same assembly.

Also, I think this would be legal:

class A {
    private A () {}
    class Nested : A {
    }
}

Because a nested class can see private members of its parent class.



---- Additional Comments From pcgod@gmx.net 2004-04-27 14:07:17 MST ----

Created an attachment (id=165314)
updated patch




---- Additional Comments From bmaurer@users.sf.net 2004-04-27 18:50:34 MST ----

parent_constructor.DeclaringType.Assembly.FullName ==
ec.ContainerType.Assembly.FullName) &&
This is not necessary, just compare the assemblies.

ec.ContainerType.BaseType == parent_constructor.DeclaringType)) {
It need not be a direct nesting. Use the IsXXX methods in TypeManager.

Also, this is not a contest for `how complex can I make an if
statement'. Let's break this down into readable code please :-).



---- Additional Comments From pcgod@gmx.net 2004-04-28 06:08:13 MST ----

Created an attachment (id=165315)
new patch




---- Additional Comments From bmaurer@users.sf.net 2004-04-28 09:27:08 MST ----

These if statements dont really work correctly.

Just make a method

bool CheckVisibility

That returns true if it is ok, false if it is invalid. THen you can 
write clean code.



---- Additional Comments From martin@ximian.com 2004-04-29 14:00:29 MST ----

I don't like the patch at all - why reinvent the wheel when we already
have MemberLookup() for such things.

Fixed in CVS.

Imported an attachment (id=165313)
Imported an attachment (id=165314)
Imported an attachment (id=165315)

Unknown operating system unknown. Setting to default OS "Other".