Bug 14734 - Use of unassigned struct variables does not lead to a compile error.
Summary: Use of unassigned struct variables does not lead to a compile error.
Status: RESOLVED FEATURE
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-09-13 17:18 UTC by kissling
Modified: 2013-09-26 08:45 UTC (History)
1 user (show)

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


Attachments
Test case where the described issue occurs. Check AppDelegate.cs. (7.44 KB, application/zip)
2013-09-13 17:18 UTC, kissling
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description kissling 2013-09-13 17:18:16 UTC
Created attachment 4872 [details]
Test case where the described issue occurs. Check AppDelegate.cs.

When using a variable of a struct type, it can be used before a value is assigned. In Visual Studio, this leads to a compile error: "Use of unassigned local variable `x". Basic value types behave consistently.

Project with a sample test case is attached.


	private void TestCorrect()
	{
		int x;
		Console.WriteLine(x);  // Use of unassigned local variable `x'

	}

	private void TestBug()
	{
		BugStruct s;
		Console.WriteLine(s);  // No error with Xamarin. Does not compile in Visual Studio.
	}

	public struct BugStruct
	{
	}



Version information:


=== Xamarin Studio ===

Version 4.1.10 (build 14)
Installation UUID: 938751df-f7a5-457d-b87b-379763e0ada1
Runtime:
	Mono 3.2.2 ((no/a0fc6ba)
	GTK+ 2.24.20 theme: Raleigh
	GTK# (2.12.0.0)
	Package version: 302020000

=== Xamarin.Android ===

Version: 4.8.2 (Business Edition)
Android SDK: /Users/***/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.3   (API level 18)
Java SDK: /usr
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)

=== Apple Developer Tools ===

Xcode 5.0 (3329.43)
Build 5A11365x

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.iOS ===

Version: 6.9.7.13 (Business Edition)
Hash: e7c3c68
Branch: 
Build date: 2013-11-09 22:23:45-0400

=== Build Information ===

Release ID: 401100014
Git revision: e88e6ef4416e4f8ca405a372df4f26cd67a2e8f6
Build date: 2013-09-05 20:32:03+0000
Xamarin addins: 0a3cbd89efe969c522b81dc7c24d7da1564df585

=== Operating System ===

Mac OS X 10.8.5
Darwin ***.local 12.5.0 Darwin Kernel Version 12.5.0
    Mon Jul 29 16:33:49 PDT 2013
    root:xnu-2050.48.11~1/RELEASE_X86_64 x86_64
Comment 1 Marek Safar 2013-09-24 13:35:52 UTC
I cannot reproduce the issue. There is nothing what should fail to compile. Extracted simple sample compiles by XS and VS

using System;

class BB
{
	public static void Main ()
	{
		BugStruct s;

		Console.WriteLine(s);  // No error with Xamarin. Does not compile in Visual Studio.
	}
}

public struct BugStruct
{
}
Comment 2 kissling 2013-09-26 08:45:32 UTC
Seems like I messed up :-)

It compiles in both Visual Studio and Xamarin Studio, unless a field is added to the BugStruct. Then, it does not compile in both Visual Studio and Xamarin Studio.

It used to compile in Xamarin Studio even if there was a field in the BugStruct.