Bug 10314 - [PARSER] Mono parser makes numerous contextual keyword errors
Summary: [PARSER] Mono parser makes numerous contextual keyword errors
Status: NEW
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
: 10094 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-02-14 17:57 UTC by Brett van Swelm
Modified: 2013-03-20 17:35 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Brett van Swelm 2013-02-14 17:57:19 UTC
C# has many "conditional" keywords; these are words which have special meaning in the language, but only when found in certain special contexts; outside of those contexts they should be treated as ordinary identifiers.

Any identifier may be prefixed with "@" to make it explicitly an identifier. 

Mono incorrectly requires the @ prefix in many places; I've illustrated each that I've found so far in the code below. This file compiles correctly as-is, but if any single @ is removed then the compiler gives an error. 

In some cases -- particularly the cases involving "partial" -- the errors are bizarre and point to possible other bugs in the Mono parser.

With "D:\Applications\Mono-2.11.4\bin" and "C:\Windows\Microsoft.NET\Framework\v4.0.30319" in the path on my Windows 7 machine:

===== Conditional.cs =====
namespace AsyncProblems
{
    class Classes {
        class async {}
        void M() {
            @async local;
        }
    }

    namespace Namespaces {
        namespace @async {}
    }
}

namespace WhereProblems
{
    // Interestingly enough, this is legal in a generic method and a delegate.
    class MyClass<@where> {}
    interface MyInterface<@where> {}
    struct MyStruct<@where> {}

    class Classes {
        class @where {}
        class DER17 : @where {}
    }
}

namespace FromProblems
{
    class from {}
    class C {
        void M1() {
            @from local = new from();
        }     
        @from M2() {
            return null;
        }
    }
}

namespace PartialProblems
{
    class Classes {
        class partial {}
        void M1(@partial formalParameter) {}

        @partial M3() {
            return null;
        }

        @partial field;
    }

}

namespace AwaitProblems {
    class Formals {
        delegate void D(int x);
        static void M1() {
            D d1 = @await=>{};
            D d2 = (int @await)=>{};
            D d3 = delegate (int @await) {};
        }
    }

    class Methods {
        void await() {}
        void M(Methods m) {
            m.@await();
            this.@await();
            @await();
        }
    }

    class Classes {
        class await {}
        void M()
        {
            @await local = new @await();
        }     
     }

     class AnonTypes {
        static void M() {
            var x = new { @await = 1 };
            var y = x.@await;
        }
    }
}
===== end =====

$ mcs /target:library Conditional.cs 
Conditional.cs(6,20): warning CS0168: The variable `local' is declared but never used
Conditional.cs(33,19): warning CS0219: The variable `local' is assigned but its value is never used
Conditional.cs(60,15): warning CS0219: The variable `d1' is assigned but its value is never used
Conditional.cs(61,15): warning CS0219: The variable `d2' is assigned but its value is never used
Conditional.cs(62,15): warning CS0219: The variable `d3' is assigned but its value is never used
Conditional.cs(79,20): warning CS0219: The variable `local' is assigned but its value is never used
Conditional.cs(51,18): warning CS0169: The private field `PartialProblems.Classes.field' is never used
Compilation succeeded - 7 warning(s)

Thanks,

Brett van Swelm | Senior Engineer
Coverity | 185 Berry Street | Suite 6500, Lobby 3 | San Francisco, CA 94107
The Leader in Development Testing
Read our profile in Forbes, Coverity Gets Code Right 25% Faster
Comment 1 Marek Safar 2013-02-20 16:00:09 UTC
Most errors should be fixed in master
Comment 2 Marek Safar 2013-03-20 17:34:55 UTC
What is still failing is await at first expression statement token

namespace AwaitProblems {
    class Methods {
        void await() {}
        void M(Methods m) {
            await();
        }
    }

    class Classes {
        class await {}
        void M()
        {
            await local = new await();
        }     
     }
}
Comment 3 Marek Safar 2013-03-20 17:35:32 UTC
*** Bug 10094 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.