diff options
author | Marek Safar <marek.safar@gmail.com> | 2017-09-19 16:47:31 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2017-10-02 17:23:04 +0300 |
commit | 34866ac4c20c781f10c40fe6f6fe0c39733fd946 (patch) | |
tree | 6ab6012a02e9c73da8c9dca6592854b5afaf26a3 /mcs/errors | |
parent | 120574de1935e11c7b39a0be75bb2803453ceadb (diff) |
[mcs] Initial by ref returns and variables support
Diffstat (limited to 'mcs/errors')
40 files changed, 539 insertions, 1 deletions
diff --git a/mcs/errors/cs0131-6.cs b/mcs/errors/cs0131-6.cs new file mode 100644 index 00000000000..8af3e939fbf --- /dev/null +++ b/mcs/errors/cs0131-6.cs @@ -0,0 +1,15 @@ +// CS0131: The left-hand side of an assignment must be a variable, a property or an indexer +// Line: 8 + +class X +{ + void Test () + { + Foo () = 1; + } + + static int Foo () + { + return 1; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs0199-2.cs b/mcs/errors/cs0199-2.cs new file mode 100644 index 00000000000..efad7c89367 --- /dev/null +++ b/mcs/errors/cs0199-2.cs @@ -0,0 +1,12 @@ +// CS0199: A static readonly field `X.f' cannot be passed ref or out (except in a static constructor) +// Line: 10 + +class X +{ + static readonly int f = 0; + + public static void Main () + { + ref int j = ref f; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs0206-5.cs b/mcs/errors/cs0206-5.cs new file mode 100644 index 00000000000..bd9691ffbc5 --- /dev/null +++ b/mcs/errors/cs0206-5.cs @@ -0,0 +1,12 @@ +// CS0206: A property, indexer or dynamic member access may not be passed as `ref' or `out' parameter +// Line: 10 + +class X +{ + static int P { get; set; } + + static void Main () + { + ref int rl = ref P; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs1503-17.cs b/mcs/errors/cs1503-17.cs new file mode 100644 index 00000000000..23921edc939 --- /dev/null +++ b/mcs/errors/cs1503-17.cs @@ -0,0 +1,31 @@ +// CS1503: Argument `#1' cannot convert `ref long' expression to type `ref int' +// Line: 18 + +using System; + +class X +{ + long field; + + static void Main () + { + var x = new X (); + x.Run (); + } + + void Run () + { + Test (ref Prop); + } + + static int Test (ref int y) + { + return y; + } + + ref long Prop { + get { + return ref field; + } + } +} diff --git a/mcs/errors/cs1547-13.cs b/mcs/errors/cs1547-13.cs new file mode 100644 index 00000000000..1b3f8e1c14b --- /dev/null +++ b/mcs/errors/cs1547-13.cs @@ -0,0 +1,7 @@ +// CS1547: Keyword `void' cannot be used in this context +// Line: 6 + +interface IA +{ + ref void Foo (); +} diff --git a/mcs/errors/cs1644-55.cs b/mcs/errors/cs1644-55.cs new file mode 100644 index 00000000000..58384a6f289 --- /dev/null +++ b/mcs/errors/cs1644-55.cs @@ -0,0 +1,11 @@ +// CS1644: Feature `byref locals and returns' cannot be used because it is not part of the C# 6.0 language specification +// Line: 9 +// Compiler options: -langversion:6 + +class Text +{ + static ref long Foo () + { + throw new System.NotImplementedException (); + } +} diff --git a/mcs/errors/cs1715-3.cs b/mcs/errors/cs1715-3.cs new file mode 100644 index 00000000000..d3cd5dab0f7 --- /dev/null +++ b/mcs/errors/cs1715-3.cs @@ -0,0 +1,16 @@ +// CS1715: `B.Foo': type must be `int' to match overridden member `A.Foo' +// Line: 11 + +public abstract class A +{ + public abstract ref int Foo { get; } +} + +public class B : A +{ + public override ref long Foo { + get { + throw null; + } + } +}
\ No newline at end of file diff --git a/mcs/errors/cs1764.cs b/mcs/errors/cs1764.cs index f8a89b25659..a1dd2e36d15 100644 --- a/mcs/errors/cs1764.cs +++ b/mcs/errors/cs1764.cs @@ -1,4 +1,4 @@ -// CS1764: Cannot use fixed local `p' inside an anonymous method, lambda expression or query expression +// CS1764: Cannot use fixed variable `p' inside an anonymous method, lambda expression or query expression // Line: 10 // Compiler options: -unsafe diff --git a/mcs/errors/cs8145.cs b/mcs/errors/cs8145.cs new file mode 100644 index 00000000000..cf3c5084722 --- /dev/null +++ b/mcs/errors/cs8145.cs @@ -0,0 +1,7 @@ +// CS8145: Auto-implemented properties cannot return by reference +// Line: 6 + +public class X +{ + ref string TestProp { get; } +}
\ No newline at end of file diff --git a/mcs/errors/cs8146.cs b/mcs/errors/cs8146.cs new file mode 100644 index 00000000000..758804c1df6 --- /dev/null +++ b/mcs/errors/cs8146.cs @@ -0,0 +1,7 @@ +// CS8146: `X.TestProp': property and indexer which return by reference must have a get accessor +// Line: 6 + +public class X +{ + ref string TestProp { set; } +}
\ No newline at end of file diff --git a/mcs/errors/cs8147-2.cs b/mcs/errors/cs8147-2.cs new file mode 100644 index 00000000000..a4375d2d1a5 --- /dev/null +++ b/mcs/errors/cs8147-2.cs @@ -0,0 +1,14 @@ +// CS8147: `X.this[int]': property and indexer which return by reference cannot have set accessors +// Line: 6 + +public class X +{ + ref string this [int arg] { + set { + + } + get { + + } + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8147.cs b/mcs/errors/cs8147.cs new file mode 100644 index 00000000000..a006a4d9727 --- /dev/null +++ b/mcs/errors/cs8147.cs @@ -0,0 +1,14 @@ +// CS8147: `X.TestProp': property and indexer which return by reference cannot have set accessors +// Line: 6 + +public class X +{ + ref string TestProp { + set { + + } + get { + + } + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8148-2.cs b/mcs/errors/cs8148-2.cs new file mode 100644 index 00000000000..1961026d0d2 --- /dev/null +++ b/mcs/errors/cs8148-2.cs @@ -0,0 +1,16 @@ +// CS8148: `B.Foo': must return by reference to match overridden member `A.Foo' +// Line: 11 + +public abstract class A +{ + public abstract ref int Foo { get; } +} + +public class B : A +{ + public override long Foo { + get { + throw null; + } + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8148.cs b/mcs/errors/cs8148.cs new file mode 100644 index 00000000000..1e9178945c0 --- /dev/null +++ b/mcs/errors/cs8148.cs @@ -0,0 +1,15 @@ +// CS8148: `B.Foo()': must not return by reference to match overridden member `A.Foo()' +// Line: 11 + +public abstract class A +{ + public abstract int Foo (); +} + +public class B : A +{ + public override ref int Foo () + { + + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8149-2.cs b/mcs/errors/cs8149-2.cs new file mode 100644 index 00000000000..3514769c702 --- /dev/null +++ b/mcs/errors/cs8149-2.cs @@ -0,0 +1,14 @@ +// CS8149: By-reference returns can only be used in lambda expressions that return by reference +// Line: 12 + +using System; + +class A +{ + int p; + + void Test () + { + Action a = () => ref p; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8149.cs b/mcs/errors/cs8149.cs new file mode 100644 index 00000000000..351dd54235b --- /dev/null +++ b/mcs/errors/cs8149.cs @@ -0,0 +1,12 @@ +// CS8149: By-reference returns can only be used in methods that return by reference +// Line: 10 + +class A +{ + int p; + + int Test () + { + return ref p; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8150.cs b/mcs/errors/cs8150.cs new file mode 100644 index 00000000000..fd4ef7a2db0 --- /dev/null +++ b/mcs/errors/cs8150.cs @@ -0,0 +1,12 @@ +// CS8150: By-reference return is required when method returns by reference +// Line: 10 + +class A +{ + int p; + + ref int Test () + { + return p; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8151.cs b/mcs/errors/cs8151.cs new file mode 100644 index 00000000000..934faefff7c --- /dev/null +++ b/mcs/errors/cs8151.cs @@ -0,0 +1,12 @@ +// CS8151: The return by reference expression must be of type `string' because this method returns by reference +// Line: 10 + +public class X +{ + int field; + + ref string TestMethod () + { + return ref field; + } +} diff --git a/mcs/errors/cs8152.cs b/mcs/errors/cs8152.cs new file mode 100644 index 00000000000..45546ad9d9a --- /dev/null +++ b/mcs/errors/cs8152.cs @@ -0,0 +1,14 @@ +// CS8152: `C' does not implement interface member `IA.Foo()' and the best implementing candidate `C.Foo()' return type `void' does not return by reference +// Line: 11 + +interface IA +{ + ref char Foo (); +} + +public class C : IA +{ + public void Foo () + { + } +} diff --git a/mcs/errors/cs8153.cs b/mcs/errors/cs8153.cs new file mode 100644 index 00000000000..d36f110208f --- /dev/null +++ b/mcs/errors/cs8153.cs @@ -0,0 +1,24 @@ +// CS8153: An expression tree lambda cannot contain a call to a method, property, or indexer that returns by reference +// Line: 11 + +using System; +using System.Linq.Expressions; + +class X +{ + void Foo () + { + Expression<Func<int>> e = () => Test (ref this[0]); + } + + static int Test (ref int y) + { + return y; + } + + ref int this [int y] { + get { + throw null; + } + } +} diff --git a/mcs/errors/cs8154.cs b/mcs/errors/cs8154.cs new file mode 100644 index 00000000000..ed98513e65e --- /dev/null +++ b/mcs/errors/cs8154.cs @@ -0,0 +1,12 @@ +// CS8154: The body of `TestClass.TestFunction()' cannot be an iterator block because the method returns by reference +// Line: 10 + +class TestClass +{ + int x; + + ref int TestFunction() + { + yield return x; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8155.cs b/mcs/errors/cs8155.cs new file mode 100644 index 00000000000..45d8b4e414a --- /dev/null +++ b/mcs/errors/cs8155.cs @@ -0,0 +1,16 @@ +// CS8155: Lambda expressions that return by reference cannot be converted to expression trees +// Line: 14 + +using System.Linq.Expressions; + +class TestClass +{ + static int x; + + delegate ref int D (); + + static void Main () + { + Expression<D> e = () => ref x; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8156-2.cs b/mcs/errors/cs8156-2.cs new file mode 100644 index 00000000000..7507ec475c3 --- /dev/null +++ b/mcs/errors/cs8156-2.cs @@ -0,0 +1,16 @@ +// CS8156: An expression cannot be used in this context because it may not be returned by reference +// Line: 8 + +class X +{ + int Prop { + get { + return 1; + } + } + + ref int Test () + { + return ref Prop; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8156.cs b/mcs/errors/cs8156.cs new file mode 100644 index 00000000000..fe3f6b7c987 --- /dev/null +++ b/mcs/errors/cs8156.cs @@ -0,0 +1,10 @@ +// CS8156: An expression cannot be used in this context because it may not be returned by reference +// Line: 8 + +class Test +{ + ref int Foo () + { + return ref 2; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8157.cs b/mcs/errors/cs8157.cs new file mode 100644 index 00000000000..35d700f19c4 --- /dev/null +++ b/mcs/errors/cs8157.cs @@ -0,0 +1,13 @@ +// CS8157: Cannot return `r' by reference because it was initialized to a value that cannot be returned by reference +// Line: 11 + +struct S +{ + int i; + + ref int M () + { + ref int r = ref i; + return ref r; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8160.cs b/mcs/errors/cs8160.cs new file mode 100644 index 00000000000..2b4ea42c5ab --- /dev/null +++ b/mcs/errors/cs8160.cs @@ -0,0 +1,12 @@ +// CS8160: A readonly field cannot be returned by reference +// Line: 10 + +class X +{ + readonly int f = 0; + + ref int Test () + { + return ref f; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8161.cs b/mcs/errors/cs8161.cs new file mode 100644 index 00000000000..0d028a116ed --- /dev/null +++ b/mcs/errors/cs8161.cs @@ -0,0 +1,12 @@ +// CS8161: A static readonly field cannot be returned by reference +// Line: 10 + +class X +{ + static readonly int f; + + static ref int Test () + { + return ref f; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8170-2.cs b/mcs/errors/cs8170-2.cs new file mode 100644 index 00000000000..dbd76a4da36 --- /dev/null +++ b/mcs/errors/cs8170-2.cs @@ -0,0 +1,12 @@ +// CS8170: +// Line: 10 + +public struct S +{ + int f; + + public ref S Foo () + { + return ref f; + } +} diff --git a/mcs/errors/cs8170.cs b/mcs/errors/cs8170.cs new file mode 100644 index 00000000000..142e1a1943f --- /dev/null +++ b/mcs/errors/cs8170.cs @@ -0,0 +1,10 @@ +// CS8170: +// Line: 8 + +public struct S +{ + public ref S Foo () + { + return ref this; + } +} diff --git a/mcs/errors/cs8171.cs b/mcs/errors/cs8171.cs new file mode 100644 index 00000000000..36eae2c65a4 --- /dev/null +++ b/mcs/errors/cs8171.cs @@ -0,0 +1,12 @@ +// CS8171: Cannot initialize a by-value variable `l' with a reference expression +// Line: 10 + +class Test +{ + int field; + + void Foo () + { + int l = ref field; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8172.cs b/mcs/errors/cs8172.cs new file mode 100644 index 00000000000..7ddd3833e8c --- /dev/null +++ b/mcs/errors/cs8172.cs @@ -0,0 +1,12 @@ +// CS8172: Cannot initialize a by-reference variable `j' with a value +// Line: 10 + +class X +{ + static int f; + + public static void Main () + { + ref int j = f; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8173.cs b/mcs/errors/cs8173.cs new file mode 100644 index 00000000000..7c7d894ad6e --- /dev/null +++ b/mcs/errors/cs8173.cs @@ -0,0 +1,13 @@ +// CS8173: The expression must be of type `long' because it is being assigned by reference +// Line: 11 + +public class X +{ + int field; + + public static void Main () + { + int i = 5; + ref long j = ref i; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8174.cs b/mcs/errors/cs8174.cs new file mode 100644 index 00000000000..888711a0626 --- /dev/null +++ b/mcs/errors/cs8174.cs @@ -0,0 +1,10 @@ +// CS8174: A declaration of a by-reference variable must have an initializer +// Line: 8 + +class X +{ + public static void Main () + { + ref int j; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8175.cs b/mcs/errors/cs8175.cs new file mode 100644 index 00000000000..4ef39db696d --- /dev/null +++ b/mcs/errors/cs8175.cs @@ -0,0 +1,17 @@ +// CS8175: Cannot use by-reference variable `v' inside an anonymous method, lambda expression, or query expression +// Line: 14 + +using System; + +public class Test +{ + public static void Main() + { + var arr = new int [1]; + ref var v = ref arr [0]; + + Action a = delegate { + ref var v2 = ref v; + }; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8176.cs b/mcs/errors/cs8176.cs new file mode 100644 index 00000000000..514c0b2b554 --- /dev/null +++ b/mcs/errors/cs8176.cs @@ -0,0 +1,15 @@ +// CS8176: Iterators cannot use by-reference variables +// Line: 12 + +using System.Collections.Generic; + +class X +{ + int x; + + IEnumerable<int> Test () + { + ref int y = ref x; + yield break; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8177.cs b/mcs/errors/cs8177.cs new file mode 100644 index 00000000000..414ece1b4be --- /dev/null +++ b/mcs/errors/cs8177.cs @@ -0,0 +1,15 @@ +// CS8177: Async methods cannot use by-reference variables +// Line: 12 + +using System.Threading.Tasks; + +class X +{ + int x; + + async Task Test () + { + ref int y = ref x; + await Task.Yield (); + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8178-2.cs b/mcs/errors/cs8178-2.cs new file mode 100644 index 00000000000..e61b7d9eb5c --- /dev/null +++ b/mcs/errors/cs8178-2.cs @@ -0,0 +1,20 @@ +// CS8178: `await' cannot be used in an expression containing a call to `X.this[int]' because it returns by reference +// Line: 12 + +using System.Threading.Tasks; + +class X +{ + int x; + + async Task Test () + { + Foo (ref this [await Task.FromResult (1)]); + } + + ref int this [int arg] => ref x; + + static void Foo (ref int arg) + { + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8178.cs b/mcs/errors/cs8178.cs new file mode 100644 index 00000000000..6f779621570 --- /dev/null +++ b/mcs/errors/cs8178.cs @@ -0,0 +1,24 @@ +// CS8178: `await' cannot be used in an expression containing a call to `X.Wrap(int)' because it returns by reference +// Line: 12 + +using System.Threading.Tasks; + +class X +{ + int x; + + async Task Test () + { + Foo (ref Wrap (await Task.FromResult (1))) = 4; + } + + ref int Wrap (int arg) + { + return ref x; + } + + static ref int Foo (ref int arg) + { + return ref arg; + } +}
\ No newline at end of file diff --git a/mcs/errors/cs8189.cs b/mcs/errors/cs8189.cs new file mode 100644 index 00000000000..909ec3b4fcf --- /dev/null +++ b/mcs/errors/cs8189.cs @@ -0,0 +1,17 @@ +// CS8189: By reference return delegate does not match `C.D()' return type +// Line: 15 + +class C +{ + delegate ref int D (); + + static int M () + { + return 1; + } + + static void Main () + { + D d = new D (M); + } +}
\ No newline at end of file diff --git a/mcs/errors/known-issues-net_4_x b/mcs/errors/known-issues-net_4_x index 40f81ded970..c9ed9317350 100644 --- a/mcs/errors/known-issues-net_4_x +++ b/mcs/errors/known-issues-net_4_x @@ -22,3 +22,8 @@ cs8129.cs NO ERROR cs8141.cs cs8141-2.cs cs8144.cs +cs8157.cs NO ERROR +cs8160.cs +cs8161.cs +cs8170.cs NO ERROR +cs8170-2.cs |