Skip to content

Commit adc3520

Browse files
committed
DStyle: Adjust guidance for contracts
1 parent 378eb8e commit adc3520

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

dstyle.dd

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,17 +384,38 @@ void foo(R)(R r)
384384
if (R == 1)
385385
-------------------------------
386386
$(LI Pre and post contracts should have the same indentation level as their
387-
declaration. Put no space between `in`/`out` and an open parenthesis:)
388-
-------------------------------
389-
int foo(int r)
390-
in(r == 0)
391-
out(result; result == 0)
392-
do { … }
387+
declaration. The expression-based syntax should be preferred when the
388+
equivalent long-form syntax would have a single `assert` statement.
389+
Put a space after `in`/`out` similar to `if` constraints:)
390+
-------------------------------
391+
// Prefer:
392+
T transmogrify(T)(T value)
393+
if (isIntegral!T)
394+
in (value % 7 == 0)
395+
out (result; result % 11 == 0)
396+
{
397+
// ...
398+
}
393399

394-
int foo(int r)
395-
in { … }
396-
out(result) { … }
397-
do { … }
400+
// over this:
401+
T transmogrify(T)(T value)
402+
if (isIntegral!T)
403+
in { assert(value % 7 == 0); }
404+
out (result) { assert(result % 11 == 0); }
405+
do
406+
{
407+
// ...
408+
}
409+
-------------------------------
410+
$(LI Invariants should use the expression-based syntax when the equivalent
411+
long-form syntax would have a single `assert` statement. Put a space
412+
between `invariant` and the opening parentheses:)
413+
-------------------------------
414+
struct S
415+
{
416+
int x;
417+
invariant (x > 0);
418+
}
398419
-------------------------------
399420
)
400421
$(LISTSECTION phobos_class_struct_field_declaration, Class/Struct Field Declarations,

0 commit comments

Comments
 (0)