472,989 Members | 3,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Mismatched behaviour between regular compiler and refactoringcompiler

The included program compiles without errors, but produces an error
when you attempt to use a refactoring tool:

J:\TypeofTest\TypeofTest1\Program.cs(3,27): error CS0246: The type or
namespace name 'Bar' could not be found (are you missing a using
directive or an assembly reference?)

In addition, the syntax highlighter doesn't highlight the "Bar" in
"typeof(Bar)" as a class. If I replace that with "typeof(Foo.Bar)",
everything works as expected. What I don't understand is why there is
a difference. Should it be possible to implicitly reference an inner
class in an attribute like this (in which case it seems the
refactoring compiler is incorrect) or is it in fact not allowed (in
which case surely the regular compiler should say something)? I'm
using Visual Studio 2005.

using System.Diagnostics;

[DebuggerTypeProxy(typeof(Bar))]
public class Foo
{
public class Bar
{
private Foo m_foo;
public Bar(Foo foo) { m_foo = foo; }
}
}

class Program
{
static void Main() { }
}
Jun 27 '08 #1
10 1228
I've found a further problem. In the code that this example is derived
from, the equivalent to Bar is a private class. In that case, when I
change "typeof(Bar)" to "typeof(Foo.Bar)", I get a new error (again,
only from the refactoring compiler, not the regular one):

J:\TypeofTest\TypeofTest1\Program.cs(3,31): error CS0122: 'Foo.Bar' is
inaccessible due to its protection level

It seems it comes down to a question of whether or not the expression
for attribute constructors are evaluated inside or outside the scope
of the class. I should note that I'm using a private inner class in
large part because of this example here:

http://msdn2.microsoft.com/en-us/library/x810d419.aspx

Even so, I think it's cleaner to use a private inner class rather than
an internal top-level class, because there's really no need to make
the debug stuff visible to any other code.

On Apr 29, 11:44 am, Weeble <clockworksa...@gmail.comwrote:
The included program compiles without errors, but produces an error
when you attempt to use a refactoring tool:

J:\TypeofTest\TypeofTest1\Program.cs(3,27): error CS0246: The type or
namespace name 'Bar' could not be found (are you missing a using
directive or an assembly reference?)

In addition, the syntax highlighter doesn't highlight the "Bar" in
"typeof(Bar)" as a class. If I replace that with "typeof(Foo.Bar)",
everything works as expected. What I don't understand is why there is
a difference. Should it be possible to implicitly reference an inner
class in an attribute like this (in which case it seems the
refactoring compiler is incorrect) or is it in fact not allowed (in
which case surely the regular compiler should say something)? I'm
using Visual Studio 2005.

using System.Diagnostics;

[DebuggerTypeProxy(typeof(Bar))]
public class Foo
{
public class Bar
{
private Foo m_foo;
public Bar(Foo foo) { m_foo = foo; }
}

}

class Program
{
static void Main() { }

}
Jun 27 '08 #2
but produces an error
when you attempt to use a refactoring tool:
Which refactoring tool? The code is fine "as is" for regular C#...

Marc
Jun 27 '08 #3
On Apr 29, 12:45 pm, Marc Gravell <marc.grav...@gmail.comwrote:
but produces an error
when you attempt to use a refactoring tool:

Which refactoring tool? The code is fine "as is" for regular C#...

Marc
Any of the built-in refactoring tools in Visual Studio 2005 seem to do
it for me. For example, right-click on "Program" (or any other
identifier) and choose "Refactor->Rename..." The output window will
switch to "Show output from: Refactor" and the error I described will
appear in it. The other symptom is the syntax highlighting, as I said.
If I have "typeof(Bar)" then "Bar" will appear black, whereas if I
have "typeof(Foo.Bar)", the "Foo.Bar" will appear teal, the colour
that indicates the name of a class.

I do have Visual Assist X installed, but I disabled it for these tests.
Jun 27 '08 #4
Verified (in VS2008) - interesting! But (in VS2008, at least) it is
purely cosmetic - the refactor still completes successfully (you just
get a yellow-triangle warning that it isn't happy, but once complete
it compiles fine; and so I couldn't say it is super-critical, unless
it actually stops VS2005 from completing the refactor [does it?]) .

I would suggest logging it via connect... http://connect.microsoft.com/VisualStudio
(if you do log it, post the url and I'll mark it as validated; or if
you don't already have a passport, I could log it on your behalf if
you like - but I won't do so without your nod).

Marc
Jun 27 '08 #5
On Apr 29, 1:56 pm, Marc Gravell <marc.grav...@gmail.comwrote:
I would suggest logging it via connect...http://connect.microsoft.com/VisualStudio
(if you do log it, post the url and I'll mark it as validated; or if
you don't already have a passport, I could log it on your behalf if
you like - but I won't do so without your nod).
Yikes, that was an ordeal to get set up. I've submitted the bug here
(I think):
https://connect.microsoft.com/Visual...dbackID=340962
Jun 27 '08 #6
On Apr 29, 3:24 pm, Weeble <clockworksa...@gmail.comwrote:
On Apr 29, 1:56 pm, Marc Gravell <marc.grav...@gmail.comwrote:
I would suggest logging it via connect...http://connect.microsoft.com/VisualStudio
(if you do log it, post the url and I'll mark it as validated; or if
you don't already have a passport, I could log it on your behalf if
you like - but I won't do so without your nod).

Yikes, that was an ordeal to get set up. I've submitted the bug here
(I think):https://connect.microsoft.com/Visual...wFeedback.aspx...
It got resolved "Won't Fix". Does that mean never? Seems a bit
disappointing. I tried to figure out which behaviour is correct, and
the best I could understand from the spec is that the refactoring
engine is correct and the regular compiler is wrong on the basis that
class members are only in scope inside the "class body", which
comprises everything between the curly braces, but not the attribute
specifiers. To be honest, that's not the behaviour I'd want, but I
couldn't see anything in there that would make me believe that either
attribute specifiers count as being in the class body, or that class
members are in scope anywhere except the class body or the class body
of a descendent class.

My workaround is to implement DebuggerTypeProxy classes as inner
classes with internal instead of private access, and to use fully
qualified names when constructing the attributes. That way both the
refactoring engine and the regular compiler seem happy. I wouldn't
like the refactoring engine to be spitting out lots of errors whenever
a colleague attempts to use it, even if I know it shouldn't actually
prevent it from working.
Jun 27 '08 #7
I'd need to look closely at the spec to figure which behavior is
correct; I would presume the regular compiler, but it could go either
way... however, I can see their view that it isn't eactly critical
(purely cosmetic, and purely during refactoring). But yes: sometimes
it can be frustrating when you see "won't fix"; I've had "won't fix"
with critical runtime issues in things like WSE, and even something as
simple (yet commonplace) as the runtime not being able to sort strings
correctly [genuinely!]. But sometimes things do get fixed... oh well.

Marc
Jun 27 '08 #8
On May 2, 10:37 am, Marc Gravell <marc.grav...@gmail.comwrote:
I'd need to look closely at the spec to figure which behavior is
correct; I would presume the regular compiler, but it could go either
way... however, I can see their view that it isn't eactly critical
(purely cosmetic, and purely during refactoring). But yes: sometimes
it can be frustrating when you see "won't fix"; I've had "won't fix"
with critical runtime issues in things like WSE, and even something as
simple (yet commonplace) as the runtime not being able to sort strings
correctly [genuinely!]. But sometimes things do get fixed... oh well.
A few hours later there was a comment explaining the reasoning. I
totally understand that it's not worth going to the bother of changing
the refactoring engine in 2005 or 2008 for something quite minor. I
am, however, worried by the idea that the problem could be in the
regular compiler. To me, that would be quite serious. I'm hoping that
someone who understands the spec better than I do might explain it to
me.

As I understand it, based on the C# Spec V3, the "scope" of a class
member (i.e. the places it can be used without "Class.Member"
qualification) is the "class-body" of that class and of any
subclasses. (3.7) The "accessibility domain" of a private class
member (i.e. the places it can be accessed from at all) are the
"program text" of the class, which is itself defined as the "class-
body". (3.5.2) The "class-body" is defined as being everything
between the { curly braces } of the class, which does not include
attribute specifiers.

I sure do hope my interpretation is wrong!
Jun 27 '08 #9
On May 2, 1:55 pm, Weeble <clockworksa...@gmail.comwrote:

<snip>
As I understand it, based on the C# Spec V3, the "scope" of a class
member (i.e. the places it can be used without "Class.Member"
qualification) is the "class-body" of that class and of any
subclasses. (3.7) The "accessibility domain" of a private class
member (i.e. the places it can be accessed from at all) are the
"program text" of the class, which is itself defined as the "class-
body". (3.5.2) The "class-body" is defined as being everything
between the { curly braces } of the class, which does not include
attribute specifiers.

I sure do hope my interpretation is wrong!
Well, your logic certainly sounds right to me. However, it could just
be another case where the bug is actually in the spec - that the
current behaviour is the designed one, but the design wasn't correctly
described in the spec. I think it's as likely that there'll be a spec
change to fix this as a compiler change (especially as fixing the spec
to mirror reality isn't a breaking change; fixing the compiler to
mirror the spec certainly would be).

Another one to ask the team, I guess...

Jon
Jun 27 '08 #10
Jon Skeet [C# MVP] <sk***@pobox.comwrote:

<snip>
Another one to ask the team, I guess...
Here's the reply:

<quote>
This certainly looks like an error in the specification. I'll see what
we can do about getting it fixed. Thanks for bringing it to our
attention.
</quote>

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gerhard Esterhuizen | last post by:
Hi, I am observing unexpected behaviour, in the form of a corrupted class member access, from a simple C++ program that accesses an attribute declared in a virtual base class via a chain of...
25
by: Nitin Bhardwaj | last post by:
Well, i'm a relatively new into C( strictly speaking : well i'm a student and have been doing & studying C programming for the last 4 years).....and also a regular reader of "comp.lang.c" I...
12
by: RoSsIaCrIiLoIA | last post by:
On Mon, 07 Feb 2005 21:28:30 GMT, Keith Thompson <kst-u@mib.org> wrote: >"Romeo Colacitti" <wwromeo@gmail.com> writes: >> Chris Torek wrote: >>> In article <4205BD5C.6DC8@mindspring.com> >>>...
31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
62
by: Argento | last post by:
I was curious at the start about how ungetc() returns the character to the stream, so i did the following coding. Things work as expected except if I change the scanf("%c",&j) to scanf("%d",&j). I...
24
by: temper3243 | last post by:
Hi, Many people have used this code in my project. It works because b is using the extra memory for other 4 variables.I access obj max. well here are a few questions 1) Where does it fail. I...
285
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/...
3
by: Martin Kulov [MVP] | last post by:
Hi, I am wondering if this problem is still valid for ASP.NET 2.0. "To maintain session state across different Web servers in the Web farm, the application path of the Web site (for example,...
11
by: Pranav | last post by:
The Code is compiling without Error/Bug/Exception.., What are the possibilities for this behaviour? //*************************************************************** #include<stdio.h> typedef...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.