--- /dev/null
+public struct S
+{
+ int private_value;
+
+ public void Test ()
+ {
+ }
+}
\ No newline at end of file
TEST_SUPPORT_FILES = \
CS0012-lib.dll CS0012-2-lib.dll CS0012-3-lib.dll CS0012-4-lib.dll CS0012-5-lib.dll CS0012-6-lib.dll CS0012-9-lib.dll CS0012-10-lib.dll CS0012-11-lib.dll CS0012-12-lib.dll CS0012-13-lib.dll CS0029-26-lib.dll \
- CS0103-2-lib.dll CS0118-2-lib.dll CS0122-10-lib.dll CS0122-14-lib.dll CS0122-15-lib.dll CS0122-19-lib.dll CS0122-35-lib.dll CS0122-36-lib.dll CS0143-lib.dll CS0144-3-lib.dll \
+ CS0103-2-lib.dll CS0118-2-lib.dll CS0122-10-lib.dll CS0122-14-lib.dll CS0122-15-lib.dll CS0122-19-lib.dll CS0122-35-lib.dll CS0122-36-lib.dll CS0143-lib.dll CS0144-3-lib.dll CS0165-19-lib.dll \
CS0205-3-lib.dll CS0229-3-lib.dll CS0229-4-lib.dll CS0266-25-lib.dll \
CS0315-2-lib.dll \
CS0433-lib.dll CS0433-2-lib.dll \
--- /dev/null
+// CS0165: Use of unassigned local variable `s'
+// Line: 10
+// Compiler options: -r:CS0165-19-lib.dll
+
+class Program
+{
+ static void Main ()
+ {
+ S s;
+ s.Test ();
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS0165: Use of unassigned local variable `s'
+// Line: 9
+
+class Program
+{
+ static void Main ()
+ {
+ S s;
+ s.Test ();
+ }
+}
+
+struct S
+{
+ string pp;
+
+ public void Test ()
+ {
+ }
+}
\ No newline at end of file
// CS0177: The out parameter `parameterModifiers' must be assigned to before control leaves the current method
-// Line: 17
+// Line: 13
using System;
using System.Reflection;
-/// <summary>
-/// MS does not report CS0177 for structs:
-/// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=304489
-/// </summary>
class Program
{
bool GetArgsForCall (object [] originalArgs, out ParameterModifier parameterModifiers)
# all the following are from bug #628673
cs1979.cs
cs0168-2.cs
-cs0177-8.cs NO ERROR
cs0647-14.cs NO ERROR
cs1612-6.cs NO ERROR
cs3006-7.cs NO ERROR
if ((member.Modifiers & Modifiers.OVERRIDE) != 0 && member.Kind != MemberKind.Event)
continue;
+ if ((member.Modifiers & Modifiers.BACKING_FIELD) != 0)
+ continue;
+
if ((arity > 0 || (restrictions & MemberLookupRestrictions.ExactArity) != 0) && member.Arity != arity)
continue;
spec = new FieldSpec (Parent.Definition, this, MemberType, FieldBuilder, ModFlags);
- // Don't cache inaccessible fields
- if ((ModFlags & Modifiers.BACKING_FIELD) == 0) {
+ //
+ // Don't cache inaccessible fields except for struct where we
+ // need them for definitive assignment checks
+ //
+ if ((ModFlags & Modifiers.BACKING_FIELD) == 0 || Parent.Kind == MemberKind.Struct) {
Parent.MemberCache.AddMember (spec);
}
}
}
-/*
- if ((ModFlags & (Modifiers.STATIC | Modifiers.READONLY | Modifiers.COMPILER_GENERATED)) == Modifiers.STATIC)
- Console.WriteLine ("{0}: {1}", Location.ToString (), GetSignatureForError ());
-*/
return true;
}
Type, Offset, Length, TotalLength);
}
- class StructInfo {
+ class StructInfo
+ {
public readonly TypeSpec Type;
- public readonly FieldSpec[] Fields;
+ readonly List<FieldSpec> fields;
public readonly TypeInfo[] StructFields;
- public readonly int Count;
- public readonly int CountPublic;
- public readonly int CountNonPublic;
public readonly int Length;
public readonly int TotalLength;
- public readonly bool HasStructFields;
public static Dictionary<TypeSpec, StructInfo> field_type_hash;
private Dictionary<string, TypeInfo> struct_field_hash;
private Dictionary<string, int> field_hash;
- protected bool InTransit = false;
+ protected bool InTransit;
// Private constructor. To save memory usage, we only need to create one instance
// of this class per struct type.
field_type_hash.Add (type, this);
- TypeContainer tc = type.MemberDefinition as TypeContainer;
-
- var public_fields = new List<FieldSpec> ();
- var non_public_fields = new List<FieldSpec> ();
-
- if (tc != null) {
- var fields = tc.Fields;
-
- if (fields != null) {
- foreach (FieldBase field in fields) {
- if ((field.ModFlags & Modifiers.STATIC) != 0)
- continue;
-
- //
- // Fixed size buffers are not subject to definite assignment checking
- //
- if (field is FixedField)
- continue;
-
- if ((field.ModFlags & Modifiers.PUBLIC) != 0)
- public_fields.Add (field.Spec);
- else
- non_public_fields.Add (field.Spec);
- }
- }
- }
-
- CountPublic = public_fields.Count;
- CountNonPublic = non_public_fields.Count;
- Count = CountPublic + CountNonPublic;
-
- Fields = new FieldSpec[Count];
- public_fields.CopyTo (Fields, 0);
- non_public_fields.CopyTo (Fields, CountPublic);
+ fields = MemberCache.GetAllFieldsForDefiniteAssignment (type);
struct_field_hash = new Dictionary<string, TypeInfo> ();
- field_hash = new Dictionary<string, int> ();
+ field_hash = new Dictionary<string, int> (fields.Count);
- Length = 0;
- StructFields = new TypeInfo [Count];
- StructInfo[] sinfo = new StructInfo [Count];
+ StructFields = new TypeInfo[fields.Count];
+ StructInfo[] sinfo = new StructInfo[fields.Count];
InTransit = true;
- for (int i = 0; i < Count; i++) {
- var field = Fields [i];
+ for (int i = 0; i < fields.Count; i++) {
+ var field = fields [i];
sinfo [i] = GetStructInfo (field.MemberType);
if (sinfo [i] == null)
InTransit = false;
TotalLength = Length + 1;
- for (int i = 0; i < Count; i++) {
- var field = Fields [i];
+ for (int i = 0; i < fields.Count; i++) {
+ var field = fields [i];
if (sinfo [i] == null)
continue;
field_hash.Add (field.Name, TotalLength);
- HasStructFields = true;
StructFields [i] = new TypeInfo (sinfo [i], TotalLength);
struct_field_hash.Add (field.Name, StructFields [i]);
TotalLength += sinfo [i].TotalLength;
}
}
+ public int Count {
+ get {
+ return fields.Count;
+ }
+ }
+
+ public List<FieldSpec> Fields {
+ get {
+ return fields;
+ }
+ }
+
public int this [string name] {
get {
int val;
break;
default:
// Ignore private fields (even for error reporting) to not require extra dependencies
- if (IgnorePrivateMembers || HasAttribute (CustomAttributeData.GetCustomAttributes (fi), "CompilerGeneratedAttribute", CompilerServicesNamespace))
+ if ((IgnorePrivateMembers && !declaringType.IsStruct) ||
+ HasAttribute (CustomAttributeData.GetCustomAttributes (fi), "CompilerGeneratedAttribute", CompilerServicesNamespace))
return null;
mod = Modifiers.PRIVATE;
throw new NotImplementedException (member.GetType ().ToString ());
}
+ public static List<FieldSpec> GetAllFieldsForDefiniteAssignment (TypeSpec container)
+ {
+ List<FieldSpec> fields = null;
+ foreach (var entry in container.MemberCache.member_hash) {
+ foreach (var name_entry in entry.Value) {
+ if (name_entry.Kind != MemberKind.Field)
+ continue;
+
+ if ((name_entry.Modifiers & Modifiers.STATIC) != 0)
+ continue;
+
+ //
+ // Fixed size buffers are not subject to definite assignment checking
+ //
+ if (name_entry is FixedFieldSpec || name_entry is ConstSpec)
+ continue;
+
+ var fs = (FieldSpec) name_entry;
+
+ //
+ // LAMESPEC: Very bizzare hack, definitive assignment is not done
+ // for imported non-public reference fields except array. No idea what the
+ // actual csc rule is
+ //
+ if (!fs.IsPublic && container.MemberDefinition.IsImported && (!fs.MemberType.IsArray && TypeSpec.IsReferenceType (fs.MemberType)))
+ continue;
+
+ if (fields == null)
+ fields = new List<FieldSpec> ();
+
+ fields.Add (fs);
+ break;
+ }
+ }
+
+ return fields ?? new List<FieldSpec> (0);
+ }
+
public static IList<MemberSpec> GetCompletitionMembers (IMemberContext ctx, TypeSpec container, string name)
{
var matches = new List<MemberSpec> ();
{
public static void Main ()
{
- DateTime junk;
+ DateTime junk = DateTime.Today;
var results = from item in "abcd"
let parsed = DateTime.TryParse ("today", out junk)
select parsed ? junk : DateTime.Now;
--- /dev/null
+// Compiler options: -t:library
+
+public struct S
+{
+ string s;
+
+ public void Test ()
+ {
+ }
+}
--- /dev/null
+// Compiler options: -r:test-827-lib.dll
+
+// Only to check we are compatible with broken csc definite assignment implementation
+
+class Program
+{
+ static void Main ()
+ {
+ S s;
+ s.Test ();
+ }
+}
<test name="gtest-linq-22.cs">
<type name="Test.MainClass">
<method name="Void Main()">
- <size>47</size>
+ <size>58</size>
</method>
<method name="Void .ctor()">
<size>7</size>
</method>
</type>
</test>
+ <test name="test-827.cs">
+ <type name="Program">
+ <method name="Void Main()">
+ <size>8</size>
+ </method>
+ <method name="Void .ctor()">
+ <size>7</size>
+ </method>
+ </type>
+ </test>
<test name="test-83.cs">
<type name="PersonArrivedArgs">
<method name="Void .ctor(String)">