[Mono-bugs] [Bug 591149] New: Is this a real compilation error? Visual Studio says OK, Mono returns error

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Mar 25 11:38:19 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=591149

http://bugzilla.novell.com/show_bug.cgi?id=591149#c0


           Summary: Is this a real compilation error? Visual Studio says
                    OK, Mono returns error
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.6.x
          Platform: i586
        OS/Version: SuSE Linux 10.0
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: djechelon at fastwebnet.it
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: No


Description of Problem:
I found that my assembly gets compiled by Visual Studio C# compiler, but not by
gmcs.

The code fragment is the following (a * highlights the affected line): we're
inside an ASP.NET user control

public bool AutoGrantTokens
        {
            get
            {
                *return (ViewState["AutoTokens"] != null &&
ViewState["AutoTokens"] is bool) ? (bool)ViewState["AutoTokens"] != null :
true;
            }
            set
            {
                ViewState["AutoTokens"] = value;
            }
        }

Actually, this is an error in my code because I abused of copy&paste, but still
Visual Studio accepts "(bool)ViewState["AutoTokens"] != null" as a valid
statement and compiles it (probably it interprets it as "cast to bool the
result of <viewstate[...] is not null>"), instead Mono says

"Controls/CaptchaControl.ascx.cs(71,101): error CS0453:  The type `bool?' must
be a non-nullable value type in order to use it as type parameter `T' in the
generic type or method `System.Nullable<T>'."

Simply, it might be evaluating the expression as "convert viewstate[...] to
bool, then evaluate if it's not null".

I know that is an error in my application code (because what I want is obtained
by removing !=null), but it should still be a bug if the two compilers differ
in evaluating C# statements. One might want to use a similar statement in his
code and find different behaviours in the final program.
However, written like that, and not like (bool)(Viewstate[...]!=null) it might
sound like a bug in VS compiler.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list