Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2018-01-11 16:52:00 +0300
committerMarek Safar <marek.safar@gmail.com>2018-01-15 19:59:44 +0300
commit46bb11eb337dd5cf951796265c00d1adf4b43d78 (patch)
tree818bc6b0ff614d4a53bf09430ac2aa4f34ea0695 /mcs
parent5929e348e940ed1b433eb112d90a63394301a624 (diff)
[mcs] C# 7.2 non-trailing named arguments
Diffstat (limited to 'mcs')
-rw-r--r--mcs/errors/cs1738-2.cs2
-rw-r--r--mcs/errors/cs1738-3.cs2
-rw-r--r--mcs/errors/cs1738.cs2
-rw-r--r--mcs/mcs/cs-parser.jay10
-rw-r--r--mcs/mcs/dynamic.cs6
-rw-r--r--mcs/mcs/ecore.cs12
-rw-r--r--mcs/tests/test-named-11.cs13
-rw-r--r--mcs/tests/ver-il-net_4_x.xml13
8 files changed, 49 insertions, 11 deletions
diff --git a/mcs/errors/cs1738-2.cs b/mcs/errors/cs1738-2.cs
index f59221f4c7a..44b3f6d1b14 100644
--- a/mcs/errors/cs1738-2.cs
+++ b/mcs/errors/cs1738-2.cs
@@ -1,4 +1,4 @@
-// CS1738: Named arguments must appear after the positional arguments
+// CS1738: Named arguments must appear after the positional arguments when using language version older than 7.2
// Line: 13
using System;
diff --git a/mcs/errors/cs1738-3.cs b/mcs/errors/cs1738-3.cs
index 53c4efc3553..901ac0e5d59 100644
--- a/mcs/errors/cs1738-3.cs
+++ b/mcs/errors/cs1738-3.cs
@@ -1,4 +1,4 @@
-// CS1738: Named arguments must appear after the positional arguments
+// CS1738: Named arguments must appear after the positional arguments when using language version older than 7.2
// Line: 14
class C
diff --git a/mcs/errors/cs1738.cs b/mcs/errors/cs1738.cs
index dab9a61160b..537bc17b917 100644
--- a/mcs/errors/cs1738.cs
+++ b/mcs/errors/cs1738.cs
@@ -1,4 +1,4 @@
-// CS1738: Named arguments must appear after the positional arguments
+// CS1738: Named arguments must appear after the positional arguments when using language version older than 7.2
// Line: 12
class C
diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay
index e33d869d563..e2118a23f0f 100644
--- a/mcs/mcs/cs-parser.jay
+++ b/mcs/mcs/cs-parser.jay
@@ -865,7 +865,7 @@ attribute_arguments
}
Arguments args = ((Arguments) o [0]);
- if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
+ if (lang_version < LanguageVersion.V_7_2 && args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
args.Add ((Argument) $3);
@@ -3856,7 +3856,7 @@ argument_list
| argument_list COMMA argument
{
Arguments list = (Arguments) $1;
- if (list [list.Count - 1] is NamedArgument)
+ if (lang_version < LanguageVersion.V_7_2 && list [list.Count - 1] is NamedArgument)
Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
list.Add ((Argument) $3);
@@ -4001,7 +4001,7 @@ expression_list_arguments
| expression_list_arguments COMMA expression_list_argument
{
Arguments args = (Arguments) $1;
- if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
+ if (lang_version < LanguageVersion.V_7_2 && args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
args.Add ((Argument) $3);
@@ -4792,7 +4792,7 @@ pattern_list
| pattern_list COMMA pattern_argument
{
Arguments args = (Arguments) $1;
- if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
+ if (lang_version < LanguageVersion.V_7_2 && args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
args.Add ((Argument) $3);
@@ -7795,7 +7795,7 @@ void Warning_EmptyStatement (Location loc)
void Error_NamedArgumentExpected (NamedArgument a)
{
- report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
+ report.Error (1738, a.Location, "Named arguments must appear after the positional arguments when using language version older than 7.2");
}
void Error_MissingInitializer (Location loc)
diff --git a/mcs/mcs/dynamic.cs b/mcs/mcs/dynamic.cs
index 32f361ba96a..f8314b2f3cd 100644
--- a/mcs/mcs/dynamic.cs
+++ b/mcs/mcs/dynamic.cs
@@ -279,6 +279,7 @@ namespace Mono.CSharp
protected bool DoResolveCore (ResolveContext rc)
{
+ int i = 0;
foreach (var arg in arguments) {
if (arg.Type == InternalType.VarOutType) {
// Should be special error message about dynamic dispatch
@@ -286,6 +287,11 @@ namespace Mono.CSharp
} else if (arg.Type == InternalType.DefaultType) {
rc.Report.Error (8311, arg.Expr.Location, "Cannot use a default literal as an argument to a dynamically dispatched operation");
}
+
+ // Forced limitation because Microsoft.CSharp needs to catch up
+ if (i > 0 && arguments [i - 1] is NamedArgument && !(arguments [i] is NamedArgument))
+ rc.Report.Error (8324, loc, "Named argument specifications must appear after all fixed arguments have been specified in a dynamic invocation");
+ ++i;
}
if (rc.CurrentTypeParameters != null && rc.CurrentTypeParameters[0].IsMethodTypeParameter)
diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs
index 4f7c6144cfa..9b40d8a2399 100644
--- a/mcs/mcs/ecore.cs
+++ b/mcs/mcs/ecore.cs
@@ -6084,9 +6084,15 @@ namespace Mono.CSharp {
else
ec.Report.SymbolRelatedToPreviousError (member);
- ec.Report.Error (1744, na.Location,
- "Named argument `{0}' cannot be used for a parameter which has positional argument specified",
- na.Name);
+ if (name_index > a_idx) {
+ ec.Report.Error (8323, na.Location,
+ "Named argument `{0}' is used out of position but is followed by positional argument",
+ na.Name);
+ } else {
+ ec.Report.Error (1744, na.Location,
+ "Named argument `{0}' cannot be used for a parameter which has positional argument specified",
+ na.Name);
+ }
}
}
diff --git a/mcs/tests/test-named-11.cs b/mcs/tests/test-named-11.cs
new file mode 100644
index 00000000000..a01d2883b9c
--- /dev/null
+++ b/mcs/tests/test-named-11.cs
@@ -0,0 +1,13 @@
+// Compiler options: -langversion:7.2
+
+class X
+{
+ public static void Main ()
+ {
+ Test (arg: 1, "");
+ }
+
+ static void Test (int arg, string str)
+ {
+ }
+} \ No newline at end of file
diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml
index 8f37458a29d..78e6782767e 100644
--- a/mcs/tests/ver-il-net_4_x.xml
+++ b/mcs/tests/ver-il-net_4_x.xml
@@ -70869,6 +70869,19 @@
</method>
</type>
</test>
+ <test name="test-named-11.cs">
+ <type name="X">
+ <method name="Void Main()" attrs="150">
+ <size>13</size>
+ </method>
+ <method name="Void Test(Int32, System.String)" attrs="145">
+ <size>2</size>
+ </method>
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ </test>
<test name="test-nameof-01.cs">
<type name="X">
<method name="Int32 Main()" attrs="150">