Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify class declaration syntax #1026

Merged
merged 2 commits into from
Jan 14, 2022
Merged
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
11 changes: 8 additions & 3 deletions docs/design/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,10 @@ for argument passing were decided in

The declarations for nominal class types will have:

- an optional `abstract` or `base` prefix
- `class` introducer
- the name of the class
- in the future, we will have optional modifiers for inheritance
- an optional `extends` followed by the name of the immediate base class
- `{`, an open curly brace
- a sequence of declarations
- `}`, a close curly brace
Expand All @@ -705,10 +706,13 @@ determined at compile time.

To support circular references between class types, we allow
[forward declaration](https://en.wikipedia.org/wiki/Forward_declaration) of
types. A type that is forward declared is considered incomplete until the end of
a definition with the same name.
types. Forward declarations end with semicolon `;` after the name of the class,
instead of any `extends` clause and the block of declarations in curly braces
`{`...`}`. A type that is forward declared is considered incomplete until the
end of a definition with the same name.

```
// Forward declaration of `GraphNode`.
class GraphNode;

class GraphEdge {
Expand All @@ -719,6 +723,7 @@ class GraphEdge {
class GraphNode {
var edges: Vector(GraphEdge*);
}
// `GraphNode` is first complete here.
```

**Open question:** What is specifically allowed and forbidden with an incomplete
Expand Down