Don't define _XOPEN_SOURCE on OpenBSD.
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml;
using System.Xml.Schema;
+using System.Xml.Serialization;
using QName = System.Xml.XmlQualifiedName;
{
Type rootType = type;
+ if (IsAny())
+ return;
+
if (root_name.Value == "")
throw new InvalidDataContractException ("Type '" + type.ToString () +
"' cannot have a DataContract attribute Name set to null or empty string.");
-
if (graph == null) {
if (names_filled)
writer.WriteStartElement (root_name.Value, root_ns.Value);
public override void WriteEndObject (XmlDictionaryWriter writer)
{
+ if (IsAny())
+ return;
+
writer.WriteEndElement ();
}
get { throw new NotImplementedException (); }
}
#endif
+
+ private bool IsAny() {
+ var xpa = type.GetCustomAttribute<XmlSchemaProviderAttribute> (true);
+ return xpa.IsAny;
+ }
}
}
+System.Runtime.Serialization/Bug11916Test.cs
System.Runtime.Serialization/Bug666333Test.cs
System.Runtime.Serialization/Bug675144Test.cs
System.Runtime.Serialization/Bug2843Test.cs
--- /dev/null
+using System;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
+using System.Text;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Runtime.Serialization
+{
+
+ [XmlSchemaProvider(null, IsAny = true)]
+ public class TestElement : IXmlSerializable
+ {
+ public string Value { get; set; }
+
+ void IXmlSerializable.WriteXml(XmlWriter writer)
+ {
+ writer.WriteElementString("dummy", Value);
+ }
+
+ void IXmlSerializable.ReadXml(XmlReader reader)
+ {
+ Value = reader.ReadElementString("dummy");
+ }
+
+ XmlSchema IXmlSerializable.GetSchema()
+ {
+ return null;
+ }
+ }
+
+
+ [TestFixture]
+ public class Bug11916Test
+ {
+ [Test]
+ public void TestIsAnyTrueDataContractSerializer()
+ {
+ TestElement element = new TestElement();
+ element.Value = "bar";
+
+ StringBuilder stringBuilder = new StringBuilder ();
+
+ DataContractSerializer ser = new DataContractSerializer (typeof (TestElement));
+
+ using (var xw = XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (new StringWriter (stringBuilder))))
+ {
+ ser.WriteObject(xw, element);
+ }
+
+ string actualXml = stringBuilder.ToString ();
+ string expectedXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?><dummy>bar</dummy>";
+
+ Assert.AreEqual (expectedXml, actualXml, "#1 IsAny=true DataContractSerializer");
+ }
+ }
+}
return true;
// LAMESPEC
- if (!bypassOnLocal) {
+ if (bypassOnLocal) {
if (String.Compare (server, "localhost", true, CultureInfo.InvariantCulture) == 0)
return true;
if (String.Compare (server, "loopback", true, CultureInfo.InvariantCulture) == 0)
}
if (socket != null) {
if (socket.State == WebSocketState.Open)
- socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait ();
+ socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait (2000);
socket.Dispose ();
socket = null;
}
{
HandleHttpRequestAsync ((req, resp) => resp.StatusCode = 418);
try {
- socket.ConnectAsync (new Uri ("ws://localhost:" + Port), CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri ("ws://localhost:" + Port), CancellationToken.None).Wait (5000));
} catch (AggregateException e) {
AssertWebSocketException (e, WebSocketError.Success, typeof (WebException));
return;
resp.Headers["Upgrade"] = "gtfo";
});
try {
- socket.ConnectAsync (new Uri ("ws://localhost:" + Port), CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri ("ws://localhost:" + Port), CancellationToken.None).Wait (5000));
} catch (AggregateException e) {
AssertWebSocketException (e, WebSocketError.Success);
return;
//ForceSetHeader (resp.Headers, "Connection", "Foo");
});
try {
- socket.ConnectAsync (new Uri ("ws://localhost:" + Port), CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri ("ws://localhost:" + Port), CancellationToken.None).Wait (5000));
} catch (AggregateException e) {
AssertWebSocketException (e, WebSocketError.Success);
return;
Assert.AreEqual (WebSocketState.Open, socket.State);
var sendBuffer = Encoding.ASCII.GetBytes (Payload);
- socket.SendAsync (new ArraySegment<byte> (sendBuffer), WebSocketMessageType.Text, true, CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.SendAsync (new ArraySegment<byte> (sendBuffer), WebSocketMessageType.Text, true, CancellationToken.None).Wait (5000));
var receiveBuffer = new byte[Payload.Length];
var resp = socket.ReceiveAsync (new ArraySegment<byte> (receiveBuffer), CancellationToken.None).Result;
Assert.AreEqual (WebSocketMessageType.Text, resp.MessageType);
Assert.AreEqual (Payload, Encoding.ASCII.GetString (receiveBuffer, 0, resp.Count));
- socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait (5000));
Assert.AreEqual (WebSocketState.Closed, socket.State);
}
[Test]
public void CloseOutputAsyncTest ()
{
- socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
Assert.AreEqual (WebSocketState.Open, socket.State);
- socket.CloseOutputAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.CloseOutputAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait (5000));
Assert.AreEqual (WebSocketState.CloseSent, socket.State);
var resp = socket.ReceiveAsync (new ArraySegment<byte> (new byte[0]), CancellationToken.None).Result;
[Test]
public void CloseAsyncTest ()
{
- socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
Assert.AreEqual (WebSocketState.Open, socket.State);
- socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait (5000));
Assert.AreEqual (WebSocketState.Closed, socket.State);
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void SendAsyncArgTest_NoArray ()
{
- socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
socket.SendAsync (new ArraySegment<byte> (), WebSocketMessageType.Text, true, CancellationToken.None);
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void ReceiveAsyncArgTest_NoArray ()
{
- socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
socket.ReceiveAsync (new ArraySegment<byte> (), CancellationToken.None);
}
public void ReceiveAsyncWrongState_Closed ()
{
try {
- socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait ();
- socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait ();
- socket.ReceiveAsync (new ArraySegment<byte> (new byte[0]), CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
+ Assert.IsTrue (socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait (5000));
+ Assert.IsTrue (socket.ReceiveAsync (new ArraySegment<byte> (new byte[0]), CancellationToken.None).Wait (5000));
} catch (AggregateException e) {
AssertWebSocketException (e, WebSocketError.Success);
return;
public void SendAsyncWrongState_Closed ()
{
try {
- socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait ();
- socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait ();
- socket.SendAsync (new ArraySegment<byte> (new byte[0]), WebSocketMessageType.Text, true, CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
+ Assert.IsTrue (socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait (5000));
+ Assert.IsTrue (socket.SendAsync (new ArraySegment<byte> (new byte[0]), WebSocketMessageType.Text, true, CancellationToken.None).Wait (5000));
} catch (AggregateException e) {
AssertWebSocketException (e, WebSocketError.Success);
return;
public void SendAsyncWrongState_CloseSent ()
{
try {
- socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait ();
- socket.CloseOutputAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait ();
- socket.SendAsync (new ArraySegment<byte> (new byte[0]), WebSocketMessageType.Text, true, CancellationToken.None).Wait ();
+ Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
+ Assert.IsTrue (socket.CloseOutputAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait (5000));
+ Assert.IsTrue (socket.SendAsync (new ArraySegment<byte> (new byte[0]), WebSocketMessageType.Text, true, CancellationToken.None).Wait (5000));
} catch (AggregateException e) {
AssertWebSocketException (e, WebSocketError.Success);
return;
--- /dev/null
+// CS0455: Type parameter `T3' inherits conflicting constraints `X' and `Y'
+// Line: 15
+
+class X
+{
+}
+
+class Y
+{
+}
+
+class C<T1, T2, T3, T4>
+ where T1 : X
+ where T2 : T1
+ where T3 : Y, T4
+ where T4 : T2
+{
+}
\ No newline at end of file
iface_found = true;
continue;
}
-
-
+
var constraint_tp = type as TypeParameterSpec;
if (constraint_tp != null) {
if (tparam_types == null) {
}
}
+ if (constraint_tp.TypeArguments != null) {
+ var eb = constraint_tp.GetEffectiveBase ();
+ if (eb != null && !CheckConflictingInheritedConstraint (spec, eb, spec.BaseType, context, constraint.Location))
+ break;
+ }
+
if (constraint_tp.HasSpecialStruct) {
context.Module.Compiler.Report.Error (456, constraint.Location,
"Type parameter `{0}' has the `struct' constraint, so it cannot be used as a constraint for `{1}'",
int tp_pos;
TypeSpec[] targs;
TypeSpec[] ifaces_defined;
+ TypeSpec effective_base;
//
// Creates type owned type parameter
return BaseType.IsStruct ? BaseType.BaseType : BaseType;
}
- var types = targs;
- if (HasTypeConstraint) {
- Array.Resize (ref types, types.Length + 1);
+ if (effective_base != null)
+ return effective_base;
+
+ var types = new TypeSpec [HasTypeConstraint ? targs.Length + 1 : targs.Length];
+
+ for (int i = 0; i < targs.Length; ++i) {
+ var t = targs [i];
- for (int i = 0; i < types.Length - 1; ++i) {
- types[i] = types[i].BaseType;
+ // Same issue as above, inherited constraints can be of struct type
+ if (t.IsStruct) {
+ types [i] = t.BaseType;
+ continue;
}
- types[types.Length - 1] = BaseType;
- } else {
- types = types.Select (l => l.BaseType).ToArray ();
+ types [i] = ((TypeParameterSpec)t).GetEffectiveBase ();
}
- if (types != null)
- return Convert.FindMostEncompassedType (types);
+ if (HasTypeConstraint)
+ types [types.Length - 1] = BaseType;
- return BaseType;
+ return effective_base = Convert.FindMostEncompassedType (types);
}
public override string GetSignatureForDocumentation ()
if (targs != null) {
foreach (var ta in targs) {
- var b_type = ta.BaseType;
- if (b_type.BuiltinType != BuiltinTypeSpec.Type.Object && b_type.BuiltinType != BuiltinTypeSpec.Type.ValueType)
- cache.AddBaseType (b_type);
-
var tps = ta as TypeParameterSpec;
- var ifaces = tps != null ? tps.InterfacesDefined : ta.Interfaces;
+ IList<TypeSpec> ifaces;
+ if (tps != null) {
+ var b_type = tps.GetEffectiveBase ();
+ if (b_type != null && b_type.BuiltinType != BuiltinTypeSpec.Type.Object && b_type.BuiltinType != BuiltinTypeSpec.Type.ValueType)
+ cache.AddBaseType (b_type);
+
+ ifaces = tps.InterfacesDefined;
+ } else {
+ ifaces = ta.Interfaces;
+ }
if (ifaces != null) {
foreach (var iface_type in ifaces) {
}
for (int i = 0; i < tparams.Count; ++i) {
- var tp = tparams[i];
+ var tp = tparams [i];
- if (!tp.ResolveConstraints (this))
+ if (base_tparams == null) {
+ tp.ResolveConstraints (this);
continue;
+ }
//
// Copy base constraints for override/explicit methods
//
- if (base_tparams != null) {
- var base_tparam = base_tparams[i];
- var local_tparam = tp.Type;
- local_tparam.SpecialConstraint = base_tparam.SpecialConstraint;
-
- var inflator = new TypeParameterInflator (this, CurrentType, base_decl_tparams, base_targs);
- base_tparam.InflateConstraints (inflator, local_tparam);
+ var base_tparam = base_tparams [i];
+ var local_tparam = tp.Type;
+ local_tparam.SpecialConstraint = base_tparam.SpecialConstraint;
- //
- // Check all type argument constraints for possible collision or unification
- // introduced by inflating inherited constraints in this context
- //
- // Conflict example:
- //
- // class A<T> { virtual void Foo<U> () where U : class, T {} }
- // class B : A<int> { override void Foo<U> {} }
- //
- var local_tparam_targs = local_tparam.TypeArguments;
- if (local_tparam_targs != null) {
- for (int ii = 0; ii < local_tparam_targs.Length; ++ii) {
- var ta = local_tparam_targs [ii];
- if (!ta.IsClass && !ta.IsStruct)
- continue;
-
- TypeSpec[] unique_tparams = null;
- for (int iii = ii + 1; iii < local_tparam_targs.Length; ++iii) {
- //
- // Remove any identical or unified constraint types
- //
- var tparam_checked = local_tparam_targs[iii];
- if (TypeSpecComparer.IsEqual (ta, tparam_checked) || TypeSpec.IsBaseClass (ta, tparam_checked, false)) {
- unique_tparams = new TypeSpec[local_tparam_targs.Length - 1];
- Array.Copy (local_tparam_targs, 0, unique_tparams, 0, iii);
- Array.Copy (local_tparam_targs, iii + 1, unique_tparams, iii, local_tparam_targs.Length - iii - 1);
- } else if (!TypeSpec.IsBaseClass (tparam_checked, ta, false)) {
- Constraints.Error_ConflictingConstraints (this, local_tparam, ta, tparam_checked, Location);
- }
- }
+ var inflator = new TypeParameterInflator (this, CurrentType, base_decl_tparams, base_targs);
+ base_tparam.InflateConstraints (inflator, local_tparam);
- if (unique_tparams != null) {
- local_tparam_targs = unique_tparams;
- local_tparam.TypeArguments = local_tparam_targs;
- continue;
+ //
+ // Check all type argument constraints for possible collision or unification
+ // introduced by inflating inherited constraints in this context
+ //
+ // Conflict example:
+ //
+ // class A<T> { virtual void Foo<U> () where U : class, T {} }
+ // class B : A<int> { override void Foo<U> {} }
+ //
+ var local_tparam_targs = local_tparam.TypeArguments;
+ if (local_tparam_targs != null) {
+ for (int ii = 0; ii < local_tparam_targs.Length; ++ii) {
+ var ta = local_tparam_targs [ii];
+ if (!ta.IsClass && !ta.IsStruct)
+ continue;
+
+ TypeSpec[] unique_tparams = null;
+ for (int iii = ii + 1; iii < local_tparam_targs.Length; ++iii) {
+ //
+ // Remove any identical or unified constraint types
+ //
+ var tparam_checked = local_tparam_targs [iii];
+ if (TypeSpecComparer.IsEqual (ta, tparam_checked) || TypeSpec.IsBaseClass (ta, tparam_checked, false)) {
+ unique_tparams = new TypeSpec[local_tparam_targs.Length - 1];
+ Array.Copy (local_tparam_targs, 0, unique_tparams, 0, iii);
+ Array.Copy (local_tparam_targs, iii + 1, unique_tparams, iii, local_tparam_targs.Length - iii - 1);
+ } else if (!TypeSpec.IsBaseClass (tparam_checked, ta, false)) {
+ Constraints.Error_ConflictingConstraints (this, local_tparam, ta, tparam_checked, Location);
}
+ }
- Constraints.CheckConflictingInheritedConstraint (local_tparam, ta, this, Location);
+ if (unique_tparams != null) {
+ local_tparam_targs = unique_tparams;
+ local_tparam.TypeArguments = local_tparam_targs;
+ continue;
}
+
+ Constraints.CheckConflictingInheritedConstraint (local_tparam, ta, this, Location);
}
}
}
--- /dev/null
+class X
+{
+ public static void Foo (X x1)
+ {
+ }
+
+ public static void Main ()
+ {
+ C<X, X, X>.Test (new X ());
+ }
+
+ public int Prop {
+ get {
+ return 5;
+ }
+ }
+}
+
+class Y
+{
+}
+
+class C<T1, T2, T3>
+ where T1 : X
+ where T2 : T1
+ where T3 : T2
+{
+ public static void Test (T3 t3)
+ {
+ X.Foo (t3);
+ var g = t3.Prop;
+ }
+}
\ No newline at end of file
</method>\r
</type>\r
</test>\r
+ <test name="gtest-613.cs">\r
+ <type name="X">\r
+ <method name="Void Foo(X)" attrs="150">\r
+ <size>2</size>\r
+ </method>\r
+ <method name="Void Main()" attrs="150">\r
+ <size>12</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ <type name="Y">\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ <type name="C`3[T1,T2,T3]">\r
+ <method name="Void Test(T3)" attrs="150">\r
+ <size>27</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ <type name="X">\r
+ <method name="Int32 get_Prop()" attrs="2182">\r
+ <size>10</size>\r
+ </method>\r
+ </type>\r
+ </test>\r
<test name="gtest-anontype-01.cs">\r
<type name="Test">\r
<method name="Int32 Main()" attrs="150">\r