Bugzilla – Bug 313368
[PATCH] MCS does not respect private ctors
Last modified: 2007-09-15 21:24:23 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".