diff --git a/src/dmd/dscope.d b/src/dmd/dscope.d index 45f3ccc0f98d..fdf406c316e0 100644 --- a/src/dmd/dscope.d +++ b/src/dmd/dscope.d @@ -597,7 +597,7 @@ struct Scope } /******************************************** - * Search enclosing scopes for ClassDeclaration. + * Search enclosing scopes for Struct/ClassDeclaration. */ extern (C++) AggregateDeclaration getStructClassScope() { diff --git a/src/dmd/typesem.d b/src/dmd/typesem.d index f1cabbf8a899..201d23fa766b 100644 --- a/src/dmd/typesem.d +++ b/src/dmd/typesem.d @@ -1146,10 +1146,23 @@ private extern (C++) final class TypeSemanticVisitor : Visitor errors = true; } - if (tf.isproperty && (tf.varargs || Parameter.dim(tf.parameters) > 2)) + if (tf.isproperty) { - mtype.error(loc, "properties can only have zero, one, or two parameter"); - errors = true; + // Deprecated in 2018-06. + // Change both to error in 2019-06 and uncomment the `errors =` lines. + // @@@DEPRECATED_2019-06@@@. + const np = Parameter.dim(tf.parameters); + if (tf.varargs || np > 2 || (np == 2 && sc.getStructClassScope)) + { + deprecation(loc, "setter property can only have one %s", + sc.getStructClassScope ? "parameter".ptr : "or two parameters".ptr); + //errors = true; + } + else if (np == 0 && tf.next && tf.next.ty == Tvoid && !tf.isref) + { + deprecation(loc, "getter properties must not return void"); + //errors = true; + } } if (tf.varargs == 1 && tf.linkage != LINK.d && Parameter.dim(tf.parameters) == 0) diff --git a/test/fail_compilation/fail334.d b/test/fail_compilation/fail334.d index 4cab7d3b56c4..2cb62a32a6b0 100644 --- a/test/fail_compilation/fail334.d +++ b/test/fail_compilation/fail334.d @@ -1,11 +1,30 @@ +// REQUIRED_ARGS: -de /* TEST_OUTPUT: --- -fail_compilation/fail334.d(10): Error: properties can only have zero, one, or two parameter +fail_compilation/fail334.d(16): Deprecation: setter property can only have one parameter +fail_compilation/fail334.d(17): Deprecation: setter property can only have one parameter +fail_compilation/fail334.d(18): Deprecation: setter property can only have one parameter +fail_compilation/fail334.d(20): Deprecation: getter properties must not return void +fail_compilation/fail334.d(28): Deprecation: setter property can only have one or two parameters +fail_compilation/fail334.d(29): Deprecation: getter properties must not return void --- */ struct S { @property int foo(int a, int b, int c) { return 1; } + @property void set(int, int) {} + @property void set(...) {} + @property void set(int) {} // OK + @property void get() {} } + +// OK +@property ufcs_set(Object obj, int val) {} +@property void set(int) {} +@property ref void get() {} + +@property void set(int[]...) {} +@property void get() {} +