public SymbolRelatedToPreviousError ( Mono.CSharp.Location loc, string symbol ) : void | ||
loc | Mono.CSharp.Location | |
symbol | string | |
return | void |
protected override bool CheckBase () { if (!base.CheckBase ()) return false; MemberSpec candidate; bool overrides = false; var conflict_symbol = MemberCache.FindBaseMember (this, out candidate, ref overrides); if (conflict_symbol == null) conflict_symbol = candidate; if (conflict_symbol == null) { if ((ModFlags & Modifiers.NEW) != 0) { Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ()); } } else { if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.BACKING_FIELD)) == 0) { Report.SymbolRelatedToPreviousError (conflict_symbol); Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended", GetSignatureForError (), conflict_symbol.GetSignatureForError ()); } if (conflict_symbol.IsAbstract) { Report.SymbolRelatedToPreviousError (conflict_symbol); Report.Error (533, Location, "`{0}' hides inherited abstract member `{1}'", GetSignatureForError (), conflict_symbol.GetSignatureForError ()); } } return true; }
public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Target == AttributeTargets.Assembly) { assembly.ApplyAttributeBuilder(a, ctor, cdata, pa); return; } if (a.Type == pa.CLSCompliant) { Attribute cls = DeclaringAssembly.CLSCompliantAttribute; if (cls == null) { Report.Warning(3012, 1, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking"); } else if (DeclaringAssembly.IsCLSCompliant != a.GetBoolean()) { Report.SymbolRelatedToPreviousError(cls.Location, cls.GetSignatureForError()); Report.Warning(3017, 1, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly"); return; } } builder.SetCustomAttribute((ConstructorInfo)ctor.GetMetaInfo(), cdata); }
public override FullNamedExpression Resolve(IResolveContext rc) { if (resolved != null || value == null) { return(resolved); } resolved = value.GetTypeExpression().ResolveAsTypeStep(rc, false); if (resolved == null) { value = null; return(null); } TypeExpr te = resolved as TypeExpr; if (te != null) { if (!te.CheckAccessLevel(rc.DeclContainer)) { Report.SymbolRelatedToPreviousError(te.Type); Expression.ErrorIsInaccesible(resolved.Location, resolved.GetSignatureForError()); } } return(resolved); }
void Error_ConversionFailed(EmitContext ec, MethodBase method, Expression return_type) { MethodInfo invoke_method = Delegate.GetInvokeMethod(ec.ContainerType, type); string member_name = delegate_instance_expression != null? Delegate.FullDelegateDesc(method) : TypeManager.GetFullNameSignature(method); Report.SymbolRelatedToPreviousError(type); Report.SymbolRelatedToPreviousError(method); if (RootContext.Version == LanguageVersion.ISO_1) { Report.Error(410, loc, "A method or delegate `{0} {1}' parameters and return type must be same as delegate `{2} {3}' parameters and return type", TypeManager.CSharpName(((MethodInfo)method).ReturnType), member_name, TypeManager.CSharpName(invoke_method.ReturnType), Delegate.FullDelegateDesc(invoke_method)); return; } if (return_type == null) { Report.Error(123, loc, "A method or delegate `{0}' parameters do not match delegate `{1}' parameters", member_name, Delegate.FullDelegateDesc(invoke_method)); return; } Report.Error(407, loc, "A method or delegate `{0} {1}' return type does not match delegate `{2} {3}' return type", return_type.GetSignatureForError(), member_name, TypeManager.CSharpName(invoke_method.ReturnType), Delegate.FullDelegateDesc(invoke_method)); }
public virtual Type LookupTypeReflection(string name, Location loc) { Type found_type = null; foreach (Assembly a in referenced_assemblies) { Type t = GetTypeInAssembly(a, name); if (t == null) { continue; } if (found_type == null) { found_type = t; continue; } Report.SymbolRelatedToPreviousError(found_type); Report.SymbolRelatedToPreviousError(t); Report.Error(433, loc, "The imported type `{0}' is defined multiple times", name); return(found_type); } return(found_type); }
static void Error_AmbiguousTypeReference(Location loc, string name, FullNamedExpression t1, FullNamedExpression t2) { Report.SymbolRelatedToPreviousError(t1.Type); Report.SymbolRelatedToPreviousError(t2.Type); Report.Error(104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'", name, t1.GetSignatureForError(), t2.GetSignatureForError()); }
/// <summary> /// Records a new namespace for resolving name references /// </summary> public void AddUsing(MemberName name, Location loc) { if (DeclarationFound) { Report.Error(1529, loc, "A using clause must precede all other namespace elements except extern alias declarations"); } if (using_clauses == null) { using_clauses = new ArrayList(); } else { foreach (UsingEntry old_entry in using_clauses) { if (name.Equals(old_entry.MemberName)) { Report.SymbolRelatedToPreviousError(old_entry.Location, old_entry.GetSignatureForError()); Report.Warning(105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetSignatureForError()); return; } } } using_clauses.Add(new UsingEntry(name)); }
public static void Error_TypeArgumentsCannotBeUsed(FullNamedExpression expr, Location loc) { if (expr is TypeExpr) { Report.SymbolRelatedToPreviousError(expr.Type); Error_TypeArgumentsCannotBeUsed(loc, "type", expr.GetSignatureForError()); } else { expr.Error_ExpressionCannotBeGeneric(loc); } }
public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Target == AttributeTargets.Assembly) { assembly.ApplyAttributeBuilder(a, ctor, cdata, pa); return; } if (a.Type == pa.DefaultCharset) { switch (a.GetCharSetValue()) { case CharSet.Ansi: case CharSet.None: break; case CharSet.Auto: DefaultCharSet = CharSet.Auto; DefaultCharSetType = TypeAttributes.AutoClass; break; case CharSet.Unicode: DefaultCharSet = CharSet.Unicode; DefaultCharSetType = TypeAttributes.UnicodeClass; break; default: Report.Error(1724, a.Location, "Value specified for the argument to `{0}' is not valid", a.GetSignatureForError()); break; } } else if (a.Type == pa.CLSCompliant) { Attribute cls = DeclaringAssembly.CLSCompliantAttribute; if (cls == null) { Report.Warning(3012, 1, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking"); } else if (DeclaringAssembly.IsCLSCompliant != a.GetBoolean()) { Report.SymbolRelatedToPreviousError(cls.Location, cls.GetSignatureForError()); Report.Warning(3017, 1, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly"); return; } } builder.SetCustomAttribute((ConstructorInfo)ctor.GetMetaInfo(), cdata); }
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa) { if (a.Type == pa.CLSCompliant) { if (CodeGen.Assembly.ClsCompliantAttribute == null) { Report.Warning(3012, 1, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking"); } else if (CodeGen.Assembly.IsClsCompliant != a.GetBoolean()) { Report.SymbolRelatedToPreviousError(CodeGen.Assembly.ClsCompliantAttribute.Location, CodeGen.Assembly.ClsCompliantAttribute.GetSignatureForError()); Report.Warning(3017, 1, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly"); return; } } Builder.SetCustomAttribute(cb); }
public bool AddTypesContainer(ITypesContainer container) { var mn = container.MemberName; ITypesContainer found; if (!defined_type_containers.TryGetValue(mn, out found)) { defined_type_containers.Add(mn, container); return(true); } if (container is NamespaceContainer && found is NamespaceContainer) { return(true); } var container_tc = container as TypeContainer; var found_tc = found as TypeContainer; if (container_tc != null && found_tc != null && container_tc.Kind == found_tc.Kind) { if ((found_tc.ModFlags & container_tc.ModFlags & Modifiers.PARTIAL) != 0) { return(false); } if (((found_tc.ModFlags | container_tc.ModFlags) & Modifiers.PARTIAL) != 0) { Report.SymbolRelatedToPreviousError(found_tc); Error_MissingPartialModifier(container_tc); return(false); } } string ns = mn.Left != null?mn.Left.GetSignatureForError() : Module.GlobalRootNamespace.GetSignatureForError(); mn = new MemberName(mn.Name, mn.TypeArguments, mn.Location); Report.SymbolRelatedToPreviousError(found.Location, ""); Report.Error(101, container.Location, "The namespace `{0}' already contains a definition for `{1}'", ns, mn.GetSignatureForError()); return(false); }
// // When using assembly public key attributes InternalsVisibleTo key // was not checked, we have to do it later when we actually know what // our public key token is // void CheckReferencesPublicToken() { // TODO: It should check only references assemblies but there is // no working SRE API foreach (var entry in Importer.Assemblies) { var a = entry as ImportedAssemblyDefinition; if (a == null) { continue; } if (public_key != null && !a.HasStrongName) { Report.Error(1577, "Referenced assembly `{0}' does not have a strong name", a.FullName); } var ci = a.Assembly.GetName().CultureInfo; if (!ci.Equals(System.Globalization.CultureInfo.InvariantCulture)) { Report.Warning(1607, 1, "Referenced assembly `{0}' has different culture setting of `{1}'", a.Name, ci.Name); } if (!a.IsFriendAssemblyTo(this)) { continue; } var attr = a.GetAssemblyVisibleToName(this); var atoken = attr.GetPublicKeyToken(); if (ArrayComparer.IsEqual(GetPublicKeyToken(), atoken)) { continue; } Report.SymbolRelatedToPreviousError(a.Location); Report.Error(281, "Friend access was granted to `{0}', but the output assembly is named `{1}'. Try adding a reference to `{0}' or change the output assembly name to match it", attr.FullName, FullName); } }
void AddUsingAlias(UsingAliasEntry uae) { if (using_aliases == null) { using_aliases = new ArrayList(); } else { foreach (UsingAliasEntry entry in using_aliases) { if (uae.Alias == entry.Alias) { Report.SymbolRelatedToPreviousError(uae.Location, uae.Alias); Report.Error(1537, entry.Location, "The using alias `{0}' appeared previously in this namespace", entry.Alias); return; } } } using_aliases.Add(uae); }
public override Type LookupTypeReflection(string name, Location loc) { Type found_type = base.LookupTypeReflection(name, loc); if (modules != null) { foreach (Module module in modules) { Type t = module.GetType(name); if (t == null) { continue; } if (found_type == null) { found_type = t; continue; } Report.SymbolRelatedToPreviousError(found_type); if (loc.IsNull) { DeclSpace ds = TypeManager.LookupDeclSpace(t); Report.Warning(1685, 1, ds.Location, "The type `{0}' conflicts with the predefined type `{1}' and will be ignored", ds.GetSignatureForError(), TypeManager.CSharpName(found_type)); return(found_type); } Report.SymbolRelatedToPreviousError(t); Report.Warning(436, 2, loc, "The type `{0}' conflicts with the imported type `{1}'. Ignoring the imported type definition", TypeManager.CSharpName(t), TypeManager.CSharpName(found_type)); return(t); } } return(found_type); }
public Namespace Resolve(IResolveContext rc) { if (resolved != null) { return(resolved); } FullNamedExpression fne = name.GetTypeExpression().ResolveAsTypeStep(rc, false); if (fne == null) { return(null); } resolved = fne as Namespace; if (resolved == null) { Report.SymbolRelatedToPreviousError(fne.Type); Report.Error(138, Location, "`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces", GetSignatureForError()); } return(resolved); }
public static void Error_VariableOfStaticClass(Location loc, string variable_name, TypeSpec static_class, Report Report) { Report.SymbolRelatedToPreviousError(static_class); Report.Error(723, loc, "`{0}': cannot declare variables of static types", variable_name); }
public static void Error_InvalidNumberOfTypeArguments(Type t, Location loc) { Report.SymbolRelatedToPreviousError(t); Report.Error(305, loc, "Using the generic type `{0}' requires `{1}' type argument(s)", TypeManager.CSharpName(t), TypeManager.GetNumberOfTypeArguments(t).ToString()); }
/// <summary> /// Verifies that any pending abstract methods or interface methods /// were implemented. /// </summary> public bool VerifyPendingMethods(Report Report) { int top = pending_implementations.Length; bool errors = false; int i; for (i = 0; i < top; i++) { TypeSpec type = pending_implementations [i].type; bool base_implements_type = type.IsInterface && container.BaseType != null && container.BaseType.ImplementsInterface(type, false); for (int j = 0; j < pending_implementations [i].methods.Count; ++j) { var mi = pending_implementations[i].methods[j]; if (mi == null) { continue; } if (type.IsInterface) { var need_proxy = pending_implementations [i].need_proxy [j]; if (need_proxy != null) { DefineProxy(type, need_proxy, mi); continue; } if (pending_implementations [i].optional) { continue; } MethodSpec candidate = null; if (base_implements_type || BaseImplements(type, mi, out candidate)) { continue; } if (candidate == null) { MethodData md = pending_implementations [i].found [j]; if (md != null) { candidate = md.method.Spec; } } Report.SymbolRelatedToPreviousError(mi); if (candidate != null) { Report.SymbolRelatedToPreviousError(candidate); if (candidate.IsStatic) { Report.Error(736, container.Location, "`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' is static", container.GetSignatureForError(), mi.GetSignatureForError(), TypeManager.CSharpSignature(candidate)); } else if ((candidate.Modifiers & Modifiers.PUBLIC) == 0) { Report.Error(737, container.Location, "`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' in not public", container.GetSignatureForError(), mi.GetSignatureForError(), candidate.GetSignatureForError()); } else { Report.Error(738, container.Location, "`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' return type `{3}' does not match interface member return type `{4}'", container.GetSignatureForError(), mi.GetSignatureForError(), TypeManager.CSharpSignature(candidate), TypeManager.CSharpName(candidate.ReturnType), TypeManager.CSharpName(mi.ReturnType)); } } else { Report.Error(535, container.Location, "`{0}' does not implement interface member `{1}'", container.GetSignatureForError(), mi.GetSignatureForError()); } } else { Report.SymbolRelatedToPreviousError(mi); Report.Error(534, container.Location, "`{0}' does not implement inherited abstract member `{1}'", container.GetSignatureForError(), mi.GetSignatureForError()); } errors = true; } } return(errors); }
static void CheckConversion(MemberSpec context, TypeSpec atype, TypeParameterSpec tparam, TypeSpec ttype, Location loc, Report report) { var expr = new EmptyExpression (atype); if (!Convert.ImplicitStandardConversionExists (expr, ttype)) { report.SymbolRelatedToPreviousError (tparam); if (TypeManager.IsValueType (atype)) { report.Error (315, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. There is no boxing conversion from `{0}' to `{3}'", atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError (), ttype.GetSignatureForError ()); } else if (atype.IsGenericParameter) { report.Error (314, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. There is no boxing or type parameter conversion from `{0}' to `{3}'", atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError (), ttype.GetSignatureForError ()); } else { report.Error (311, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. There is no implicit reference conversion from `{0}' to `{3}'", atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError (), ttype.GetSignatureForError ()); } } }
private FullNamedExpression Lookup(DeclSpace ds, string name, Location loc, bool ignore_cs0104) { // // Check whether it's in the namespace. // FullNamedExpression fne = ns.Lookup(ds, name, loc); // // Check aliases. // if (using_aliases != null) { foreach (UsingAliasEntry ue in using_aliases) { if (ue.Alias == name) { if (fne != null) { if (Doppelganger != null) { // TODO: Namespace has broken location //Report.SymbolRelatedToPreviousError (fne.Location, null); Report.SymbolRelatedToPreviousError(ue.Location, null); Report.Error(576, loc, "Namespace `{0}' contains a definition with same name as alias `{1}'", GetSignatureForError(), name); } else { return(fne); } } return(ue.Resolve(Doppelganger)); } } } if (fne != null) { return(fne); } if (IsImplicit) { return(null); } // // Check using entries. // FullNamedExpression match = null; foreach (Namespace using_ns in GetUsingTable()) { match = using_ns.Lookup(ds, name, loc); if (match == null || !(match is TypeExpr)) { continue; } if (fne != null) { if (!ignore_cs0104) { Error_AmbiguousTypeReference(loc, name, fne, match); } return(null); } fne = match; } return(fne); }
public bool Define (DeclSpace parent, string method_full_name, Report Report) { TypeContainer container = parent.PartialContainer; PendingImplementation pending = container.PendingImplementations; if (pending != null){ implementing = pending.IsInterfaceMethod (method.MethodName, member.InterfaceType, this); if (member.InterfaceType != null){ if (implementing == null){ if (member is PropertyBase) { Report.Error (550, method.Location, "`{0}' is an accessor not found in interface member `{1}{2}'", method.GetSignatureForError (), TypeManager.CSharpName (member.InterfaceType), member.GetSignatureForError ().Substring (member.GetSignatureForError ().LastIndexOf ('.'))); } else { Report.Error (539, method.Location, "`{0}.{1}' in explicit interface declaration is not a member of interface", TypeManager.CSharpName (member.InterfaceType), member.ShortName); } return false; } if (implementing.IsAccessor && !(method is AbstractPropertyEventMethod)) { Report.SymbolRelatedToPreviousError (implementing); Report.Error (683, method.Location, "`{0}' explicit method implementation cannot implement `{1}' because it is an accessor", member.GetSignatureForError (), TypeManager.CSharpSignature (implementing)); return false; } } else { if (implementing != null) { AbstractPropertyEventMethod prop_method = method as AbstractPropertyEventMethod; if (prop_method == null) { if (implementing.IsAccessor) { Report.SymbolRelatedToPreviousError (implementing); Report.Error (470, method.Location, "Method `{0}' cannot implement interface accessor `{1}'", method.GetSignatureForError (), TypeManager.CSharpSignature (implementing)); } } else if (implementing.DeclaringType.IsInterface) { if (!implementing.IsAccessor) { Report.SymbolRelatedToPreviousError (implementing); Report.Error (686, method.Location, "Accessor `{0}' cannot implement interface member `{1}' for type `{2}'. Use an explicit interface implementation", method.GetSignatureForError (), TypeManager.CSharpSignature (implementing), container.GetSignatureForError ()); } else { PropertyBase.PropertyMethod pm = prop_method as PropertyBase.PropertyMethod; if (pm != null && pm.HasCustomAccessModifier && (pm.ModFlags & Modifiers.PUBLIC) == 0) { Report.SymbolRelatedToPreviousError (implementing); Report.Error (277, method.Location, "Accessor `{0}' must be declared public to implement interface member `{1}'", method.GetSignatureForError (), implementing.GetSignatureForError ()); } } } } } } // // For implicit implementations, make sure we are public, for // explicit implementations, make sure we are private. // if (implementing != null){ // // Setting null inside this block will trigger a more // verbose error reporting for missing interface implementations // // The "candidate" function has been flagged already // but it wont get cleared // if (member.IsExplicitImpl){ if (method.ParameterInfo.HasParams && !implementing.Parameters.HasParams) { Report.SymbolRelatedToPreviousError (implementing); Report.Error (466, method.Location, "`{0}': the explicit interface implementation cannot introduce the params modifier", method.GetSignatureForError ()); } } else { if (implementing.DeclaringType.IsInterface) { // // If this is an interface method implementation, // check for public accessibility // if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public) { implementing = null; } } else if ((flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Private){ // We may never be private. implementing = null; } else if ((modifiers & Modifiers.OVERRIDE) == 0){ // // We may be protected if we're overriding something. // implementing = null; } } // // Static is not allowed // if ((modifiers & Modifiers.STATIC) != 0){ implementing = null; } } // // If implementing is still valid, set flags // if (implementing != null){ // // When implementing interface methods, set NewSlot // unless, we are overwriting a method. // if (implementing.DeclaringType.IsInterface){ if ((modifiers & Modifiers.OVERRIDE) == 0) flags |= MethodAttributes.NewSlot; } flags |= MethodAttributes.Virtual | MethodAttributes.HideBySig; // Set Final unless we're virtual, abstract or already overriding a method. if ((modifiers & (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE)) == 0) flags |= MethodAttributes.Final; // // clear the pending implementation flag (requires explicit methods to be defined first) // parent.PartialContainer.PendingImplementations.ImplementMethod (method.MethodName, member.InterfaceType, this, member.IsExplicitImpl); // // Update indexer accessor name to match implementing abstract accessor // if (!implementing.DeclaringType.IsInterface && !member.IsExplicitImpl && implementing.IsAccessor) method_full_name = implementing.MemberDefinition.Name; } DefineMethodBuilder (container, method_full_name, method.ParameterInfo); if (builder == null) return false; // if (container.CurrentType != null) // declaring_type = container.CurrentType; // else declaring_type = container.Definition; if (implementing != null && member.IsExplicitImpl) { container.TypeBuilder.DefineMethodOverride (builder, (MethodInfo) implementing.GetMetaInfo ()); } return true; }
/// <summary> /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank /// </summary> /// // TODO: refactor as method is always 'this' public static void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder, Report Report) { EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public; for (int i = 0; i < al.Count; ++i) { MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i]; // skip itself if (entry.Member == this_builder) continue; if ((entry.EntryType & tested_type) != tested_type) continue; MethodBase method_to_compare = (MethodBase)entry.Member; AttributeTester.Result result = AttributeTester.AreOverloadedMethodParamsClsCompliant ( method.Parameters, TypeManager.GetParameterData (method_to_compare)); if (result == AttributeTester.Result.Ok) continue; IMethodData md = TypeManager.GetMethod (method_to_compare); // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy. // However it is exactly what csc does. if (md != null && !md.IsClsComplianceRequired ()) continue; Report.SymbolRelatedToPreviousError (entry.Member); switch (result) { case AttributeTester.Result.RefOutArrayError: Report.Warning (3006, 1, method.Location, "Overloaded method `{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ()); continue; case AttributeTester.Result.ArrayArrayError: Report.Warning (3007, 1, method.Location, "Overloaded method `{0}' differing only by unnamed array types is not CLS-compliant", method.GetSignatureForError ()); continue; } throw new NotImplementedException (result.ToString ()); } }
public void Error_TypeArgumentsCannotBeUsed(Report report, Location loc, MemberSpec member, int arity) { // Better message for possible generic expressions if (member != null && (member.Kind & MemberKind.GenericMask) != 0) { report.SymbolRelatedToPreviousError (member); if (member is TypeSpec) member = ((TypeSpec) member).GetDefinition (); else member = ((MethodSpec) member).GetGenericMethodDefinition (); string name = member.Kind == MemberKind.Method ? "method" : "type"; if (member.IsGeneric) { report.Error (305, loc, "Using the generic {0} `{1}' requires `{2}' type argument(s)", name, member.GetSignatureForError (), member.Arity.ToString ()); } else { report.Error (308, loc, "The non-generic {0} `{1}' cannot be used with the type arguments", name, member.GetSignatureForError ()); } } else { report.Error (307, loc, "The {0} `{1}' cannot be used with type arguments", ExprClassName, GetSignatureForError ()); } }
protected override bool DoDefineMembers() { var builtin_types = Compiler.BuiltinTypes; var ctor_parameters = ParametersCompiled.CreateFullyResolved( new [] { new Parameter(new TypeExpression(builtin_types.Object, Location), "object", Parameter.Modifier.NONE, null, Location), new Parameter(new TypeExpression(builtin_types.IntPtr, Location), "method", Parameter.Modifier.NONE, null, Location) }, new [] { builtin_types.Object, builtin_types.IntPtr } ); Constructor = new Constructor(this, Constructor.ConstructorName, Modifiers.PUBLIC, null, ctor_parameters, Location); Constructor.Define(); // // Here the various methods like Invoke, BeginInvoke etc are defined // // First, call the `out of band' special method for // defining recursively any types we need: // var p = parameters; if (!p.Resolve(this)) { return(false); } // // Invoke method // // Check accessibility foreach (var partype in p.Types) { if (!IsAccessibleAs(partype)) { Report.SymbolRelatedToPreviousError(partype); Report.Error(59, Location, "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'", partype.GetSignatureForError(), GetSignatureForError()); } } var ret_type = ReturnType.ResolveAsType(this); if (ret_type == null) { return(false); } // // We don't have to check any others because they are all // guaranteed to be accessible - they are standard types. // if (!IsAccessibleAs(ret_type)) { Report.SymbolRelatedToPreviousError(ret_type); Report.Error(58, Location, "Inconsistent accessibility: return type `" + ret_type.GetSignatureForError() + "' is less " + "accessible than delegate `" + GetSignatureForError() + "'"); return(false); } CheckProtectedModifier(); if (Compiler.Settings.StdLib && ret_type.IsSpecialRuntimeType) { Method.Error1599(Location, ret_type, Report); return(false); } VarianceDecl.CheckTypeVariance(ret_type, Variance.Covariant, this); var resolved_rt = new TypeExpression(ret_type, Location); InvokeBuilder = new Method(this, resolved_rt, MethodModifiers, new MemberName(InvokeMethodName), p, null); InvokeBuilder.Define(); // // Don't emit async method for compiler generated delegates (e.g. dynamic site containers) // if (!IsCompilerGenerated) { DefineAsyncMethods(resolved_rt); } return(true); }
public void VerifyClsCompliance (Report report) { foreach (var c in constraints) { if (c == null) continue; if (!c.Type.IsCLSCompliant ()) { report.SymbolRelatedToPreviousError (c.Type); report.Warning (3024, 1, loc, "Constraint type `{0}' is not CLS-compliant", c.Type.GetSignatureForError ()); } } }
void Warning_ConstrainIsNotClsCompliant (Type t, Location loc, Report Report) { Report.SymbolRelatedToPreviousError (t); Report.Warning (3024, 1, loc, "Constraint type `{0}' is not CLS-compliant", TypeManager.CSharpName (t)); }
/// <summary> /// Resolve the constraints - but only resolve things into Expression's, not /// into actual types. /// </summary> public bool Resolve (MemberCore ec, TypeParameter tp, Report Report) { if (resolved) return true; if (ec == null) return false; iface_constraints = new ArrayList (2); // TODO: Too expensive allocation type_param_constraints = new ArrayList (); foreach (object obj in constraints) { if (HasConstructorConstraint) { Report.Error (401, loc, "The new() constraint must be the last constraint specified"); return false; } if (obj is SpecialConstraint) { SpecialConstraint sc = (SpecialConstraint) obj; if (sc == SpecialConstraint.Constructor) { if (!HasValueTypeConstraint) { attrs |= GenericParameterAttributes.DefaultConstructorConstraint; continue; } Report.Error (451, loc, "The `new()' constraint " + "cannot be used with the `struct' constraint"); return false; } if ((num_constraints > 0) || HasReferenceTypeConstraint || HasValueTypeConstraint) { Report.Error (449, loc, "The `class' or `struct' " + "constraint must be the first constraint specified"); return false; } if (sc == SpecialConstraint.ReferenceType) attrs |= GenericParameterAttributes.ReferenceTypeConstraint; else attrs |= GenericParameterAttributes.NotNullableValueTypeConstraint; continue; } int errors = Report.Errors; FullNamedExpression fn = ((Expression) obj).ResolveAsTypeStep (ec, false); if (fn == null) { if (errors != Report.Errors) return false; NamespaceEntry.Error_NamespaceNotFound (loc, ((Expression)obj).GetSignatureForError (), Report); return false; } TypeExpr expr; GenericTypeExpr cexpr = fn as GenericTypeExpr; if (cexpr != null) { expr = cexpr.ResolveAsBaseTerminal (ec, false); } else expr = ((Expression) obj).ResolveAsTypeTerminal (ec, false); if ((expr == null) || (expr.Type == null)) return false; if (!ec.IsAccessibleAs (fn.Type)) { Report.SymbolRelatedToPreviousError (fn.Type); Report.Error (703, loc, "Inconsistent accessibility: constraint type `{0}' is less accessible than `{1}'", fn.GetSignatureForError (), ec.GetSignatureForError ()); return false; } if (TypeManager.IsGenericParameter (expr.Type)) type_param_constraints.Add (expr); else if (expr.IsInterface) iface_constraints.Add (expr); else if (class_constraint != null || iface_constraints.Count != 0) { Report.Error (406, loc, "The class type constraint `{0}' must be listed before any other constraints. Consider moving type constraint to the beginning of the constraint list", expr.GetSignatureForError ()); return false; } else if (HasReferenceTypeConstraint || HasValueTypeConstraint) { Report.Error (450, loc, "`{0}': cannot specify both " + "a constraint class and the `class' " + "or `struct' constraint", expr.GetSignatureForError ()); return false; } else class_constraint = expr; // // Checks whether each generic method parameter constraint type // is valid with respect to T // if (tp != null && tp.Type.DeclaringMethod != null) { TypeManager.CheckTypeVariance (expr.Type, Variance.Contravariant, ec as MemberCore); } num_constraints++; } ArrayList list = new ArrayList (); foreach (TypeExpr iface_constraint in iface_constraints) { foreach (Type type in list) { if (!type.Equals (iface_constraint.Type)) continue; Report.Error (405, loc, "Duplicate constraint `{0}' for type " + "parameter `{1}'.", iface_constraint.GetSignatureForError (), name); return false; } list.Add (iface_constraint.Type); } foreach (TypeExpr expr in type_param_constraints) { foreach (Type type in list) { if (!type.Equals (expr.Type)) continue; Report.Error (405, loc, "Duplicate constraint `{0}' for type " + "parameter `{1}'.", expr.GetSignatureForError (), name); return false; } list.Add (expr.Type); } iface_constraint_types = new Type [list.Count]; list.CopyTo (iface_constraint_types, 0); if (class_constraint != null) { class_constraint_type = class_constraint.Type; if (class_constraint_type == null) return false; if (class_constraint_type.IsSealed) { if (class_constraint_type.IsAbstract) { Report.Error (717, loc, "`{0}' is not a valid constraint. Static classes cannot be used as constraints", TypeManager.CSharpName (class_constraint_type)); } else { Report.Error (701, loc, "`{0}' is not a valid constraint. A constraint must be an interface, " + "a non-sealed class or a type parameter", TypeManager.CSharpName(class_constraint_type)); } return false; } if ((class_constraint_type == TypeManager.array_type) || (class_constraint_type == TypeManager.delegate_type) || (class_constraint_type == TypeManager.enum_type) || (class_constraint_type == TypeManager.value_type) || (class_constraint_type == TypeManager.object_type) || class_constraint_type == TypeManager.multicast_delegate_type) { Report.Error (702, loc, "A constraint cannot be special class `{0}'", TypeManager.CSharpName (class_constraint_type)); return false; } if (TypeManager.IsDynamicType (class_constraint_type)) { Report.Error (1967, loc, "A constraint cannot be the dynamic type"); return false; } } if (class_constraint_type != null) effective_base_type = class_constraint_type; else if (HasValueTypeConstraint) effective_base_type = TypeManager.value_type; else effective_base_type = TypeManager.object_type; if ((attrs & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) attrs |= GenericParameterAttributes.DefaultConstructorConstraint; resolved = true; return true; }
/// <summary> /// Verifies that any pending abstract methods or interface methods /// were implemented. /// </summary> public bool VerifyPendingMethods(Report Report) { int top = pending_implementations.Length; bool errors = false; int i; for (i = 0; i < top; i++){ TypeSpec type = pending_implementations [i].type; int j = 0; bool base_implements_type = type.IsInterface && container.BaseType != null && container.BaseType.ImplementsInterface (type); foreach (var mi in pending_implementations [i].methods){ if (mi == null) continue; if (type.IsInterface){ var need_proxy = pending_implementations [i].need_proxy [j]; if (need_proxy != null) { DefineProxy (type, need_proxy, mi); continue; } if (pending_implementations [i].optional) continue; MethodSpec candidate = null; if (base_implements_type || BaseImplements (type, mi, out candidate)) continue; if (candidate == null) { MethodData md = pending_implementations [i].found [j]; if (md != null) candidate = md.method.Spec; } Report.SymbolRelatedToPreviousError (mi); if (candidate != null) { Report.SymbolRelatedToPreviousError (candidate); if (candidate.IsStatic) { Report.Error (736, container.Location, "`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' is static", container.GetSignatureForError (), mi.GetSignatureForError (), TypeManager.CSharpSignature (candidate)); } else if ((candidate.Modifiers & Modifiers.PUBLIC) == 0) { Report.Error (737, container.Location, "`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' in not public", container.GetSignatureForError (), mi.GetSignatureForError (), candidate.GetSignatureForError ()); } else { Report.Error (738, container.Location, "`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' return type `{3}' does not match interface member return type `{4}'", container.GetSignatureForError (), mi.GetSignatureForError (), TypeManager.CSharpSignature (candidate), TypeManager.CSharpName (candidate.ReturnType), TypeManager.CSharpName (mi.ReturnType)); } } else { Report.Error (535, container.Location, "`{0}' does not implement interface member `{1}'", container.GetSignatureForError (), mi.GetSignatureForError ()); } } else { Report.SymbolRelatedToPreviousError (mi); Report.Error (534, container.Location, "`{0}' does not implement inherited abstract member `{1}'", container.GetSignatureForError (), mi.GetSignatureForError ()); } errors = true; j++; } } return errors; }
public override Expression DoResolve(EmitContext ec) { constructor_method = Delegate.GetConstructor(ec.ContainerType, type); MethodInfo invoke_method = Delegate.GetInvokeMethod(ec.ContainerType, type); method_group.DelegateType = type; method_group.CustomErrorHandler = this; ArrayList arguments = CreateDelegateMethodArguments(invoke_method, loc); method_group = method_group.OverloadResolve(ec, ref arguments, false, loc); if (method_group == null) { return(null); } delegate_method = (MethodInfo)method_group; if (TypeManager.IsNullableType(delegate_method.DeclaringType)) { Report.Error(1728, loc, "Cannot create delegate from method `{0}' because it is a member of System.Nullable<T> type", TypeManager.GetFullNameSignature(delegate_method)); return(null); } Invocation.IsSpecialMethodInvocation(delegate_method, loc); ExtensionMethodGroupExpr emg = method_group as ExtensionMethodGroupExpr; if (emg != null) { delegate_instance_expression = emg.ExtensionExpression; Type e_type = delegate_instance_expression.Type; if (TypeManager.IsValueType(e_type)) { Report.Error(1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates", TypeManager.CSharpSignature(delegate_method), TypeManager.CSharpName(e_type)); } } Type rt = TypeManager.TypeToCoreType(delegate_method.ReturnType); Expression ret_expr = new TypeExpression(rt, loc); if (!Delegate.IsTypeCovariant(ret_expr, (TypeManager.TypeToCoreType(invoke_method.ReturnType)))) { Error_ConversionFailed(ec, delegate_method, ret_expr); } if (Invocation.IsMethodExcluded(delegate_method, loc)) { Report.SymbolRelatedToPreviousError(delegate_method); MethodOrOperator m = TypeManager.GetMethod(delegate_method) as MethodOrOperator; if (m != null && m.IsPartialDefinition) { Report.Error(762, loc, "Cannot create delegate from partial method declaration `{0}'", TypeManager.CSharpSignature(delegate_method)); } else { Report.Error(1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute", TypeManager.CSharpSignature(delegate_method)); } } DoResolveInstanceExpression(ec); eclass = ExprClass.Value; return(this); }
public static void Error_TypeArgumentsCannotBeUsed(MethodBase mi, Location loc) { Report.SymbolRelatedToPreviousError(mi); Error_TypeArgumentsCannotBeUsed(loc, "method", TypeManager.CSharpSignature(mi)); }
public bool CheckExistingMembersOverloads (MemberCore member, string name, ParametersCompiled parameters, Report Report) { ArrayList entries = (ArrayList)member_hash [name]; if (entries == null) return true; int method_param_count = parameters.Count; for (int i = entries.Count - 1; i >= 0; --i) { CacheEntry ce = (CacheEntry) entries [i]; if (ce.Container != member.Parent.PartialContainer) return true; Type [] p_types; AParametersCollection pd; if ((ce.EntryType & EntryType.Property) != 0) { pd = TypeManager.GetParameterData ((PropertyInfo) ce.Member); p_types = pd.Types; } else { MethodBase mb = (MethodBase) ce.Member; // TODO: This is more like a hack, because we are adding generic methods // twice with and without arity name if (TypeManager.IsGenericMethod (mb) && !member.MemberName.IsGeneric) continue; pd = TypeManager.GetParameterData (mb); p_types = pd.Types; } if (p_types.Length != method_param_count) continue; if (method_param_count > 0) { int ii = method_param_count - 1; Type type_a, type_b; do { type_a = parameters.Types [ii]; type_b = p_types [ii]; #if GMCS_SOURCE if (TypeManager.IsGenericParameter (type_a) && type_a.DeclaringMethod != null) type_a = typeof (TypeParameter); if (TypeManager.IsGenericParameter (type_b) && type_b.DeclaringMethod != null) type_b = typeof (TypeParameter); #endif if ((pd.FixedParameters [ii].ModFlags & Parameter.Modifier.ISBYREF) != (parameters.FixedParameters [ii].ModFlags & Parameter.Modifier.ISBYREF)) type_a = null; } while (type_a == type_b && ii-- != 0); if (ii >= 0) continue; // // Operators can differ in return type only // if (member is Operator) { Operator op = TypeManager.GetMethod ((MethodBase) ce.Member) as Operator; if (op != null && op.ReturnType != ((Operator) member).ReturnType) continue; } // // Report difference in parameter modifiers only // if (pd != null && member is MethodCore) { ii = method_param_count; while (ii-- != 0 && parameters.FixedParameters [ii].ModFlags == pd.FixedParameters [ii].ModFlags && parameters.ExtensionMethodType == pd.ExtensionMethodType); if (ii >= 0) { MethodCore mc = TypeManager.GetMethod ((MethodBase) ce.Member) as MethodCore; Report.SymbolRelatedToPreviousError (ce.Member); if ((member.ModFlags & Modifiers.PARTIAL) != 0 && (mc.ModFlags & Modifiers.PARTIAL) != 0) { if (parameters.HasParams || pd.HasParams) { Report.Error (758, member.Location, "A partial method declaration and partial method implementation cannot differ on use of `params' modifier"); } else { Report.Error (755, member.Location, "A partial method declaration and partial method implementation must be both an extension method or neither"); } } else { if (member is Constructor) { Report.Error (851, member.Location, "Overloaded contructor `{0}' cannot differ on use of parameter modifiers only", member.GetSignatureForError ()); } else { Report.Error (663, member.Location, "Overloaded method `{0}' cannot differ on use of parameter modifiers only", member.GetSignatureForError ()); } } return false; } } } if ((ce.EntryType & EntryType.Method) != 0) { Method method_a = member as Method; Method method_b = TypeManager.GetMethod ((MethodBase) ce.Member) as Method; if (method_a != null && method_b != null && (method_a.ModFlags & method_b.ModFlags & Modifiers.PARTIAL) != 0) { const int partial_modifiers = Modifiers.STATIC | Modifiers.UNSAFE; if (method_a.IsPartialDefinition == method_b.IsPartialImplementation) { if ((method_a.ModFlags & partial_modifiers) == (method_b.ModFlags & partial_modifiers) || method_a.Parent.IsUnsafe && method_b.Parent.IsUnsafe) { if (method_a.IsPartialImplementation) { method_a.SetPartialDefinition (method_b); entries.RemoveAt (i); } else { method_b.SetPartialDefinition (method_a); } continue; } if ((method_a.ModFlags & Modifiers.STATIC) != (method_b.ModFlags & Modifiers.STATIC)) { Report.SymbolRelatedToPreviousError (ce.Member); Report.Error (763, member.Location, "A partial method declaration and partial method implementation must be both `static' or neither"); } Report.SymbolRelatedToPreviousError (ce.Member); Report.Error (764, member.Location, "A partial method declaration and partial method implementation must be both `unsafe' or neither"); return false; } Report.SymbolRelatedToPreviousError (ce.Member); if (method_a.IsPartialDefinition) { Report.Error (756, member.Location, "A partial method `{0}' declaration is already defined", member.GetSignatureForError ()); } Report.Error (757, member.Location, "A partial method `{0}' implementation is already defined", member.GetSignatureForError ()); return false; } Report.SymbolRelatedToPreviousError (ce.Member); IMethodData duplicate_member = TypeManager.GetMethod ((MethodBase) ce.Member); if (member is Operator && duplicate_member is Operator) { Report.Error (557, member.Location, "Duplicate user-defined conversion in type `{0}'", member.Parent.GetSignatureForError ()); return false; } bool is_reserved_a = member is AbstractPropertyEventMethod || member is Operator; bool is_reserved_b = duplicate_member is AbstractPropertyEventMethod || duplicate_member is Operator; if (is_reserved_a || is_reserved_b) { Report.Error (82, member.Location, "A member `{0}' is already reserved", is_reserved_a ? TypeManager.GetFullNameSignature (ce.Member) : member.GetSignatureForError ()); return false; } } else { Report.SymbolRelatedToPreviousError (ce.Member); } Report.Error (111, member.Location, "A member `{0}' is already defined. Rename this member or use different parameter types", member.GetSignatureForError ()); return false; } return true; }
protected override bool DoDefineMembers() { if (IsGeneric) { foreach (TypeParameter type_param in TypeParameters) { if (!type_param.Resolve(this)) { return(false); } } foreach (TypeParameter type_param in TypeParameters) { if (!type_param.DefineType(this)) { return(false); } } } member_cache = new MemberCache(TypeManager.multicast_delegate_type, this); // FIXME: POSSIBLY make this static, as it is always constant // Type [] const_arg_types = new Type [2]; const_arg_types [0] = TypeManager.object_type; const_arg_types [1] = TypeManager.intptr_type; const MethodAttributes ctor_mattr = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public; ConstructorBuilder = TypeBuilder.DefineConstructor(ctor_mattr, CallingConventions.Standard, const_arg_types); ConstructorBuilder.DefineParameter(1, ParameterAttributes.None, "object"); ConstructorBuilder.DefineParameter(2, ParameterAttributes.None, "method"); // // HACK because System.Reflection.Emit is lame // IParameterData [] fixed_pars = new IParameterData [] { new ParameterData("object", Parameter.Modifier.NONE), new ParameterData("method", Parameter.Modifier.NONE) }; AParametersCollection const_parameters = new ParametersImported( fixed_pars, new Type[] { TypeManager.object_type, TypeManager.intptr_type }); TypeManager.RegisterMethod(ConstructorBuilder, const_parameters); member_cache.AddMember(ConstructorBuilder, this); ConstructorBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); // // Here the various methods like Invoke, BeginInvoke etc are defined // // First, call the `out of band' special method for // defining recursively any types we need: if (!Parameters.Resolve(this)) { return(false); } // // Invoke method // // Check accessibility foreach (Type partype in Parameters.Types) { if (!IsAccessibleAs(partype)) { Report.SymbolRelatedToPreviousError(partype); Report.Error(59, Location, "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'", TypeManager.CSharpName(partype), GetSignatureForError()); return(false); } } ReturnType = ReturnType.ResolveAsTypeTerminal(this, false); if (ReturnType == null) { return(false); } ret_type = ReturnType.Type; if (!IsAccessibleAs(ret_type)) { Report.SymbolRelatedToPreviousError(ret_type); Report.Error(58, Location, "Inconsistent accessibility: return type `" + TypeManager.CSharpName(ret_type) + "' is less " + "accessible than delegate `" + GetSignatureForError() + "'"); return(false); } CheckProtectedModifier(); if (RootContext.StdLib && TypeManager.IsSpecialType(ret_type)) { Method.Error1599(Location, ret_type, Report); return(false); } TypeManager.CheckTypeVariance(ret_type, Variance.Covariant, this); // // We don't have to check any others because they are all // guaranteed to be accessible - they are standard types. // CallingConventions cc = Parameters.CallingConvention; InvokeBuilder = TypeBuilder.DefineMethod("Invoke", mattr, cc, ret_type, Parameters.GetEmitTypes()); InvokeBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); TypeManager.RegisterMethod(InvokeBuilder, Parameters); member_cache.AddMember(InvokeBuilder, this); // // Don't emit async method for compiler generated delegates (e.g. dynamic site containers) // if (TypeManager.iasyncresult_type != null && TypeManager.asynccallback_type != null && !IsCompilerGenerated) { DefineAsyncMethods(cc); } return(true); }
public void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.IsValidSecurityAttribute()) { a.ExtractSecurityPermissionSet(ctor, ref declarative_security); return; } if (a.Type == pa.AssemblyCulture) { string value = a.GetString(); if (value == null || value.Length == 0) { return; } if (Compiler.Settings.Target == Target.Exe) { a.Error_AttributeEmitError("The executables cannot be satelite assemblies, remove the attribute or keep it empty"); return; } if (value == "neutral") { value = ""; } if (Compiler.Settings.Target == Target.Module) { SetCustomAttribute(ctor, cdata); } else { builder_extra.SetCulture(value, a.Location); } IsSatelliteAssembly = true; return; } if (a.Type == pa.AssemblyVersion) { string value = a.GetString(); if (value == null || value.Length == 0) { return; } var vinfo = IsValidAssemblyVersion(value, true); if (vinfo == null) { a.Error_AttributeEmitError(string.Format("Specified version `{0}' is not valid", value)); return; } if (Compiler.Settings.Target == Target.Module) { SetCustomAttribute(ctor, cdata); } else { builder_extra.SetVersion(vinfo, a.Location); } return; } if (a.Type == pa.AssemblyAlgorithmId) { const int pos = 2; // skip CA header uint alg = (uint)cdata [pos]; alg |= ((uint)cdata [pos + 1]) << 8; alg |= ((uint)cdata [pos + 2]) << 16; alg |= ((uint)cdata [pos + 3]) << 24; if (Compiler.Settings.Target == Target.Module) { SetCustomAttribute(ctor, cdata); } else { builder_extra.SetAlgorithmId(alg, a.Location); } return; } if (a.Type == pa.AssemblyFlags) { const int pos = 2; // skip CA header uint flags = (uint)cdata[pos]; flags |= ((uint)cdata [pos + 1]) << 8; flags |= ((uint)cdata [pos + 2]) << 16; flags |= ((uint)cdata [pos + 3]) << 24; // Ignore set PublicKey flag if assembly is not strongnamed if ((flags & (uint)AssemblyNameFlags.PublicKey) != 0 && public_key == null) { flags &= ~(uint)AssemblyNameFlags.PublicKey; } if (Compiler.Settings.Target == Target.Module) { SetCustomAttribute(ctor, cdata); } else { builder_extra.SetFlags(flags, a.Location); } return; } if (a.Type == pa.TypeForwarder) { TypeSpec t = a.GetArgumentType(); if (t == null || TypeManager.HasElementType(t)) { Report.Error(735, a.Location, "Invalid type specified as an argument for TypeForwardedTo attribute"); return; } if (emitted_forwarders == null) { emitted_forwarders = new Dictionary <ITypeDefinition, Attribute> (); } else if (emitted_forwarders.ContainsKey(t.MemberDefinition)) { Report.SymbolRelatedToPreviousError(emitted_forwarders[t.MemberDefinition].Location, null); Report.Error(739, a.Location, "A duplicate type forward of type `{0}'", t.GetSignatureForError()); return; } emitted_forwarders.Add(t.MemberDefinition, a); if (t.MemberDefinition.DeclaringAssembly == this) { Report.SymbolRelatedToPreviousError(t); Report.Error(729, a.Location, "Cannot forward type `{0}' because it is defined in this assembly", t.GetSignatureForError()); return; } if (t.IsNested) { Report.Error(730, a.Location, "Cannot forward type `{0}' because it is a nested type", t.GetSignatureForError()); return; } builder_extra.AddTypeForwarder(t.GetDefinition(), a.Location); return; } if (a.Type == pa.Extension) { a.Error_MisusedExtensionAttribute(); return; } if (a.Type == pa.InternalsVisibleTo) { string assembly_name = a.GetString(); if (assembly_name.Length == 0) { return; } #if STATIC ParsedAssemblyName aname; ParseAssemblyResult r = Fusion.ParseAssemblyName(assembly_name, out aname); if (r != ParseAssemblyResult.OK) { Report.Warning(1700, 3, a.Location, "Assembly reference `{0}' is invalid and cannot be resolved", assembly_name); return; } if (aname.Version != null || aname.Culture != null || aname.ProcessorArchitecture != ProcessorArchitecture.None) { Report.Error(1725, a.Location, "Friend assembly reference `{0}' is invalid. InternalsVisibleTo declarations cannot have a version, culture or processor architecture specified", assembly_name); return; } if (public_key != null && !aname.HasPublicKey) { Report.Error(1726, a.Location, "Friend assembly reference `{0}' is invalid. Strong named assemblies must specify a public key in their InternalsVisibleTo declarations", assembly_name); return; } #endif } else if (a.Type == pa.RuntimeCompatibility) { wrap_non_exception_throws_custom = true; } else if (a.Type == pa.AssemblyFileVersion) { string value = a.GetString(); if (string.IsNullOrEmpty(value) || IsValidAssemblyVersion(value, false) == null) { Report.Warning(1607, 1, a.Location, "The version number `{0}' specified for `{1}' is invalid", value, a.Name); return; } } SetCustomAttribute(ctor, cdata); }
/// <summary> /// Verifies that any pending abstract methods or interface methods /// were implemented. /// </summary> public bool VerifyPendingMethods() { int top = pending_implementations.Length; bool errors = false; int i; for (i = 0; i < top; i++) { Type type = pending_implementations [i].type; int j = 0; bool base_implements_type = type.IsInterface && container.TypeBuilder.BaseType != null && TypeManager.ImplementsInterface(container.TypeBuilder.BaseType, type); foreach (MethodInfo mi in pending_implementations[i].methods) { if (mi == null) { continue; } if (type.IsInterface) { MethodInfo need_proxy = pending_implementations [i].need_proxy [j]; if (need_proxy != null) { DefineProxy(type, need_proxy, mi, TypeManager.GetParameterData(mi)); continue; } if (pending_implementations [i].optional) { continue; } MethodInfo candidate = null; if (base_implements_type || BaseImplements(type, mi, out candidate)) { continue; } if (candidate == null) { MethodData md = pending_implementations [i].found [j]; if (md != null) { candidate = md.MethodBuilder; } } Report.SymbolRelatedToPreviousError(mi); if (candidate != null) { Report.SymbolRelatedToPreviousError(candidate); if (candidate.IsStatic) { Report.Error(736, container.Location, "`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' is static", container.GetSignatureForError(), TypeManager.CSharpSignature(mi, true), TypeManager.CSharpSignature(candidate)); } else if (!candidate.IsPublic) { Report.Error(737, container.Location, "`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' in not public", container.GetSignatureForError(), TypeManager.CSharpSignature(mi, true), TypeManager.CSharpSignature(candidate, true)); } else { Report.Error(738, container.Location, "`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' return type `{3}' does not match interface member return type `{4}'", container.GetSignatureForError(), TypeManager.CSharpSignature(mi, true), TypeManager.CSharpSignature(candidate), TypeManager.CSharpName(candidate.ReturnType), TypeManager.CSharpName(mi.ReturnType)); } } else { Report.Error(535, container.Location, "`{0}' does not implement interface member `{1}'", container.GetSignatureForError(), TypeManager.CSharpSignature(mi, true)); } } else { Report.Error(534, container.Location, "`{0}' does not implement inherited abstract member `{1}'", container.GetSignatureForError(), TypeManager.CSharpSignature(mi, true)); } errors = true; j++; } } return(errors); }
protected void ResolveAssemblySecurityAttributes() { string key_file = null; string key_container = null; if (module.OptAttributes != null) { foreach (Attribute a in module.OptAttributes.Attrs) { // cannot rely on any resolve-based members before you call Resolve if (a.ExplicitTarget != "assembly") { continue; } // TODO: This code is buggy: comparing Attribute name without resolving is wrong. // However, this is invoked by CodeGen.Init, when none of the namespaces // are loaded yet. // TODO: Does not handle quoted attributes properly switch (a.Name) { case "AssemblyKeyFile": case "AssemblyKeyFileAttribute": case "System.Reflection.AssemblyKeyFileAttribute": if (Compiler.Settings.StrongNameKeyFile != null) { Report.SymbolRelatedToPreviousError(a.Location, a.GetSignatureForError()); Report.Warning(1616, 1, "Option `{0}' overrides attribute `{1}' given in a source file or added module", "keyfile", "System.Reflection.AssemblyKeyFileAttribute"); } else { string value = a.GetString(); if (!string.IsNullOrEmpty(value)) { Error_ObsoleteSecurityAttribute(a, "keyfile"); key_file = value; } } break; case "AssemblyKeyName": case "AssemblyKeyNameAttribute": case "System.Reflection.AssemblyKeyNameAttribute": if (Compiler.Settings.StrongNameKeyContainer != null) { Report.SymbolRelatedToPreviousError(a.Location, a.GetSignatureForError()); Report.Warning(1616, 1, "Option `{0}' overrides attribute `{1}' given in a source file or added module", "keycontainer", "System.Reflection.AssemblyKeyNameAttribute"); } else { string value = a.GetString(); if (!string.IsNullOrEmpty(value)) { Error_ObsoleteSecurityAttribute(a, "keycontainer"); key_container = value; } } break; case "AssemblyDelaySign": case "AssemblyDelaySignAttribute": case "System.Reflection.AssemblyDelaySignAttribute": bool b = a.GetBoolean(); if (b) { Error_ObsoleteSecurityAttribute(a, "delaysign"); } delay_sign = b; break; } } } // We came here only to report assembly attributes warnings if (public_key != null) { return; } // // Load the strong key file found in attributes when no // command line key was given // if (key_file != null || key_container != null) { LoadPublicKey(key_file, key_container); } else if (delay_sign) { Report.Warning(1607, 1, "Delay signing was requested but no key file was given"); } }
static bool CheckConstraint(MemberSpec context, TypeSpec atype, TypeParameterSpec tparam, Location loc, Report report) { // // First, check the `class' and `struct' constraints. // if (tparam.HasSpecialClass && !TypeManager.IsReferenceType (atype)) { report.Error (452, loc, "The type `{0}' must be a reference type in order to use it as type parameter `{1}' in the generic type or method `{2}'", TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ()); return false; } if (tparam.HasSpecialStruct && (!TypeManager.IsValueType (atype) || TypeManager.IsNullableType (atype))) { report.Error (453, loc, "The type `{0}' must be a non-nullable value type in order to use it as type parameter `{1}' in the generic type or method `{2}'", TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ()); return false; } // // The class constraint comes next. // if (tparam.HasTypeConstraint) { CheckConversion (context, atype, tparam, tparam.BaseType, loc, report); } // // Now, check the interfaces and type parameters constraints // if (tparam.Interfaces != null) { if (TypeManager.IsNullableType (atype)) { report.Error (313, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. The nullable type `{0}' never satisfies interface constraint", atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError ()); } else { foreach (TypeSpec iface in tparam.Interfaces) { CheckConversion (context, atype, tparam, iface, loc, report); } } } // // Finally, check the constructor constraint. // if (!tparam.HasSpecialConstructor) return true; if (!HasDefaultConstructor (atype)) { report.SymbolRelatedToPreviousError (atype); report.Error (310, loc, "The type `{0}' must have a public parameterless constructor in order to use it as parameter `{1}' in the generic type or method `{2}'", TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ()); return false; } return true; }
public static void Error_VariableOfStaticClass (Location loc, string variable_name, TypeSpec static_class, Report Report) { Report.SymbolRelatedToPreviousError (static_class); Report.Error (723, loc, "`{0}': cannot declare variables of static types", variable_name); }
// TODO: rewrite this code (to kill N bugs and make it faster) and use standard ApplyAttribute way. public AssemblyName GetAssemblyName(string name, string output) { if (OptAttributes != null) { foreach (Attribute a in OptAttributes.Attrs) { // cannot rely on any resolve-based members before you call Resolve if (a.ExplicitTarget == null || a.ExplicitTarget != "assembly") { continue; } // TODO: This code is buggy: comparing Attribute name without resolving is wrong. // However, this is invoked by CodeGen.Init, when none of the namespaces // are loaded yet. // TODO: Does not handle quoted attributes properly switch (a.Name) { case "AssemblyKeyFile": case "AssemblyKeyFileAttribute": case "System.Reflection.AssemblyKeyFileAttribute": if (RootContext.StrongNameKeyFile != null) { Report.SymbolRelatedToPreviousError(a.Location, a.GetSignatureForError()); Report.Warning(1616, 1, "Option `{0}' overrides attribute `{1}' given in a source file or added module", "keyfile", "System.Reflection.AssemblyKeyFileAttribute"); } else { string value = a.GetString(); if (value != null && value.Length != 0) { RootContext.StrongNameKeyFile = value; } } break; case "AssemblyKeyName": case "AssemblyKeyNameAttribute": case "System.Reflection.AssemblyKeyNameAttribute": if (RootContext.StrongNameKeyContainer != null) { Report.SymbolRelatedToPreviousError(a.Location, a.GetSignatureForError()); Report.Warning(1616, 1, "Option `{0}' overrides attribute `{1}' given in a source file or added module", "keycontainer", "System.Reflection.AssemblyKeyNameAttribute"); } else { string value = a.GetString(); if (value != null && value.Length != 0) { RootContext.StrongNameKeyContainer = value; } } break; case "AssemblyDelaySign": case "AssemblyDelaySignAttribute": case "System.Reflection.AssemblyDelaySignAttribute": RootContext.StrongNameDelaySign = a.GetBoolean(); break; } } } AssemblyName an = new AssemblyName(); an.Name = Path.GetFileNameWithoutExtension(name); // note: delay doesn't apply when using a key container if (RootContext.StrongNameKeyContainer != null) { an.KeyPair = new StrongNameKeyPair(RootContext.StrongNameKeyContainer); return(an); } // strongname is optional if (RootContext.StrongNameKeyFile == null) { return(an); } string AssemblyDir = Path.GetDirectoryName(output); // the StrongName key file may be relative to (a) the compiled // file or (b) to the output assembly. See bugzilla #55320 // http://bugzilla.ximian.com/show_bug.cgi?id=55320 // (a) relative to the compiled file string filename = Path.GetFullPath(RootContext.StrongNameKeyFile); bool exist = File.Exists(filename); if ((!exist) && (AssemblyDir != null) && (AssemblyDir != String.Empty)) { // (b) relative to the outputed assembly filename = Path.GetFullPath(Path.Combine(AssemblyDir, RootContext.StrongNameKeyFile)); exist = File.Exists(filename); } if (exist) { using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { byte[] snkeypair = new byte [fs.Length]; fs.Read(snkeypair, 0, snkeypair.Length); if (RootContext.StrongNameDelaySign) { // delayed signing - DO NOT include private key SetPublicKey(an, snkeypair); } else { // no delay so we make sure we have the private key try { CryptoConvert.FromCapiPrivateKeyBlob(snkeypair); an.KeyPair = new StrongNameKeyPair(snkeypair); } catch (CryptographicException) { if (snkeypair.Length == 16) { // error # is different for ECMA key Report.Error(1606, "Could not sign the assembly. " + "ECMA key can only be used to delay-sign assemblies"); } else { Error_AssemblySigning("The specified file `" + RootContext.StrongNameKeyFile + "' does not have a private key"); } return(null); } } } } else { Error_AssemblySigning("The specified file `" + RootContext.StrongNameKeyFile + "' does not exist"); return(null); } return(an); }