}
}
+ bool ITypeDefinition.IsPartial {
+ get {
+ return false;
+ }
+ }
+
public bool IsMethodTypeParameter {
get {
return spec.IsMethodOwned;
// Copy constraint from resolved part to partial container
spec.SpecialConstraint = tp.spec.SpecialConstraint;
- spec.InterfacesDefined = tp.spec.InterfacesDefined;
+ spec.Interfaces = tp.spec.Interfaces;
spec.TypeArguments = tp.spec.TypeArguments;
spec.BaseType = tp.spec.BaseType;
}
}
+ public bool HasAnyTypeConstraint {
+ get {
+ return (spec & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0 || ifaces != null || targs != null || HasTypeConstraint;
+ }
+ }
+
public bool HasTypeConstraint {
get {
var bt = BaseType.BuiltinType;
return false;
}
+ public static bool HasAnyTypeParameterTypeConstrained (IGenericMethodDefinition md)
+ {
+ var tps = md.TypeParameters;
+ for (int i = 0; i < md.TypeParametersCount; ++i) {
+ if (tps[i].HasAnyTypeConstraint) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static bool HasAnyTypeParameterConstrained (IGenericMethodDefinition md)
+ {
+ var tps = md.TypeParameters;
+ for (int i = 0; i < md.TypeParametersCount; ++i) {
+ if (tps[i].IsConstrained) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
public override TypeSpec Mutate (TypeParameterMutator mutator)
{
return mutator.Mutate (this);
if (targs == null)
throw new ArgumentNullException ("targs");
-// this.state = openType.state;
+ this.state &= ~SharedStateFlags;
+ this.state |= (openType.state & SharedStateFlags);
+
this.context = context;
this.open_type = openType;
this.targs = targs;
this.args = args;
}
- public TypeArguments TypeArguments {
- get { return args; }
- }
-
public override string GetSignatureForError ()
{
return TypeManager.CSharpName (type);
struct ConstraintChecker
{
IMemberContext mc;
- bool ignore_inferred_dynamic;
bool recursive_checks;
public ConstraintChecker (IMemberContext ctx)
{
this.mc = ctx;
- ignore_inferred_dynamic = false;
recursive_checks = false;
}
- #region Properties
-
- public bool IgnoreInferredDynamic {
- get {
- return ignore_inferred_dynamic;
- }
- set {
- ignore_inferred_dynamic = value;
- }
- }
-
- #endregion
-
//
// Checks the constraints of open generic type against type
// arguments. This version is used for types which could not be
//
// Checks all type arguments againts type parameters constraints
- // NOTE: It can run in probing mode when `mc' is null
+ // NOTE: It can run in probing mode when `this.mc' is null
//
public bool CheckAll (MemberSpec context, TypeSpec[] targs, TypeParameterSpec[] tparams, Location loc)
{
for (int i = 0; i < tparams.Length; i++) {
- if (ignore_inferred_dynamic && targs[i].BuiltinType == BuiltinTypeSpec.Type.Dynamic)
- continue;
-
var targ = targs[i];
if (!CheckConstraint (context, targ, tparams [i], loc))
return false;
// Check the class constraint
//
if (tparam.HasTypeConstraint) {
- var dep = tparam.BaseType.GetMissingDependencies ();
- if (dep != null) {
- if (mc == null)
- return false;
-
- ImportedTypeDefinition.Error_MissingDependency (mc, dep, loc);
- ok = false;
- }
-
if (!CheckConversion (mc, context, atype, tparam, tparam.BaseType, loc)) {
if (mc == null)
return false;
//
if (tparam.Interfaces != null) {
foreach (TypeSpec iface in tparam.Interfaces) {
- var dep = iface.GetMissingDependencies ();
- if (dep != null) {
- if (mc == null)
- return false;
-
- ImportedTypeDefinition.Error_MissingDependency (mc, dep, loc);
- ok = false;
-
- // return immediately to avoid duplicate errors because we are scanning
- // expanded interface list
- return false;
- }
-
if (!CheckConversion (mc, context, atype, tparam, iface, loc)) {
if (mc == null)
return false;
return true;
}
- //
- // When partial/full type inference finds a dynamic type argument delay
- // the constraint check to runtime, it can succeed for real underlying
- // dynamic type
- //
- if (ignore_inferred_dynamic && HasDynamicTypeArgument (ttype.TypeArguments))
- return true;
-
if (mc != null) {
mc.Module.Compiler.Report.SymbolRelatedToPreviousError (tparam);
if (atype.IsGenericParameter) {
return false;
}
- bool HasDefaultConstructor (TypeSpec atype)
+ static bool HasDefaultConstructor (TypeSpec atype)
{
var tp = atype as TypeParameterSpec;
if (tp != null) {
Upper = 2
}
- protected class BoundInfo : IEquatable<BoundInfo>
+ struct BoundInfo : IEquatable<BoundInfo>
{
public readonly TypeSpec Type;
public readonly BoundKind Kind;
return Type.GetHashCode ();
}
- public virtual Expression GetTypeExpression ()
+ public Expression GetTypeExpression ()
{
return new TypeExpression (Type, Location.Null);
}
#region IEquatable<BoundInfo> Members
- public virtual bool Equals (BoundInfo other)
+ public bool Equals (BoundInfo other)
{
return Type == other.Type && Kind == other.Kind;
}
AddToBounds (new BoundInfo (type, BoundKind.Lower), 0);
}
- protected void AddToBounds (BoundInfo bound, int index)
+ void AddToBounds (BoundInfo bound, int index)
{
//
// Some types cannot be used as type arguments
for (int i = 0; i < ga_u.Length; ++i)
score += ExactInference (ga_u [i], ga_v [i]);
- return score > 0 ? 1 : 0;
+ return System.Math.Min (1, score);
}
// If V is one of the unfixed type arguments