Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dmd/dscope.d
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ struct Scope
}

/********************************************
* Search enclosing scopes for ClassDeclaration.
* Search enclosing scopes for Struct/ClassDeclaration.
*/
extern (C++) AggregateDeclaration getStructClassScope()
{
Expand Down
19 changes: 16 additions & 3 deletions src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 20 additions & 1 deletion test/fail_compilation/fail334.d
Original file line number Diff line number Diff line change
@@ -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() {}