+2009-08-13 Marek Safar <marek.safar@gmail.com>
+
+ * decl.cs, namespace.cs, ecore.cs, class.cs, attribute.cs,
+ codegen.cs: Add IResolveContext::LookupTypeParameter.
+
2009-08-13 Marek Safar <marek.safar@gmail.com>
* lambda.cs, expression.cs, statement.cs, namespace.cs, ecore.cs:
"expression or array creation expression");
}
- static void Error_TypeParameterInAttribute (Location loc)
- {
- Report.Error (
- -202, loc, "Can not use a type parameter in an attribute");
- }
-
public void Error_MissingGuidAttribute ()
{
Report.Error (596, Location, "The Guid attribute must be specified with the ComImport attribute");
}
}
- DeclSpace ds = context.GenericDeclContainer;
+ DeclSpace ds = context.GenericDeclContainer;
EmitContext ec = new EmitContext (context, ds, ds,
Location, null, typeof (Attribute), ds.ModFlags, false);
ec.IsAnonymousMethodAllowed = false;
return false;
}
- if (a.Expr is TypeParameterExpr){
- Error_TypeParameterInAttribute (Location);
- return false;
- }
-
ObsoleteAttribute obsolete_attr;
if (member is PropertyExpr) {
return tc.Parent.LookupNamespaceOrType (name, loc, ignore_cs0104);
}
+ public Type LookupTypeParameter (string name)
+ {
+ return tc.PartialContainer.LookupTypeParameter (name);
+ }
+
public DeclSpace GenericDeclContainer {
get { return tc.GenericDeclContainer; }
}
if (base_class == TypeManager.system_object_expr)
base_class = new_base_class;
else {
- if (new_base_class != null && !new_base_class.Equals (base_class)) {
+ if (new_base_class != null && !TypeManager.IsEqual (new_base_class.Type, base_class.Type)) {
Report.SymbolRelatedToPreviousError (base_class.Location, "");
Report.Error (263, part.Location,
"Partial declarations of `{0}' must not specify different base classes",
protected bool DefineParameters (ParametersCompiled parameters)
{
- IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
-
- if (!parameters.Resolve (rc))
+ if (!parameters.Resolve (this))
return false;
bool error = false;
return mi;
}
+ public override Type LookupTypeParameter (string name)
+ {
+ if (GenericMethod != null) {
+ Type t = GenericMethod.LookupTypeParameter (name);
+ if (t != null)
+ return t;
+ }
+
+ return base.LookupTypeParameter (name);
+ }
+
public void SetPartialDefinition (Method methodDefinition)
{
caching_flags |= Flags.PartialDefinitionExists;
bool IsInUnsafeScope { get; }
FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104);
+ Type LookupTypeParameter (string name);
// the declcontainer to lookup for type-parameters. Should only use LookupGeneric on it.
//
return ResolveContext.LookupNamespaceOrType (name, loc, ignore_cs0104);
}
+ public Type LookupTypeParameter (string name)
+ {
+ return ResolveContext.LookupTypeParameter (name);
+ }
+
#endregion
}
return RootContext.ToplevelTypes.LookupNamespaceOrType (name, loc, ignore_cs0104);
}
+ public Type LookupTypeParameter (string name)
+ {
+ return null;
+ }
+
#endregion
}
return Parent.LookupNamespaceOrType (name, loc, ignore_cs0104);
}
+ public virtual Type LookupTypeParameter (string name)
+ {
+ return Parent.LookupTypeParameter (name);
+ }
+
/// <summary>
/// Goes through class hierarchy and gets value of first found CLSCompliantAttribute.
/// If no is attribute exists then assembly CLSCompliantAttribute is returned.
if (TypeManager.HasElementType (check_type))
return CheckAccessLevel (TypeManager.GetElementType (check_type));
+ if (TypeManager.IsGenericParameter (check_type))
+ return true;
+
TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
switch (check_attr){
return e;
}
+ public override Type LookupTypeParameter (string name)
+ {
+ if (type_params != null) {
+ Type t = LookupLocalTypeParameter (name);
+ if (t != null)
+ return t;
+ }
+
+ if (Parent != null)
+ return Parent.LookupTypeParameter (name);
+
+ return null;
+ }
+
+ Type LookupLocalTypeParameter (string name)
+ {
+ foreach (var tp in CurrentTypeParameters) {
+ if (tp.Name == name)
+ return tp.Type;
+ }
+
+ return null;
+ }
+
/// <remarks>
/// This function is broken and not what you're looking for. It should only
/// be used while the type is still being created since it doesn't use the cache
}
}
- public TypeParameterExpr LookupGeneric (string name, Location loc)
- {
- if (!IsGeneric)
- return null;
-
- TypeParameter [] current_params;
- if (this is TypeContainer)
- current_params = PartialContainer.CurrentTypeParameters;
- else
- current_params = CurrentTypeParameters;
-
- foreach (TypeParameter type_param in current_params) {
- if (type_param.Name == name)
- return new TypeParameterExpr (type_param, loc);
- }
-
- if (Parent != null)
- return Parent.LookupGeneric (name, loc);
-
- return null;
- }
-
// Used for error reporting only
public virtual Type LookupAnyGeneric (string typeName)
{
GenericTypeExpr ct = te as GenericTypeExpr;
if (ct != null) {
- // Skip constrains check for overrides and explicit implementations
- // TODO: they should use different overload
- GenericMethod gm = ec.GenericDeclContainer as GenericMethod;
+ //
+ // TODO: Constrained type parameters check for parameters of generic method overrides is broken
+ // There are 2 solutions.
+ // 1, Skip this check completely when we are in override/explicit impl scope
+ // 2, Copy type parameters constraints from base implementation and pass (they have to be emitted anyway)
+ //
+ MemberCore gm = ec as GenericMethod;
+ if (gm == null)
+ gm = ec as Method;
if (gm != null && ((gm.ModFlags & Modifiers.OVERRIDE) != 0 || gm.MemberName.Left != null)) {
te.loc = loc;
return te;
public override FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
{
- FullNamedExpression fne = ec.GenericDeclContainer.LookupGeneric (Name, loc);
- if (fne != null)
- return fne.ResolveAsTypeStep (ec, silent);
+ Type t = ec.LookupTypeParameter (Name);
+ if (t != null)
+ return new TypeParameterExpr (TypeManager.LookupTypeParameter (t), loc).ResolveAsTypeStep (ec, false);
int errors = Report.Errors;
- fne = ec.LookupNamespaceOrType (Name, loc, /*ignore_cs0104=*/ false);
+ FullNamedExpression fne = ec.LookupNamespaceOrType (Name, loc, /*ignore_cs0104=*/ false);
if (fne != null) {
if (fne.Type == null)
return resolved;
}
+ public Type LookupTypeParameter (string name)
+ {
+ return null;
+ }
+
public ICollection CompletionGetTypesStartingWith (DeclSpace ds, string prefix)
{
Hashtable result = new Hashtable ();