private bool InferConstructedType(IType formalType, IType actualType, TypeInference inference) { // look for a single occurance of the formal // constructed type in the actual type's hierarchy IType constructedActualType = GenericsServices.FindConstructedType( actualType, formalType.ConstructedInfo.GenericDefinition); if (constructedActualType == null) { return(false); } // Exact inference requires the constructed occurance to be // the actual type itself if (inference == TypeInference.Exact && actualType != constructedActualType) { return(false); } for (int i = 0; i < formalType.ConstructedInfo.GenericArguments.Length; ++i) { bool inferenceSuccessful = Infer( formalType.ConstructedInfo.GenericArguments[i], constructedActualType.ConstructedInfo.GenericArguments[i], TypeInference.Exact); // Generic arguments must match exactly, no variance allowed if (!inferenceSuccessful) { return(false); } } return(true); }
/// <summary> /// Maps a type involving generic parameters to the corresponding type after substituting concrete /// arguments for generic parameters. /// </summary> /// <remarks> /// If the source type is a generic parameter, it is mapped to the corresponding argument. /// If the source type is an open generic type using any of the specified generic parameters, it /// is mapped to a closed constructed type based on the specified arguments. /// </remarks> override public IType MapType(IType sourceType) { if (sourceType == _genericSource) { return(_constructedOwner as IType); } IGenericParameter gp = sourceType as IGenericParameter; if (gp != null) { // Map type parameters declared on our source if (_map.ContainsKey(gp)) { return(_map[gp]); } // Map type parameters declared on members of our source (methods / nested types) return(GenericsServices.GetGenericParameters(Map(gp.DeclaringEntity))[gp.GenericParameterPosition]); } // TODO: Map nested types // GenericType[of T].NestedType => GenericType[of int].NestedType return(base.MapType(sourceType)); }
private bool IsGenericDefinition(IEntity definition) { if (GenericsServices.IsGenericMethod(definition) || GenericsServices.IsGenericType(definition)) { return(true); } Errors.Add(CompilerErrorFactory.NotAGenericDefinition(ConstructionNode, definition.FullName)); return(false); }
private bool IsFullyConstructed() { foreach (IType arg in GenericArguments) { if (GenericsServices.IsOpenGenericType(arg)) { return(false); } } return(true); }
private IEnumerable <IGenericParameter> FindGenericParameters(IType type) { foreach (IGenericParameter gp in GenericsServices.FindGenericParameters(type)) { if (!InferredTypes.ContainsKey(gp)) { continue; } yield return(gp); } }
private bool HasCorrectGenerity(IEntity definition) { IGenericParameter[] typeParameters = GenericsServices.GetGenericParameters(definition); if (typeParameters.Length != TypeArguments.Length) { Errors.Add(CompilerErrorFactory.GenericDefinitionArgumentCount(ConstructionNode, definition, typeParameters.Length)); return(false); } return(true); }
private bool MaintainsParameterConstraints(IEntity definition) { IGenericParameter[] parameters = GenericsServices.GetGenericParameters(definition); _definition = definition as IType; bool valid = true; for (int i = 0; i < parameters.Length; i++) { valid &= MaintainsParameterConstraints(parameters[i], TypeArguments[i]); } return(valid); }
private bool HasCorrectGenerity(IEntity definition) { IGenericParameter[] typeParameters = GenericsServices.GetGenericParameters(definition); if (typeParameters.Length != TypeArguments.Length) { var error = CompilerErrorFactory.GenericDefinitionArgumentCount(ConstructionNode, definition, typeParameters.Length); var internalType = definition as IInternalEntity; if (internalType != null) { var node = internalType.Node; var replacementNode = node["TypeRefReplacement"] as GenericReferenceExpression; if (replacementNode != null && replacementNode.GenericArguments.Count == typeParameters.Length) { error.Data["TypeRefReplacement"] = replacementNode.CloneNode(); throw error; } } Errors.Add(error); return(false); } return(true); }
protected bool IsFullyConstructed() { return(GenericsServices.GetTypeGenerity(this) == 0); }