From dea12ad837dfe2b2f63b875b07196a8875a4dfc6 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 4 Nov 2016 18:34:24 +0100 Subject: [mcs] Consider method candidates with misplaced named arguments not applicable. Fixes #46190 --- mcs/errors/cs1744-3.cs | 18 ++++++++++++++++++ mcs/mcs/ecore.cs | 2 +- mcs/tests/test-named-10.cs | 18 ++++++++++++++++++ mcs/tests/ver-il-net_4_x.xml | 16 ++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 mcs/errors/cs1744-3.cs create mode 100644 mcs/tests/test-named-10.cs diff --git a/mcs/errors/cs1744-3.cs b/mcs/errors/cs1744-3.cs new file mode 100644 index 00000000000..b899816d213 --- /dev/null +++ b/mcs/errors/cs1744-3.cs @@ -0,0 +1,18 @@ +// CS1744: Named argument `p1' cannot be used for a parameter which has positional argument specified +// Line: 8 + +internal class Program +{ + public static void Main () + { + Method (1, 2, p1: 3); + } + + static void Method (int p1, int paramNamed, int p2) + { + } + + static void Method (int p1, int p2, object paramNamed) + { + } +} diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs index edc860eca83..39ee29f1c5d 100644 --- a/mcs/mcs/ecore.cs +++ b/mcs/mcs/ecore.cs @@ -5050,7 +5050,7 @@ namespace Mono.CSharp { // The slot has been taken by positional argument if (temp != null && !(temp is NamedArgument)) - break; + return NamedArgumentsMismatch - i - 1; } if (!arg_moved) { diff --git a/mcs/tests/test-named-10.cs b/mcs/tests/test-named-10.cs new file mode 100644 index 00000000000..6434c836612 --- /dev/null +++ b/mcs/tests/test-named-10.cs @@ -0,0 +1,18 @@ +using System; + +internal class Program +{ + public static void Main () + { + Method (1, 2, paramNamed: 3); + } + + static void Method (int p1, int paramNamed, int p2) + { + throw new ApplicationException (); + } + + static void Method (int p1, int p2, object paramNamed) + { + } +} diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index 3bf44ceb436..f9c8f8b2465 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -70068,6 +70068,22 @@ + + + + 15 + + + 7 + + + 2 + + + 7 + + + -- cgit v1.2.3