--- /dev/null
+// CS0121: The call is ambiguous between the following methods or properties: `D.Test(bool, string)' and `D.Test(bool, int, string)'
+// Line: 16
+
+public class D
+{
+ static void Test (bool b, string a = "s")
+ {
+ }
+
+ static void Test (bool b, int i = 9, string a = "b")
+ {
+ }
+
+ public static void Main ()
+ {
+ Test (false);
+ }
+}
// CS0121: The call is ambiguous between the following methods or properties: `C.Foo(byte)' and `C.Foo(int)'
// Line: 18
-// Compiler options: -langversion:future
class C
{
--- /dev/null
+// CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression
+// Line: 13
+
+using System;
+
+class MyAttribute : Attribute
+{
+ public MyAttribute (object s)
+ {
+ }
+}
+
+[My (decimal.MaxValue)]
+class X
+{
+}
-// cs0617-2.cs: `foo3' is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, const or read-write properties which are public and not static
+// CS0617: `foo3' is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, const or read-write properties which are public and not static
// Line: 11
class BazAttribute : System.Attribute
--- /dev/null
+// CS0617: `Foo' is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, const or read-write properties which are public and not static
+// Line: 11
+
+using System;
+
+public sealed class FooAttribute : Attribute
+{
+ internal int Foo;
+}
+
+[Foo (Foo = 1)]
+public class Tests
+{
+}
--- /dev/null
+// CS0617: `Foo' is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, const or read-write properties which are public and not static
+// Line: 11
+
+using System;
+
+public sealed class FooAttribute : Attribute
+{
+ public short Foo { get; private set; }
+}
+
+[Foo (Foo = 1)]
+public class Tests
+{
+}
-// cs0617.cs: `MyNamedArg' is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, const or read-write properties which are public and not static
-// Line : 20
+// CS0617: `MyNamedArg' is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, const or read-write properties which are public and not static
+// Line : 19
using System;
[AttributeUsage (AttributeTargets.Class, AllowMultiple = true)]
- public class SimpleAttribute : Attribute {
+public class SimpleAttribute : Attribute
+{
+ string name;
- string name = null;
-
- public readonly string MyNamedArg;
-
- public SimpleAttribute (string name)
- {
- this.name = name;
- }
+ public readonly string MyNamedArg;
+ public SimpleAttribute (string name)
+ {
+ this.name = name;
}
+}
[Simple ("Dummy", MyNamedArg = "Dude!")]
- public class Blah {
+public class Blah {
- public static void Main ()
- {
- }
+ public static void Main ()
+ {
}
+}
+++ /dev/null
-// CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression
-// Line: 13
-
-using System;
-
-class AAttribute : Attribute
-{
- public AAttribute (dynamic X)
- {
- }
-}
-
-[A (Test.B)]
-class Test
-{
- public static dynamic B;
-
- static void Main ()
- {
- }
-}
--- /dev/null
+// CS01982: An attribute argument cannot be dynamic expression
+// Line: 6
+
+using System;
+
+[A((dynamic) null)]
+public class A : Attribute
+{
+ public A (Type arg)
+ {
+ }
+}
--- /dev/null
+// CS01982: An attribute argument cannot be dynamic expression
+// Line: 6
+
+using System;
+
+[A(typeof (dynamic[]))]
+public class A : Attribute
+{
+ public A (object arg)
+ {
+ }
+}
--- /dev/null
+// CS01982: An attribute argument cannot be dynamic expression
+// Line: 6
+
+using System;
+
+[A(new dynamic [] { 8 })]
+public class A : Attribute
+{
+ public A (object arg)
+ {
+ }
+}
--- /dev/null
+// CS01982: An attribute argument cannot be dynamic expression
+// Line: 6
+
+using System;
+
+[A(typeof (Func<dynamic>))]
+public class A : Attribute
+{
+ public A (Type arg)
+ {
+ }
+}
--- /dev/null
+// CS1982: An attribute argument cannot be dynamic expression
+// Line: 13
+
+using System;
+
+class AAttribute : Attribute
+{
+ public AAttribute (dynamic X)
+ {
+ }
+}
+
+[A (Test.B)]
+class Test
+{
+ public static dynamic B;
+
+ static void Main ()
+ {
+ }
+}
name.Name);
}
- public static void Error_AttributeArgumentNotValid (IMemberContext rc, Location loc)
+ public static void Error_AttributeArgumentIsDynamic (IMemberContext context, Location loc)
{
- rc.Compiler.Report.Error (182, loc,
- "An attribute argument must be a constant expression, typeof " +
- "expression or array creation expression");
+ context.Compiler.Report.Error (1982, loc, "An attribute argument cannot be dynamic expression");
}
public void Error_MissingGuidAttribute ()
bool dynamic;
PosArguments.Resolve (ec, out dynamic);
if (dynamic) {
- Error_AttributeArgumentNotValid (ec, loc);
+ Error_AttributeArgumentIsDynamic (ec.MemberContext, loc);
return null;
}
}
if (member is PropertyExpr) {
var pi = ((PropertyExpr) member).PropertyInfo;
- if (!pi.HasSet || !pi.HasGet || pi.IsStatic) {
+ if (!pi.HasSet || !pi.HasGet || pi.IsStatic || !pi.Get.IsPublic || !pi.Set.IsPublic) {
ec.Report.SymbolRelatedToPreviousError (pi);
Error_InvalidNamedArgument (ec, a);
return false;
} else {
var fi = ((FieldExpr) member).Spec;
- if (fi.IsReadOnly || fi.IsStatic) {
+ if (fi.IsReadOnly || fi.IsStatic || !fi.IsPublic) {
Error_InvalidNamedArgument (ec, a);
return false;
}
var param_types = ctor.Parameters.Types;
for (int j = 0; j < PosArguments.Count; ++j) {
var pt = param_types[j];
- if (!IsValidArgumentType (pt)) {
- Error_AttributeArgumentNotValid (context, loc);
- return;
- }
-
var arg_expr = PosArguments[j].Expr;
if (j == 0) {
if (Type == predefined.IndexerName || Type == predefined.Conditional) {
public struct AttributeEncoder
{
+ [Flags]
+ public enum EncodedTypeProperties
+ {
+ None = 0,
+ DynamicType = 1,
+ TypeParameter = 1 << 1
+ }
+
public readonly BinaryWriter Stream;
public AttributeEncoder (bool empty)
Stream.Write (buf);
}
- public void Encode (TypeSpec type)
+ public EncodedTypeProperties Encode (TypeSpec type)
{
if (type == TypeManager.bool_type) {
Stream.Write ((byte) 0x02);
EncodeTypeName (type);
} else if (type.IsArray) {
Stream.Write ((byte) 0x1D);
- Encode (TypeManager.GetElementType (type));
- } else {
- throw new NotImplementedException (type.ToString ());
+ return Encode (TypeManager.GetElementType (type));
+ } else if (type == InternalType.Dynamic) {
+ Stream.Write ((byte) 0x51);
+ return EncodedTypeProperties.DynamicType;
}
+
+ return EncodedTypeProperties.None;
}
public void EncodeTypeName (TypeSpec type)
var ac = targetType as ArrayContainer;
if (ac != null) {
- if (ac.Rank != 1)
+ if (ac.Rank != 1 || ac.Element.IsArray)
base.EncodeAttributeValue (rc, enc, targetType);
else
enc.Stream.Write (uint.MaxValue);
public virtual void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- Attribute.Error_AttributeArgumentNotValid (rc, loc);
+ rc.Compiler.Report.Error (182, loc,
+ "An attribute argument must be a constant expression, typeof expression or array creation expression");
}
/// <summary>
return;
}
- enc.Encode (type);
+ if (enc.Encode (type) == AttributeEncoder.EncodedTypeProperties.DynamicType) {
+ Attribute.Error_AttributeArgumentIsDynamic (rc, loc);
+ return;
+ }
}
// Single dimensional array of 0 size
return this;
}
+ static bool ContainsDynamicType (TypeSpec type)
+ {
+ if (type == InternalType.Dynamic)
+ return true;
+
+ var element_container = type as ElementTypeSpec;
+ if (element_container != null)
+ return ContainsDynamicType (element_container.Element);
+
+ foreach (var t in type.TypeArguments) {
+ if (ContainsDynamicType (t)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
static bool ContainsTypeParameter (TypeSpec type)
{
if (type.Kind == MemberKind.TypeParameter)
if (ContainsTypeParameter (typearg)) {
rc.Compiler.Report.Error (416, loc, "`{0}': an attribute argument cannot use type parameters",
- TypeManager.CSharpName (typearg));
+ typearg.GetSignatureForError ());
+ return;
+ }
+
+ if (ContainsDynamicType (typearg)) {
+ Attribute.Error_AttributeArgumentIsDynamic (rc, loc);
return;
}
if (mc != null) {
SymbolRelatedToPreviousError (mc);
- } else {
+ } else if (ms.MemberDefinition != null) {
SymbolRelatedToPreviousError (ms.MemberDefinition.Assembly.Location, "");
}
}