public int AnonymousMethodsCounter;
public int MethodGroupsCounter;
- static readonly string[] attribute_targets = new string[] { "type" };
+ static readonly string[] attribute_targets = new [] { "type" };
+ static readonly string[] attribute_targets_primary = new [] { "type", "method" };
/// <remarks>
/// The pending methods that need to be implemented
public override string[] ValidAttributeTargets {
get {
- return attribute_targets;
+ return PrimaryConstructorParameters != null ? attribute_targets_primary : attribute_targets;
}
}
if (symbol is TypeParameter) {
Report.Error (692, symbol.Location,
"Duplicate type parameter `{0}'", symbol.GetSignatureForError ());
- } else if (symbol is PrimaryConstructorField && mc is TypeParameter) {
- Report.Error (8038, symbol.Location, "Primary constructor of type `{0}' has parameter of same name as type parameter `{1}'",
- symbol.Parent.GetSignatureForError (), symbol.GetSignatureForError ());
} else {
Report.Error (102, symbol.Location,
"The type `{0}' already contains a definition for `{1}'",
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
+ if (a.Target == AttributeTargets.Method) {
+ foreach (var m in members) {
+ var c = m as Constructor;
+ if (c == null)
+ continue;
+
+ if (c.IsPrimaryConstructor) {
+ c.ApplyAttributeBuilder (a, ctor, cdata, pa);
+ return;
+ }
+ }
+
+ throw new InternalErrorException ();
+ }
+
if (has_normal_indexers && a.Type == pa.DefaultMember) {
Report.Error (646, a.Location, "Cannot specify the `DefaultMember' attribute on type containing an indexer");
return;
// defined after current container
//
if (class_partial_parts != null) {
- foreach (var pp in class_partial_parts)
+ foreach (var pp in class_partial_parts) {
+ if (pp.PrimaryConstructorBaseArguments != null)
+ PrimaryConstructorBaseArguments = pp.PrimaryConstructorBaseArguments;
+
pp.DoDefineBaseType ();
+ }
}
{
}
+ public ToplevelBlock PrimaryConstructorBlock { get; set; }
+
protected override TypeAttributes TypeAttr {
get {
TypeAttributes ta = base.TypeAttr;
return;
}
- if (symbol is PrimaryConstructorField) {
- Report.Error (8039, symbol.Location, "Primary constructor of type `{0}' has parameter of same name as containing type",
- symbol.Parent.GetSignatureForError ());
- return;
- }
-
InterfaceMemberBase imb = symbol as InterfaceMemberBase;
if (imb == null || !imb.IsExplicitImpl) {
Report.SymbolRelatedToPreviousError (this);
c.IsPrimaryConstructor = true;
AddConstructor (c, true);
- c.Block = new ToplevelBlock (Compiler, c.ParameterInfo, Location) {
- IsCompilerGenerated = true
- };
+ if (PrimaryConstructorBlock == null) {
+ c.Block = new ToplevelBlock (Compiler, parameters, Location) {
+ IsCompilerGenerated = true
+ };
+ } else {
+ c.Block = PrimaryConstructorBlock;
+ }
return c;
}
if (PrimaryConstructorParameters != null) {
foreach (Parameter p in PrimaryConstructorParameters.FixedParameters) {
- if ((p.ModFlags & Parameter.Modifier.RefOutMask) != 0)
- continue;
-
- var f = new PrimaryConstructorField (this, p);
- AddField (f);
+ if (p.Name == MemberName.Name) {
+ Report.Error (8039, p.Location, "Primary constructor of type `{0}' has parameter of same name as containing type",
+ GetSignatureForError ());
+ }
- generated_primary_constructor.Block.AddStatement (
- new StatementExpression (new PrimaryConstructorAssign (f, p), p.Location));
+ if (CurrentTypeParameters != null) {
+ for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
+ var tp = CurrentTypeParameters [i];
+ if (p.Name == tp.Name) {
+ Report.Error (8038, p.Location, "Primary constructor of type `{0}' has parameter of same name as type parameter `{1}'",
+ GetSignatureForError (), p.GetSignatureForError ());
+ }
+ }
+ }
}
}