Bug 312222 (MONO41787) - Definite assignment errors
Summary: Definite assignment errors
Status: RESOLVED MOVED
Alias: MONO41787
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-23 17:44 UTC by Robert Staerk
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 18:09:00 UTC


---- Reported by staerk@inf.ethz.ch 2003-04-23 10:44:08 MST ----

Here are some programs where Mono's MCS and Microsoft's CSC do
not agree on definite assignement (see also 13.3.3 "Precise rules
for determining definite assignment" in the Ecma C# standard).
------------------------------------------------------------------------
using System;

class Test14 {
  static void F(bool b, int i) {
    int x;
    if (b && (x = i) >= 0)
      // OK: 'x' definitely assigned
      Console.WriteLine(x);
    else
      // Error: 'x' not definitely assigned
      Console.WriteLine(x);
  }

  public static void Main() {
    F(true,5);
    F(false,7);
  }
}

// Mono (mcs 0.23 Redhat 7.2)
// > mcs Test14.cs
// Compilation succeeded
// qed> mono Test14.exe
// 5
// 0

// Microsoft .NET
// > csc Test14.cs
// Test14.cs(11,25): error CS0165: Use of unassigned local variable 'x'
------------------------------------------------------------------------
using System;

class Test15 {
  static void F(bool b, int i) {
    int x;
    if (b || (x = i) >= 0)
      // Error: 'x' not definitely assigned
      Console.WriteLine(x);
    else
      // OK: 'x' definitely assigned
      Console.WriteLine(x);
  }

  public static void Main() {
    F(true,5);
    F(false,7);
  }
}

// Mono (mcs 0.23 Redhat 7.2)
// > mcs Test15.cs
// Compilation succeeded
// qed> mono Test15.exe
// 0
// 7

// Microsoft .NET
// > csc Test14.cs
// Test14.cs(11,25): error CS0165: Use of unassigned local variable 'x'
------------------------------------------------------------------------
using System;

class Test13 {
  static void F(int i) {
    int x;
    while (true) {
      if (i < 7) {
	x = 3;
	break;
      }
    }
    // OK: 'x' definitely assigned
    Console.WriteLine(x);
  }

  public static void Main() {
    F(4);
  }
}

// Mono (mcs 0.23 Redhat 7.2)
// > mcs Test13.cs
// Test13.cs(13) error CS0165: Use of unassigned local variable `x'
// Compilation failed: 1 error(s), 0 warnings

// Microsoft .NET
// > csc Test13.cs
// > Test13.exe
// 3
------------------------------------------------------------------------
using System;

class Test5 {
  static void F(bool b) {
    int x;
    while (b?true:true);
    // OK: 'x' definitely assigned
    Console.WriteLine(x);
  }

  public static void Main() {
    F(true);
  }
}

// Mono (mcs 0.23 Redhat 7.2)
// > mcs Test5.cs
// Test5.cs(8) error CS0165: Use of unassigned local variable `x'
// Compilation failed: 1 error(s), 0 warnings

// Microsoft .NET
// > csc Test5.cs
// > Test5.exe
------------------------------------------------------------------------



---- Additional Comments From martin@ximian.com 2003-05-18 17:18:38 MST ----

Setting severity to one week since this'll probably require some larger changes in the flow code.
This means that it may take a long time to get this bug fixed ....




---- Additional Comments From martin@ximian.com 2004-04-27 23:14:34 MST ----

See https://bugzilla.novell.com/show_bug.cgi?id=MONO57747.

*** This bug has been marked as a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=MONO57747 ***


Unknown operating system unknown. Setting to default OS "Other".
This bug was marked DUPLICATE in the database it was moved from.
    Changing resolution to "MOVED"