The OpenD Programming Language

Legacy Code

To maintain compatibility with older D code, many legacy features remain supported. This page describes each legacy feature that is supported, with a suggestion of how to modernize the code.

More...
Legacy Features
Feature Summary
`body` keywordbody after a contract statement - use do instead
alias target first syntaxuse alias name = target instead.
Struct/union postblituse a copy constructor instead.

body keyword

body was a keyword used to specify a function/method's body after a contract statement:

class Foo
{
    void bar(int i)
    in { assert(i >= 42); }
    body { /* Do something interesting */ }

    string method(string s)
    out(v) { assert(v.length == s.length); }
    body { /* Do something even more interesting */ }

    void noBody() { /* No contracts, no body */ }
}

Corrective Action

Use the do keyword instead (introduced in v2.075.0):

void bar(int i)
in { assert(i >= 42); }
do { /* Look ma, no body! */ }

Rationale: The body keyword was only used for this single purpose. Since D grammar aims to be context free, this common word was reserved, which led to frequent trouble for people interfacing with other languages (e.g. javascript) or auto-generating code.

glossary, Glossary