private NamedTupleSpec(InflatedTypeSpec tupleDefinition, IList <string> elements) : base(tupleDefinition.Kind, tupleDefinition.DeclaringType, tupleDefinition.MemberDefinition, null, tupleDefinition.Modifiers) { tuple = tupleDefinition; this.elements = elements; state |= StateFlags.HasNamedTupleElement | StateFlags.Tuple; }
static bool CheckType(TypeSpec ret, TypeContainer parent, out TypeSpec original_iterator_type, out bool is_enumerable) { original_iterator_type = null; is_enumerable = false; if (ret.BuiltinType == BuiltinTypeSpec.Type.IEnumerable) { original_iterator_type = parent.Compiler.BuiltinTypes.Object; is_enumerable = true; return(true); } if (ret.BuiltinType == BuiltinTypeSpec.Type.IEnumerator) { original_iterator_type = parent.Compiler.BuiltinTypes.Object; is_enumerable = false; return(true); } InflatedTypeSpec inflated = ret as InflatedTypeSpec; if (inflated == null) { return(false); } var member_definition = inflated.MemberDefinition; PredefinedType ptype = parent.Module.PredefinedTypes.IEnumerableGeneric; if (ptype.Define() && ptype.TypeSpec.MemberDefinition == member_definition) { original_iterator_type = inflated.TypeArguments[0]; is_enumerable = true; return(true); } ptype = parent.Module.PredefinedTypes.IEnumeratorGeneric; if (ptype.Define() && ptype.TypeSpec.MemberDefinition == member_definition) { original_iterator_type = inflated.TypeArguments[0]; is_enumerable = false; return(true); } return(false); }
bool OverloadResolver.IErrorHandler.TypeInferenceFailed(ResolveContext rc, MemberSpec best) { var ms = (MethodSpec)best; TypeSpec source_type = ms.Parameters.ExtensionMethodType; if (source_type != null) { Argument a = arguments[0]; if (TypeManager.IsGenericType(source_type) && InflatedTypeSpec.ContainsTypeParameter(source_type)) { TypeInferenceContext tic = new TypeInferenceContext(source_type.TypeArguments); tic.OutputTypeInference(rc, a.Expr, source_type); if (tic.FixAllTypes(rc)) { source_type = source_type.GetDefinition().MakeGenericType(rc, tic.InferredTypeArguments); } } if (!Convert.ImplicitConversionExists(rc, a.Expr, source_type)) { rc.Report.Error(1936, loc, "An implementation of `{0}' query expression pattern for source type `{1}' could not be found", best.Name, a.Type.GetSignatureForError()); return(true); } } if (best.Name == "SelectMany") { rc.Report.Error(1943, loc, "An expression type is incorrect in a subsequent `from' clause in a query expression with source type `{0}'", arguments[0].GetSignatureForError()); } else { rc.Report.Error(1942, loc, "An expression type in `{0}' clause is incorrect. Type inference failed in the call to `{1}'", best.Name.ToLowerInvariant(), best.Name); } return(true); }
static bool CheckType(TypeSpec ret, out TypeSpec original_iterator_type, out bool is_enumerable) { original_iterator_type = null; is_enumerable = false; if (ret == TypeManager.ienumerable_type) { original_iterator_type = TypeManager.object_type; is_enumerable = true; return(true); } if (ret == TypeManager.ienumerator_type) { original_iterator_type = TypeManager.object_type; is_enumerable = false; return(true); } InflatedTypeSpec inflated = ret as InflatedTypeSpec; if (inflated == null) { return(false); } ret = inflated.GetDefinition(); if (ret == TypeManager.generic_ienumerable_type) { original_iterator_type = inflated.TypeArguments[0]; is_enumerable = true; return(true); } if (ret == TypeManager.generic_ienumerator_type) { original_iterator_type = inflated.TypeArguments[0]; is_enumerable = false; return(true); } return(false); }
public InflatedTypeSpec MakeGenericType(IModuleContext context, TypeSpec[] targs) { if (targs.Length == 0 && !IsNested) { throw new ArgumentException("Empty type arguments for type " + GetSignatureForError()); } InflatedTypeSpec instance; if (inflated_instances == null) { inflated_instances = new Dictionary <TypeSpec[], InflatedTypeSpec> (TypeSpecComparer.Default); if (IsNested) { instance = this as InflatedTypeSpec; if (instance != null) { // // Nested types could be inflated on already inflated instances // Caching this type ensured we are using same instance for // inside/outside inflation using local type parameters // inflated_instances.Add(TypeArguments, instance); } } } if (!inflated_instances.TryGetValue(targs, out instance)) { if (GetDefinition() != this && !IsNested) { throw new InternalErrorException("`{0}' must be type definition or nested non-inflated type to MakeGenericType", GetSignatureForError()); } instance = new InflatedTypeSpec(context, this, declaringType, targs); inflated_instances.Add(targs, instance); } return(instance); }
public static NamedTupleSpec MakeType(ModuleContainer module, InflatedTypeSpec tupleType, IList <string> names) { // TODO: cache it return(new NamedTupleSpec(tupleType, names)); }