public void AssertEmptyStack() { #if STATIC if (ig.__StackHeight != 0) { throw new InternalErrorException("Await yields with non-empty stack in `{0}", member_context.GetSignatureForError()); } #endif }
public void ErrorInvalidVariance (IMemberContext mc, Variance expected) { Report.SymbolRelatedToPreviousError (mc.CurrentMemberDefinition); string input_variance = Variance == Variance.Contravariant ? "contravariant" : "covariant"; string gtype_variance; switch (expected) { case Variance.Contravariant: gtype_variance = "contravariantly"; break; case Variance.Covariant: gtype_variance = "covariantly"; break; default: gtype_variance = "invariantly"; break; } Delegate d = mc as Delegate; string parameters = d != null ? d.Parameters.GetSignatureForError () : ""; Report.Error (1961, Location, "The {2} type parameter `{0}' must be {3} valid on `{1}{4}'", GetSignatureForError (), mc.GetSignatureForError (), input_variance, gtype_variance, parameters); }
public string GetSignatureForError() { return(MemberContext.GetSignatureForError()); }
// // Resolve the constraints types with only possible early checks, return // value `false' is reserved for recursive failure // public bool Resolve (IMemberContext context, TypeParameter tp) { if (resolved) return true; if (resolving) return false; resolving = true; var spec = tp.Type; List<TypeParameterSpec> tparam_types = null; bool iface_found = false; spec.BaseType = TypeManager.object_type; for (int i = 0; i < constraints.Count; ++i) { var constraint = constraints[i]; if (constraint is SpecialContraintExpr) { spec.SpecialConstraint |= ((SpecialContraintExpr) constraint).Constraint; if (spec.HasSpecialStruct) spec.BaseType = TypeManager.value_type; // Set to null as it does not have a type constraints[i] = null; continue; } var type_expr = constraints[i] = constraint.ResolveAsTypeTerminal (context, false); if (type_expr == null) continue; var gexpr = type_expr as GenericTypeExpr; if (gexpr != null && gexpr.HasDynamicArguments ()) { context.Compiler.Report.Error (1968, constraint.Location, "A constraint cannot be the dynamic type `{0}'", gexpr.GetSignatureForError ()); continue; } var type = type_expr.Type; if (!context.CurrentMemberDefinition.IsAccessibleAs (type)) { context.Compiler.Report.SymbolRelatedToPreviousError (type); context.Compiler.Report.Error (703, loc, "Inconsistent accessibility: constraint type `{0}' is less accessible than `{1}'", type.GetSignatureForError (), context.GetSignatureForError ()); } if (type.IsInterface) { if (!spec.AddInterface (type)) { context.Compiler.Report.Error (405, constraint.Location, "Duplicate constraint `{0}' for type parameter `{1}'", type.GetSignatureForError (), tparam.Value); } iface_found = true; continue; } var constraint_tp = type as TypeParameterSpec; if (constraint_tp != null) { if (tparam_types == null) { tparam_types = new List<TypeParameterSpec> (2); } else if (tparam_types.Contains (constraint_tp)) { context.Compiler.Report.Error (405, constraint.Location, "Duplicate constraint `{0}' for type parameter `{1}'", type.GetSignatureForError (), tparam.Value); continue; } // // Checks whether each generic method parameter constraint type // is valid with respect to T // if (tp.IsMethodTypeParameter) { TypeManager.CheckTypeVariance (type, Variance.Contravariant, context); } var tp_def = constraint_tp.MemberDefinition as TypeParameter; if (tp_def != null && !tp_def.ResolveConstraints (context)) { context.Compiler.Report.Error (454, constraint.Location, "Circular constraint dependency involving `{0}' and `{1}'", constraint_tp.GetSignatureForError (), tp.GetSignatureForError ()); continue; } // // Checks whether there are no conflicts between type parameter constraints // // class Foo<T, U> // where T : A // where U : B, T // // A and B are not convertible and only 1 class constraint is allowed // if (constraint_tp.HasTypeConstraint) { if (spec.HasTypeConstraint || spec.HasSpecialStruct) { if (!CheckConflictingInheritedConstraint (spec.BaseType, constraint_tp.BaseType, context, constraint.Location)) continue; } else { for (int ii = 0; ii < tparam_types.Count; ++ii) { if (!tparam_types[ii].HasTypeConstraint) continue; if (!CheckConflictingInheritedConstraint (tparam_types[ii].BaseType, constraint_tp.BaseType, context, constraint.Location)) break; } } } if (constraint_tp.HasSpecialStruct) { context.Compiler.Report.Error (456, constraint.Location, "Type parameter `{0}' has the `struct' constraint, so it cannot be used as a constraint for `{1}'", constraint_tp.GetSignatureForError (), tp.GetSignatureForError ()); continue; } tparam_types.Add (constraint_tp); continue; } if (iface_found || spec.HasTypeConstraint) { context.Compiler.Report.Error (406, constraint.Location, "The class type constraint `{0}' must be listed before any other constraints. Consider moving type constraint to the beginning of the constraint list", type.GetSignatureForError ()); } if (spec.HasSpecialStruct || spec.HasSpecialClass) { context.Compiler.Report.Error (450, type_expr.Location, "`{0}': cannot specify both a constraint class and the `class' or `struct' constraint", type.GetSignatureForError ()); } if (type == InternalType.Dynamic) { context.Compiler.Report.Error (1967, constraint.Location, "A constraint cannot be the dynamic type"); continue; } if (type.IsSealed || !type.IsClass) { context.Compiler.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 (type)); continue; } if (type.IsStatic) { context.Compiler.Report.Error (717, constraint.Location, "`{0}' is not a valid constraint. Static classes cannot be used as constraints", type.GetSignatureForError ()); } else if (type == TypeManager.array_type || type == TypeManager.delegate_type || type == TypeManager.enum_type || type == TypeManager.value_type || type == TypeManager.object_type || type == TypeManager.multicast_delegate_type) { context.Compiler.Report.Error (702, constraint.Location, "A constraint cannot be special class `{0}'", type.GetSignatureForError ()); continue; } spec.BaseType = type; } if (tparam_types != null) spec.TypeArguments = tparam_types.ToArray (); resolving = false; resolved = true; return true; }