+2004-05-30 Ben Maurer <bmaurer@users.sourceforge.net>
+
+ * expression.cs:
+ According to the spec,
+
+ In a member access of the form E.I, if E is a single identifier,
+ and if the meaning of E as a simple-name (§7.5.2) is a constant,
+ field, property, localvariable, or parameter with the same type as
+ the meaning of E as a type-name (§3.8), then both possible
+ meanings of E are permitted.
+
+ We did not check that E as a simple-name had the same type as E as
+ a type name.
+
+ This trivial check gives us 5-7% on bootstrap time.
+
2004-05-30 Marek Safar <marek.safar@seznam.cz>
Fixed bug #59071 & cs0160.cs
"type name instead");
}
- static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, Location loc)
+ static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, Expression left, Location loc)
{
- if (left_original == null)
+ SimpleName sn = left_original as SimpleName;
+ if (sn == null || left == null || left.Type.Name != sn.Name)
return false;
- if (!(left_original is SimpleName))
- return false;
-
- SimpleName sn = (SimpleName) left_original;
-
- Type t = RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc);
- if (t != null)
- return true;
-
- return false;
+ return RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc) != null;
}
public static Expression ResolveMemberAccess (EmitContext ec, Expression member_lookup,
if (decl_type.IsSubclassOf (TypeManager.enum_type)) {
if (left_is_explicit && !left_is_type &&
- !IdenticalNameAndTypeName (ec, left_original, loc)) {
+ !IdenticalNameAndTypeName (ec, left_original, member_lookup, loc)) {
error176 (loc, fe.FieldInfo.Name);
return null;
}
if (!me.IsStatic){
if ((ec.IsFieldInitializer || ec.IsStatic) &&
- IdenticalNameAndTypeName (ec, left_original, loc))
+ IdenticalNameAndTypeName (ec, left_original, member_lookup, loc))
return member_lookup;
-
+
SimpleName.Error_ObjectRefRequired (ec, loc, me.Name);
return null;
}
} else {
- if (!me.IsInstance){
- if (IdenticalNameAndTypeName (ec, left_original, loc))
+ if (!me.IsInstance) {
+ if (IdenticalNameAndTypeName (ec, left_original, left, loc))
return member_lookup;
if (left_is_explicit) {
error176 (loc, me.Name);
return null;
}
- }
+ }
//
// Since we can not check for instance objects in SimpleName,
}
}
- if ((mg != null) && IdenticalNameAndTypeName (ec, left_original, loc))
+ if ((mg != null) && IdenticalNameAndTypeName (ec, left_original, left, loc))
mg.IdenticalTypeName = true;
me.InstanceExpression = left;