[Mono-dev] Unexpected compiler errors when using "as" keyword

Aaron Colwell acolwell at shelfari.com
Tue Aug 12 15:23:52 EDT 2008


Hi,

I've been trying to port some C# code to mono and encountered a difference
with
how gmcs & Visual Studio handle the "as" keyword. The code below is a simple
repro
case that demonstrates the problem.

using System;

namespace AsStringProblem
{
 class MainClass
 {
  public static void Main(string[] args)
  {
   object o = "Hello World";
   Console.WriteLine(o as string  + "blah");   // A. Error in Mono
   Console.WriteLine((o as string)  + "blah"); // B. Ok
   Console.WriteLine("blah" + o as string);    // C. Ok

  }
 }
}

It may seem like an odd case, but we typically use constructs like this when
constructing strings from DataRow fields.

I've spent some quality time looking at parser output and the grammar and
I'm
having a hard time understanding why C works, but A doesn't. I'm also
confused
why C works at all since my interpretation of the grammar seems to imply
that
only putting "as" clauses in parenthesis will make them compatible with an
additive-expression.

So here are my questions:
1. Is this a known issue and is someone working on it?
2. Is my interpretation of the grammar(as specified in cs-parser.jay and/or
in the ECMA-334 spec) correct
   and A & C shouldn't work ?
3. Does anyone have suggestions on how I can get A to work. (I have a lot of
instances of these and it would
   make me sad to have to put () around all them).

Any help would be greatly appreciated.

Thanks,
Aaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080812/d8539442/attachment-0001.html 


More information about the Mono-devel-list mailing list