bugDotGNU Portable.NET - Bugs: bug #19129, Reading uninitialised variable...

 
 

You are not allowed to post comments on this tracker with your current authentification level.

bug #19129: Reading uninitialised variable does not cause compile error.

Submitted by:  None
Submitted on:  Fri 23 Feb 2007 01:43:13 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Sat 24 Feb 2007 02:04:58 AM UTC, comment #3:

Hello,

I see your point. Semantics are still defined for uninitialized variables and therefore the code is correct seen from the compilers point of view, and soundness is preserved.

However, I do not agree that "my code will work". How should the compiler know which value I need my variables to be initialized with? The original error message was helping the programmer.

Robert Jørgensgaard Olesen <egir>
Fri 23 Feb 2007 02:59:36 PM UTC, comment #2:

Hello,
i can confirm this from my experience. I guess that checking for unitialized values is not implemented in cscc compiler, but the resulting code is correct (all variables in C# are internally always initialized to the default value which is 0 in this case.)

You can safely use cscc even if it does not print these warnings. Your code will work, but you will have to correct your code to compile with other C# compilers then (which is not really big problem).

Radek Polak <radekp>
Project Member
Fri 23 Feb 2007 02:54:58 PM UTC, comment #1:

This violates the soundness of the C# type system.

Robert Jørgensgaard Olesen <egir>
Fri 23 Feb 2007 01:43:13 PM UTC, original submission:

Reading uninitialised variable does not cause compile error. I was reading "Programming C#" from Oreley. Example3-2 on page 27 is an example of using an unitialised variable, see attachment. According to "Programming C#" I am suposed to get this error message when compiling:

3.1.cs(6,55): error CS0165: Use of unassigned local
variable 'myInt'

But cscc version 0.7.4 compiles without any error, and the program runs without crashing:

$ cscc Values.cs
$ ilrun a.out
Uninitialized, myInt: 0
Assigned, myInt: 5

According to "Programming C#" it is not legal to use an unitialised variable in C#.

Example3-2 is attached as Value.cs.

Anonymous

 

Attached Files
file #12030:  Values.cs added by None (252B - text/x-csharp - Example3-2 from "Programming C#")

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by radekp (Posted a comment)
  • -unavailable- added by egir (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 23 Feb 2007 02:27:23 PM UTCegirCarbon-Copy-=>Added egir
    Fri 23 Feb 2007 01:43:13 PM UTCNoneAttached File-=>Added Values.cs, #12030

    Back to the top


    Powered by Savane 3.1-cleanup