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

Update documentation for overloading methods #658

Merged
merged 1 commit into from
Apr 21, 2021
Merged
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
17 changes: 17 additions & 0 deletions docs/sigs.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ ERROR -- : [Kaigi::Conference#speakers] UnexpectedBlockError: unexpected block i
The error means there is a type error on overloaded methods.
The `rbs` test framework tries to the best error message for overloaded methods too, but it reports the `UnresolvedOverloadingError` when it fails.

### DuplicatedMethodDefinitionError

The error is reported when a method is defined multiple times, as RBS does not allow duplicate method definitions. When you need to overload a method, use the `...` syntax:

```ruby
# First definition
class C
def foo: () -> untyped
end

# Second definition, use `...` syntax to tell RBS that we're overloading the method
class C
def foo: () -> untyped
| ...
end
```

## Setting up the test

The design of the signature testing aims to be non-intrusive. The setup is done in two steps:
Expand Down
22 changes: 11 additions & 11 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ _type_ ::= _class-name_ _type-arguments_ (Class instance type)
| _type_ `|` _type_ (Union type)
| _type_ `&` _type_ (Intersection type)
| _type_ `?` (Optional type)
| `{` _record-name_ `:` _type_ `,` ... `}` (Record type)
| `[]` | `[` _type_ `,` ... `]` (Tuples)
| `{` _record-name_ `:` _type_ `,` etc. `}` (Record type)
| `[]` | `[` _type_ `,` etc. `]` (Tuples)
| _type-variable_ (Type variables)
| `^(` _parameters_ `) ->` _type_ (Proc type)
| `self`
Expand All @@ -36,7 +36,7 @@ _namespace_ ::= (Empty namespace)
| _namespace_ /[A-Z]\w*/ `::` (Namespace)

_type-arguments_ ::= (No application)
| `[` _type_ `,` ... `]` (Type application)
| `[` _type_ `,` etc. `]` (Type application)

_literal_ ::= _string-literal_
| _symbol-literal_
Expand Down Expand Up @@ -203,7 +203,6 @@ We can see an example at the definition of `Enumerable#find`:
```
module Enumerable[Elem, Return]
def find: () { (Elem) -> boolish } -> Elem?
...
end
```

Expand Down Expand Up @@ -233,11 +232,11 @@ _parameters_ ::= _required-positionals_ _optional-positionals_ _rest-positional_

_parameter_ ::= _type_ _var-name_ # Parameter with var name
| _type_ # Parameter without var name
_required-positionals_ ::= _parameter_ `,` ...
_optional-positionals_ ::= `?` _parameter_ `,` ...
_required-positionals_ ::= _parameter_ `,` etc.
_optional-positionals_ ::= `?` _parameter_ `,` etc.
_rest-positional_ ::= # Empty
| `*` _parameter_
_trailing-positionals_ ::= _parameter_ `,` ...
_trailing-positionals_ ::= _parameter_ `,` etc.
_keywords_ ::= # Empty
| `**` _parameter_ # Rest keyword
| _keyword_ `:` _parameter_ `,` _keywords_ # Required keyword
Expand Down Expand Up @@ -292,9 +291,10 @@ _method-member_ ::= `def` _method-name_ `:` _method-types_ # Instance
_method-types_ ::= # Empty
| `super` # `super` overloading
| _type-parameters_ _method-type_ `|` _method-types_ # Overloading types
| `...` # Overloading for duplicate definitions

_type-parameters_ ::= # Empty
| `[` _type-variable_ `,` ... `]`
| `[` _type-variable_ `,` etc. `]`

_attribute-member_ ::= _attribute-type_ _method-name_ `:` _type_ # Attribute
| _attribute-type_ _method-name_ `(` _ivar-name_ `) :` _type_ # Attribute with variable name specification
Expand Down Expand Up @@ -450,7 +450,7 @@ _const-name_ ::= _namespace_ /[A-Z]\w*/
_global-name_ ::= /$[a-zA-Z]\w+/ | ...

_module-type-parameters_ ::= # Empty
| `[` _module-type-parameter_ `,` ... `]`
| `[` _module-type-parameter_ `,` etc. `]`

_module-type-parameter_ ::= _check_ _variance_ _type-variable_
_variance_ ::= `out` | `in`
Expand All @@ -475,7 +475,7 @@ For example, an `Array` of `String` can almost be considered to be an `Array` of

```
class Array[out T]
# ...
# etc.
end
```

Expand All @@ -486,7 +486,7 @@ In those cases, one must use the `unchecked` keyword:

```
class Array[unchecked out T]
# ...
# etc.
end
```

Expand Down