Bug 313426 (MONO52408) - MCS does not know the difference between a `new' property and an `override' property
Summary: MCS does not know the difference between a `new' property and an `override' p...
Status: RESOLVED FIXED
Alias: MONO52408
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2003-12-21 09:32 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
mcs-52408.patch -- patch (13.38 KB, patch)
2003-12-22 18:19 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:22:32 UTC


---- Reported by bmaurer@users.sf.net 2003-12-21 02:32:28 MST ----

Description of Problem:
MCS is having trouble with the scoping of properties.

Steps to reproduce the problem:using System;

class A {
	public int Prop {
		get { Console.WriteLine (this.GetType ()); return 1; }
		set { Console.WriteLine (this.GetType ()); }
	}
}

class B : A {
	public int Prop {
		get { Console.WriteLine (this.GetType ()); return 1; }
	}
	
	static void Main () {
		B b = new B ();
		b.Prop ++;
	}
}

Actual Results:
Successful compile

Expected Results:
It should not compile b.Prop is readonly.

How often does this happen? 
Always

Additional Information:
I am not sure how we can tell this from the Metadata, we are not given
much. The PropertyInfo gives no way for us to tell the new case from the
override case. I think we have to look *directly* at the MethodInfo.

Miguel?



---- Additional Comments From bmaurer@users.sf.net 2003-12-21 11:17:43 MST ----

Note in the spec, sec 17.6.2 it states:

`When a derived class declares a property by the same name as an
inherited property, the derived property hides the inherited property
with respect to both reading and writing.'

It gives an example that we are not able to compile and use correctly:

class A  { public int P { set {...} } } 
class B: A  { new public int P { get {...} } }

B b = new B();
b.P = 1; // Error, B.P is read-only
((A)b).P = 1;  // Ok, reference to A.P

On the line b.P we do not report an error.




---- Additional Comments From bmaurer@users.sf.net 2003-12-21 11:50:31 MST ----

Ok, I think I found the critical piece:

class A {
	public virtual int Prop {
		get { ... }
		
	}
}

class B : A {
	public override int Prop {
		get { ... }
		set { ... }
	}
}

is not valid. Eg, you can not `augment' existing properties. So, what
we need to do when we are scanning is:

1) Take a look at the PropertyInfo, it will have either a get or a set
method (or both). If neither of them are `override', then we have
found the full set of properties

2) If one of them *is* override, we need to search the base classes
for a definition. 



---- Additional Comments From bmaurer@users.sf.net 2003-12-21 16:40:51 MST ----

Have a patch for the client. Need to do some bug checking on the decl
side of this (eg, can we run an invalid example, as in my last comment).



---- Additional Comments From bmaurer@users.sf.net 2003-12-22 00:52:16 MST ----

ok, so now i have a patch for everything with properties. Now I have
to test and work with indexers.

Also, my patch adds .2 sec to bootstrap, I can probably cut down that
affect.



---- Additional Comments From bmaurer@users.sf.net 2003-12-22 11:19:19 MST ----

Created an attachment (id=165363)
mcs-52408.patch -- patch




---- Additional Comments From bmaurer@users.sf.net 2003-12-22 11:21:01 MST ----

This patch should fix the stuff relating to properties.

I still need to study Indexer calls, however, since that code will
build on this stuff, I would like to get this checked in first.

I am going to come up with a test suite for this all.

The perf regression is gone, in fact, this patch brings a (very) small
improvement.



---- Additional Comments From bmaurer@users.sf.net 2003-12-22 12:03:09 MST ----

I just did some regression-prevention patches (issues that I found
while writing the code, that could easily be reintroduced). Those work
on the current cvs code, so i checked it in. Will work on the error
testing later.



---- Additional Comments From miguel@ximian.com 2004-05-12 13:15:12 MST ----

Does it mean that the bug is fixed and its missing tests?





---- Additional Comments From marek.safar@seznam.cz 2004-09-16 09:49:28 MST ----

I think we can close this patch.



---- Additional Comments From miguel@ximian.com 2004-09-19 02:51:23 MST ----

Closing.

Imported an attachment (id=165363)

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