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

spec: allow import to merge service definitions #504

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Changes from 2 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
13 changes: 7 additions & 6 deletions spec/Candid.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The purpose of an IDL is defining the signature, and thereby the *type* of an ac
This is a summary of the grammar proposed:
```
<prog> ::= <def>;* <actor>?
<def> ::= type <id> = <datatype> | import <text> | import* <text>
<def> ::= type <id> = <datatype> | import service? <text>
<actor> ::= service <id>? : (<tuptype> ->)? (<actortype> | <id>) ;?

<actortype> ::= { <methtype>;* }
Expand Down Expand Up @@ -519,14 +519,15 @@ type B = A; // error: cyclic type definition
In order to allow splitting interface definitions up into multiple files or share common definitions between multiple interfaces, *import* declarations are provided.

```
<def> ::= ... | import <text> | import* <text>
<def> ::= ... | import service? <text>
```

There are two forms of import: `import` and `import*`. Both `import` and `import*` refer to another interface file by URL. The type definitions from the imported file are textually included in the importing file. The definitions from the imported file must not refer to definitions from the importing file.
An import refers to another interface file by URL. The type definitions from the imported file are textually included in the importing file. The definitions from the imported file must not refer to definitions from the importing file.

In addition, `import*` includes the main service from the imported file and merges the service definition with the main service in the importing file. The methods in the imported file must not have the same name as the importing file.
`import` ignores the main service definition from the imported file, while `import service` includes the main service from the imported file and merges the service definition with the main service in the importing file. There are two constraints with the main service definition in the imported file:

`import` ignores the main service definition from the imported file.
* The main service cannot be a service constructor.
* The methods from the imported file must not have the same method name as the importing file.

##### Example

Expand All @@ -537,7 +538,7 @@ service : A
```
File `B.did`:
```
import "A.did"; // Cannot use import* because of method name duplication
import "A.did"; // Cannot use import_service because of method name duplication
service B : A ;
```

Expand Down
Loading