--- /dev/null
+// CS0103: The name `nameof' does not exist in the current context
+// Line: 8
+
+static class C
+{
+ static void Main ()
+ {
+ string s = nameof (nameof);
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS7003: Unbound generic name is not valid in this context
+// Line: 8
+
+class C
+{
+ static void Main ()
+ {
+ System.Action<>.Combine ();
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS7003: Unbound generic name is not valid in this context
+// Line: 12
+
+static class C
+{
+ static void Foo<T> ()
+ {
+ }
+
+ static void Main ()
+ {
+ string s = nameof (Foo<>);
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS7003: Unbound generic name is not valid in this context
+// Line: 12
+
+static class C
+{
+ static void Foo<T> ()
+ {
+ }
+
+ static void Main ()
+ {
+ string s = nameof (C.Foo<>);
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS8081: Expression does not have a name
+// Line: 8
+
+class C
+{
+ void Foo ()
+ {
+ string s = nameof (this);
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS8081: Expression does not have a name
+// Line: 8
+
+class C
+{
+ static void Main ()
+ {
+ string s = nameof (Main ());
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS8082: An argument to nameof operator cannot include sub-expression
+// Line: 9
+
+class C
+{
+ void Foo ()
+ {
+ object o = null;
+ var s = nameof (o.ToString ().Equals);
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS8083: An alias-qualified name is not an expression
+// Line: 8
+
+class C
+{
+ static void Main ()
+ {
+ string s = nameof (global::C);
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS8084: An argument to nameof operator cannot be method group with type arguments
+// Line: 12
+
+static class C
+{
+ static void Foo<T> ()
+ {
+ }
+
+ static void Main ()
+ {
+ string s = nameof (C.Foo<int>);
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS8084: An argument to nameof operator cannot be method group with type arguments
+// Line: 12
+
+static class C
+{
+ static void Foo<T> ()
+ {
+ }
+
+ static void Main ()
+ {
+ string s = nameof (Foo<int>);
+ }
+}
\ No newline at end of file
}
if (targs != null) {
- if (!targs.Resolve (rc))
+ if (!targs.Resolve (rc, true))
return null;
}
this.name = name;
}
+ static void Error_MethodGroupWithTypeArguments (ResolveContext rc, Location loc)
+ {
+ rc.Report.Error (8084, loc, "An argument to nameof operator cannot be method group with type arguments");
+ }
+
protected override Expression DoResolve (ResolveContext rc)
{
throw new NotSupportedException ();
if (rc.Module.Compiler.Settings.Version < LanguageVersion.V_6)
rc.Report.FeatureIsNotAvailable (rc.Module.Compiler, Location, "nameof operator");
- sn.LookupNameExpression (rc, MemberLookupRestrictions.IgnoreAmbiguity);
+ var res = sn.LookupNameExpression (rc, MemberLookupRestrictions.IgnoreAmbiguity | MemberLookupRestrictions.NameOfExcluded);
+ if (sn.HasTypeArguments && res is MethodGroupExpr) {
+ Error_MethodGroupWithTypeArguments (rc, expr.Location);
+ }
+
return true;
}
var ma = expr as MemberAccess;
if (ma != null) {
+ var lexpr = ma.LeftExpression;
+
var res = ma.LookupNameExpression (rc, MemberLookupRestrictions.IgnoreAmbiguity);
- if (res == null)
+ if (res == null) {
return false;
+ }
if (rc.Module.Compiler.Settings.Version < LanguageVersion.V_6)
rc.Report.FeatureIsNotAvailable (rc.Module.Compiler, Location, "nameof operator");
+ if (ma is QualifiedAliasMember) {
+ rc.Report.Error (8083, loc, "An alias-qualified name is not an expression");
+ return false;
+ }
+
+ if (!IsLeftExpressionValid (lexpr)) {
+ rc.Report.Error (8082, lexpr.Location, "An argument to nameof operator cannot include sub-expression");
+ return false;
+ }
+
var mg = res as MethodGroupExpr;
if (mg != null) {
var emg = res as ExtensionMethodGroupExpr;
if (!mg.HasAccessibleCandidate (rc)) {
ErrorIsInaccesible (rc, ma.GetSignatureForError (), loc);
}
+
+ if (ma.HasTypeArguments) {
+ Error_MethodGroupWithTypeArguments (rc, ma.Location);
+ }
}
Value = ma.Name;
return true;
}
+ rc.Report.Error (8081, loc, "Expression does not have a name");
+ return false;
+ }
+
+ static bool IsLeftExpressionValid (Expression expr)
+ {
+ if (expr is SimpleName)
+ return true;
+
+ if (expr is This)
+ return true;
+
+ if (expr is NamespaceExpression)
+ return true;
+
+ if (expr is TypeExpr)
+ return true;
+
+ var ma = expr as MemberAccess;
+ if (ma != null) {
+ // TODO: Will conditional access be allowed?
+ return IsLeftExpressionValid (ma.LeftExpression);
+ }
+
return false;
}
var arg = args [0];
var res = ResolveArgumentExpression (rc, arg.Expr);
if (!res) {
- name.Error_NameDoesNotExist (rc);
return null;
}
Error_SyntaxError (yyToken);
$$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
}
+/*
| CASE pattern_expr_invocation COLON
{
if (lang_version != LanguageVersion.Experimental)
};
lbag.AddLocation ($$, GetLocation ($3));
}
+*/
| DEFAULT_COLON
{
$$ = new SwitchLabel (null, GetLocation ($1));
if (member != null && member.HasTypeArguments) {
TypeArguments ta = member.TypeArguments;
- if (ta.Resolve (ec)) {
+ if (ta.Resolve (ec, false)) {
var targs = new ArrayInitializer (ta.Count, loc);
foreach (TypeSpec t in ta.Arguments)
targs.Add (new TypeOf (t, loc));
ReadAccess = 1 << 3,
EmptyArguments = 1 << 4,
IgnoreArity = 1 << 5,
- IgnoreAmbiguity = 1 << 6
+ IgnoreAmbiguity = 1 << 6,
+ NameOfExcluded = 1 << 7,
}
//
}
protected ATypeNameExpression (string name, int arity, Location l)
- : this (name, new UnboundTypeArguments (arity), l)
+ : this (name, new UnboundTypeArguments (arity, l), l)
{
}
(targs == null || targs.Equals (atne.targs));
}
- protected void Error_OpenGenericTypeIsNotAllowed (IMemberContext mc)
- {
- mc.Module.Compiler.Report.Error (7003, Location, "Unbound generic name is not valid in this context");
- }
-
public override int GetHashCode ()
{
return Name.GetHashCode ();
return ct;
}
- if (!allowUnboundTypeArguments)
- Error_OpenGenericTypeIsNotAllowed (mc);
+ targs.Resolve (mc, allowUnboundTypeArguments);
return new GenericOpenTypeExpr (fne.Type, loc);
}
me = me.ResolveMemberAccess (rc, null, null);
if (Arity > 0) {
- targs.Resolve (rc);
+ targs.Resolve (rc, false);
me.SetTypeArguments (rc, targs);
}
var mg = NamespaceContainer.LookupStaticUsings (rc, Name, Arity, loc);
if (mg != null) {
if (Arity > 0) {
- targs.Resolve (rc);
+ targs.Resolve (rc, false);
mg.SetTypeArguments (rc, targs);
}
return mg;
}
- if (Name == "nameof")
+ if ((restrictions & MemberLookupRestrictions.NameOfExcluded) == 0 && Name == "nameof")
return new NameOf (this);
if (errorMode) {
return this;
}
- public void Error_NamespaceDoesNotExist (IMemberContext ctx, string name, int arity)
+ public void Error_NamespaceDoesNotExist (IMemberContext ctx, string name, int arity, Location loc)
{
var retval = Namespace.LookupType (ctx, name, arity, LookupMode.IgnoreAccessibility, loc);
if (retval != null) {
var retval = ns.LookupTypeOrNamespace (rc, Name, Arity, LookupMode.Normal, loc);
if (retval == null) {
- ns.Error_NamespaceDoesNotExist (rc, Name, Arity);
+ ns.Error_NamespaceDoesNotExist (rc, Name, Arity, loc);
return null;
}
- if (HasTypeArguments)
- return new GenericTypeExpr (retval.Type, targs, loc);
+ if (Arity > 0) {
+ if (HasTypeArguments)
+ return new GenericTypeExpr (retval.Type, targs, loc);
+
+ targs.Resolve (rc, false);
+ }
return retval;
}
if (methods != null) {
var emg = new ExtensionMethodGroupExpr (methods, expr, loc);
if (HasTypeArguments) {
- if (!targs.Resolve (rc))
+ if (!targs.Resolve (rc, false))
return null;
emg.SetTypeArguments (rc, targs);
me = me.ResolveMemberAccess (rc, expr, sn);
if (Arity > 0) {
- if (!targs.Resolve (rc))
+ if (!targs.Resolve (rc, false))
return null;
me.SetTypeArguments (rc, targs);
FullNamedExpression retval = ns.LookupTypeOrNamespace (rc, Name, Arity, LookupMode.Normal, loc);
if (retval == null) {
- ns.Error_NamespaceDoesNotExist (rc, Name, Arity);
+ ns.Error_NamespaceDoesNotExist (rc, Name, Arity, loc);
} else if (Arity > 0) {
if (HasTypeArguments) {
retval = new GenericTypeExpr (retval.Type, targs, loc);
if (retval.ResolveAsType (rc) == null)
return null;
} else {
- if (!allowUnboundTypeArguments)
- Error_OpenGenericTypeIsNotAllowed (rc);
+ targs.Resolve (rc, allowUnboundTypeArguments);
retval = new GenericOpenTypeExpr (retval.Type, loc);
}
if (HasTypeArguments) {
texpr = new GenericTypeExpr (nested, targs, loc);
} else {
- if (!allowUnboundTypeArguments || expr_resolved is GenericTypeExpr) // && HasTypeArguments
- Error_OpenGenericTypeIsNotAllowed (rc);
+ targs.Resolve (rc, allowUnboundTypeArguments && !(expr_resolved is GenericTypeExpr));
texpr = new GenericOpenTypeExpr (nested, loc);
}
/// <summary>
/// Resolve the type arguments.
/// </summary>
- public virtual bool Resolve (IMemberContext ec)
+ public virtual bool Resolve (IMemberContext ec, bool allowUnbound)
{
if (atypes != null)
return true;
public class UnboundTypeArguments : TypeArguments
{
- public UnboundTypeArguments (int arity)
+ Location loc;
+
+ public UnboundTypeArguments (int arity, Location loc)
: base (new FullNamedExpression[arity])
{
+ this.loc = loc;
}
public override bool IsEmpty {
}
}
- public override bool Resolve (IMemberContext ec)
+ public override bool Resolve (IMemberContext mc, bool allowUnbound)
{
+ if (!allowUnbound) {
+ mc.Module.Compiler.Report.Error (7003, loc, "Unbound generic name is not valid in this context");
+ }
+
// Nothing to be resolved
return true;
}
if (eclass != ExprClass.Unresolved)
return type;
- if (!args.Resolve (mc))
+ if (!args.Resolve (mc, allowUnboundTypeArguments))
return null;
TypeSpec[] atypes = args.Arguments;
--- /dev/null
+using System.Collections.Generic;
+
+class X
+{
+ public static int Main ()
+ {
+ switch (nameof (Dictionary<int,int>.Add)) {
+ case nameof (List<int>.Equals):
+ return 1;
+ case nameof(List<int>.Add):
+ return 0;
+ default:
+ return 2;
+ }
+ }
+}
\ No newline at end of file
if (Switch_1 (1) != 1)
return 3;
- if (Switch_1 (new C1 ()) != 3)
- return 4;
+// if (Switch_1 (new C1 ()) != 3)
+// return 4;
if (Switch_1 ((byte?) 1) != 1)
return 5;
switch (o) {
case 1:
return 1;
- case C1 (3):
- return 2;
- case C1 (2):
- return 3;
+// case C1 (3):
+// return 2;
+// case C1 (2):
+// return 3;
case null:
return 4;
default:
</method>\r
</type>\r
</test>\r
+ <test name="test-named-09.cs">\r
+ <type name="X">\r
+ <method name="Int32 Main()" attrs="150">\r
+ <size>11</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ </test>\r
<test name="test-nameof-01.cs">\r
<type name="X">\r
<method name="Int32 Main()" attrs="150">\r
<test name="test-pattern-06.cs">\r
<type name="RecursiveNamedPattern">\r
<method name="Int32 Main()" attrs="150">\r
- <size>182</size>\r
+ <size>159</size>\r
</method>\r
<method name="Int32 Switch_1(System.Object)" attrs="145">\r
- <size>149</size>\r
+ <size>53</size>\r
</method>\r
<method name="Int32 Switch_2(C1)" attrs="145">\r
<size>28</size>\r