rbs 0.10.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +9 -9
- data/CHANGELOG.md +29 -0
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/Rakefile +16 -6
- data/Steepfile +28 -0
- data/bin/steep +4 -0
- data/bin/test_runner.rb +7 -5
- data/docs/syntax.md +14 -1
- data/lib/rbs/ast/comment.rb +7 -1
- data/lib/rbs/ast/declarations.rb +15 -9
- data/lib/rbs/ast/members.rb +3 -8
- data/lib/rbs/buffer.rb +1 -1
- data/lib/rbs/cli.rb +72 -3
- data/lib/rbs/constant.rb +1 -1
- data/lib/rbs/constant_table.rb +9 -8
- data/lib/rbs/definition.rb +31 -14
- data/lib/rbs/definition_builder.rb +97 -67
- data/lib/rbs/environment.rb +28 -11
- data/lib/rbs/environment_loader.rb +67 -47
- data/lib/rbs/location.rb +1 -5
- data/lib/rbs/method_type.rb +5 -5
- data/lib/rbs/namespace.rb +14 -3
- data/lib/rbs/parser.y +2 -12
- data/lib/rbs/prototype/rb.rb +3 -5
- data/lib/rbs/prototype/rbi.rb +1 -4
- data/lib/rbs/prototype/runtime.rb +0 -4
- data/lib/rbs/substitution.rb +4 -3
- data/lib/rbs/test/setup.rb +5 -1
- data/lib/rbs/test/setup_helper.rb +15 -0
- data/lib/rbs/test/tester.rb +7 -5
- data/lib/rbs/test/type_check.rb +14 -2
- data/lib/rbs/type_name.rb +18 -1
- data/lib/rbs/type_name_resolver.rb +10 -3
- data/lib/rbs/types.rb +27 -21
- data/lib/rbs/variance_calculator.rb +9 -6
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +26 -17
- data/sig/annotation.rbs +26 -0
- data/sig/buffer.rbs +28 -0
- data/sig/builtin_names.rbs +41 -0
- data/sig/comment.rbs +26 -0
- data/sig/constant.rbs +21 -0
- data/sig/constant_table.rbs +30 -0
- data/sig/declarations.rbs +202 -0
- data/sig/definition.rbs +129 -0
- data/sig/definition_builder.rbs +94 -0
- data/sig/environment.rbs +94 -0
- data/sig/environment_loader.rbs +58 -0
- data/sig/location.rbs +52 -0
- data/sig/members.rbs +160 -0
- data/sig/method_types.rbs +40 -0
- data/sig/namespace.rbs +124 -0
- data/sig/polyfill.rbs +3 -0
- data/sig/rbs.rbs +3 -0
- data/sig/substitution.rbs +39 -0
- data/sig/type_name_resolver.rbs +24 -0
- data/sig/typename.rbs +70 -0
- data/sig/types.rbs +361 -0
- data/sig/util.rbs +13 -0
- data/sig/variance_calculator.rbs +35 -0
- data/sig/version.rbs +3 -0
- data/sig/writer.rbs +40 -0
- data/stdlib/bigdecimal/big_decimal.rbs +887 -0
- data/stdlib/bigdecimal/math/big_math.rbs +142 -0
- data/stdlib/builtin/array.rbs +2 -1
- data/stdlib/builtin/builtin.rbs +0 -3
- data/stdlib/builtin/hash.rbs +1 -1
- data/stdlib/builtin/kernel.rbs +2 -0
- data/stdlib/builtin/math.rbs +26 -26
- data/stdlib/builtin/struct.rbs +9 -10
- data/stdlib/date/date.rbs +1056 -0
- data/stdlib/date/date_time.rbs +582 -0
- data/stdlib/forwardable/forwardable.rbs +204 -0
- data/stdlib/pathname/pathname.rbs +2 -0
- data/stdlib/pty/pty.rbs +5 -29
- data/stdlib/set/set.rbs +1 -1
- data/stdlib/uri/file.rbs +167 -0
- data/stdlib/uri/generic.rbs +875 -0
- data/stdlib/uri/http.rbs +158 -0
- data/stdlib/uri/https.rbs +108 -0
- data/stdlib/uri/ldap.rbs +224 -0
- data/stdlib/uri/ldaps.rbs +108 -0
- data/stdlib/zlib/zlib.rbs +1 -1
- data/steep/Gemfile +3 -0
- data/steep/Gemfile.lock +51 -0
- metadata +45 -5
@@ -0,0 +1,40 @@
|
|
1
|
+
module RBS
|
2
|
+
class MethodType
|
3
|
+
class Block
|
4
|
+
attr_reader type: Types::Function
|
5
|
+
attr_reader required: bool
|
6
|
+
|
7
|
+
def initialize: (type: Types::Function, required: bool) -> void
|
8
|
+
|
9
|
+
def ==: (untyped other) -> bool
|
10
|
+
|
11
|
+
def to_json: (*untyped) -> String
|
12
|
+
|
13
|
+
def sub: (Substitution) -> Block
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader type_params: Array[Symbol]
|
17
|
+
attr_reader type: Types::Function
|
18
|
+
attr_reader block: Block?
|
19
|
+
attr_reader location: Location?
|
20
|
+
|
21
|
+
def initialize: (type_params: Array[Symbol], type: Types::Function, block: Block?, location: Location?) -> void
|
22
|
+
|
23
|
+
def ==: (untyped other) -> bool
|
24
|
+
|
25
|
+
def to_json: (*untyped) -> String
|
26
|
+
|
27
|
+
def sub: (Substitution) -> MethodType
|
28
|
+
|
29
|
+
def update: (?type_params: Array[Symbol], ?type: Types::Function, ?block: Block?, ?location: Location?) -> MethodType
|
30
|
+
|
31
|
+
def free_variables: (?Set[Symbol] set) -> Set[Symbol]
|
32
|
+
|
33
|
+
def map_type: () { (Types::t) -> Types::t } -> MethodType
|
34
|
+
|
35
|
+
def each_type: () { (Types::t) -> void } -> void
|
36
|
+
| () -> Enumerator[Types::t, void]
|
37
|
+
|
38
|
+
def to_s: () -> String
|
39
|
+
end
|
40
|
+
end
|
data/sig/namespace.rbs
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
module RBS
|
2
|
+
# Namespace instance represents a _prefix of module names_.
|
3
|
+
#
|
4
|
+
# vvvvvvvvvvvvvv TypeName
|
5
|
+
# RBS::Namespace
|
6
|
+
# ^^^^^ Namespace
|
7
|
+
#
|
8
|
+
# vvvvvvvvvv TypeName
|
9
|
+
# RBS::Types
|
10
|
+
# ^^^^^ Namespace
|
11
|
+
#
|
12
|
+
# vvvvvvvvvvvvvvvvv TypeName
|
13
|
+
# RBS::Types::Union
|
14
|
+
# ^^^^^^^^^^^^ Namespace
|
15
|
+
#
|
16
|
+
# Note that `Namespace` is a RBS specific concept and there is no corresponding concept in Ruby.
|
17
|
+
#
|
18
|
+
# There are _absolute_ and _relative_ namespaces.
|
19
|
+
#
|
20
|
+
# Namespace(::RBS::) # Absolute namespace
|
21
|
+
# Namespace( RBS::) # Relative namespace
|
22
|
+
#
|
23
|
+
# It also defines two special namespaces.
|
24
|
+
#
|
25
|
+
# :: # _Root_ namespace
|
26
|
+
# # _Empty_ namespace
|
27
|
+
#
|
28
|
+
class Namespace
|
29
|
+
attr_reader path: Array[Symbol]
|
30
|
+
|
31
|
+
def initialize: (path: Array[Symbol], absolute: bool) -> void
|
32
|
+
|
33
|
+
# Returns new _empty_ namespace.
|
34
|
+
def self.empty: () -> Namespace
|
35
|
+
|
36
|
+
# Returns new _root_ namespace.
|
37
|
+
def self.root: () -> Namespace
|
38
|
+
|
39
|
+
# Concat two namespaces.
|
40
|
+
#
|
41
|
+
# Namespace("Foo::") + Namespace("Bar::") # => Foo::Bar::
|
42
|
+
# Namespace("::Foo::") + Namespace("Bar::") # => ::Foo::Bar::
|
43
|
+
#
|
44
|
+
# If `other` is an absolute namespace, it returns `other`.
|
45
|
+
#
|
46
|
+
# Namespace("Foo::") + Namespace("::Bar::") # => ::Bar::
|
47
|
+
#
|
48
|
+
def +: (Namespace other) -> Namespace
|
49
|
+
|
50
|
+
# Add one path component to self.
|
51
|
+
#
|
52
|
+
# Namespace("Foo::").append(:Bar) # => Namespace("Foo::Bar::")
|
53
|
+
def append: (Symbol component) -> Namespace
|
54
|
+
|
55
|
+
# Returns parent namespace.
|
56
|
+
# Raises error there is no parent namespace.
|
57
|
+
#
|
58
|
+
# Namespace("::A").parent # => Namespace("::")
|
59
|
+
# Namespace("::").parent # raises error
|
60
|
+
# Namespace("A::B").parent # => Namespace("A")
|
61
|
+
def parent: () -> Namespace
|
62
|
+
|
63
|
+
# Returns true if self is absolute namespace.
|
64
|
+
def absolute?: () -> bool
|
65
|
+
|
66
|
+
# Returns true if self is relative namespace.
|
67
|
+
def relative?: () -> bool
|
68
|
+
|
69
|
+
# Returns absolute namespace.
|
70
|
+
#
|
71
|
+
# Namespace("A").absolute! # => Namespace("::A")
|
72
|
+
# Namespace("::A").absolute! # => Namespace("::A")
|
73
|
+
#
|
74
|
+
def absolute!: () -> Namespace
|
75
|
+
|
76
|
+
# Returns _relative_ namespace.
|
77
|
+
#
|
78
|
+
def relative!: () -> Namespace
|
79
|
+
|
80
|
+
def empty?: () -> bool
|
81
|
+
|
82
|
+
# Equality is defined by its structure.
|
83
|
+
#
|
84
|
+
def ==: (untyped other) -> bool
|
85
|
+
|
86
|
+
alias eql? ==
|
87
|
+
|
88
|
+
# Hash is defined based on its structure.
|
89
|
+
#
|
90
|
+
def hash: () -> Integer
|
91
|
+
|
92
|
+
# Returns a pair of parent namespace and a symbol of last component.
|
93
|
+
#
|
94
|
+
# Namespace("::A::B::C").split # => [Namespace("::A::B::"), :C]
|
95
|
+
#
|
96
|
+
def split: () -> [Namespace, Symbol]?
|
97
|
+
|
98
|
+
def to_s: () -> String
|
99
|
+
|
100
|
+
# Construct a type name which points to the same name type.
|
101
|
+
#
|
102
|
+
def to_type_name: () -> TypeName
|
103
|
+
|
104
|
+
def self.parse: (String string) -> Namespace
|
105
|
+
|
106
|
+
# Iterate over Namespace for each element in ascending order.
|
107
|
+
#
|
108
|
+
# ```
|
109
|
+
# Namespace.parse("::A::B::C").ascend {|ns| p ns }
|
110
|
+
# => ::A::B::C
|
111
|
+
# => ::A::B
|
112
|
+
# => ::A
|
113
|
+
# => ::(root)
|
114
|
+
# ```
|
115
|
+
def ascend: () { (Namespace) -> void } -> void
|
116
|
+
| () -> Enumerator[Namespace, void]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
module Kernel
|
121
|
+
# Parses given string and returns Namespace.
|
122
|
+
#
|
123
|
+
def Namespace: (String) -> RBS::Namespace
|
124
|
+
end
|
data/sig/polyfill.rbs
ADDED
data/sig/rbs.rbs
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module RBS
|
2
|
+
# Substitution from type variables to types.
|
3
|
+
#
|
4
|
+
# The substitution construction is in _destructive_ manner.
|
5
|
+
#
|
6
|
+
# sub = Substitution.new
|
7
|
+
# sub.add(from: :A, to: type1)
|
8
|
+
# sub.add(from: :B, to: type2)
|
9
|
+
# sub.instance_type = type3
|
10
|
+
#
|
11
|
+
class Substitution
|
12
|
+
# A hash containing mapping from type variable name to type.
|
13
|
+
attr_reader mapping: Hash[Symbol, Types::t]
|
14
|
+
|
15
|
+
# The result of applying this substitution to `instance` type.
|
16
|
+
# `nil` maps to `instance` type itself.
|
17
|
+
attr_accessor instance_type: Types::t?
|
18
|
+
|
19
|
+
def initialize: () -> void
|
20
|
+
|
21
|
+
# Add mapping to this substitution.
|
22
|
+
# Overwrites the previous mapping if same `from` is given.
|
23
|
+
def add: (from: Symbol, to: Types::t) -> void
|
24
|
+
|
25
|
+
# Utility method to construct a substitution.
|
26
|
+
# Raises an error when `variables.size != types.size`.
|
27
|
+
# `instance_type` defaults to `nil`.
|
28
|
+
#
|
29
|
+
# Yields types in `types` and the block value is used if block is given.
|
30
|
+
#
|
31
|
+
def self.build: (Array[Symbol] variables, Array[Types::t] types, ?instance_type: Types::t?) ?{ (Types::t) -> Types::t } -> instance
|
32
|
+
|
33
|
+
# Applies the substitution to given type.
|
34
|
+
def apply: (Types::t) -> Types::t
|
35
|
+
|
36
|
+
# Returns a substitution without variables given in `vars`.
|
37
|
+
def without: (*Symbol vars) -> Substitution
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RBS
|
2
|
+
class TypeNameResolver
|
3
|
+
class Query
|
4
|
+
attr_reader type_name: TypeName
|
5
|
+
attr_reader context: Array[Namespace]
|
6
|
+
|
7
|
+
def initialize: (type_name: TypeName, context: Array[Namespace]) -> void
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader all_names: Set[TypeName]
|
11
|
+
|
12
|
+
attr_reader cache: Hash[Query, TypeName?]
|
13
|
+
|
14
|
+
def self.from_env: (Environment) -> TypeNameResolver
|
15
|
+
|
16
|
+
def add_names: (Array[TypeName]) -> self
|
17
|
+
|
18
|
+
def resolve: (TypeName, context: Array[Namespace]) -> TypeName?
|
19
|
+
|
20
|
+
def has_name?: (TypeName) -> TypeName?
|
21
|
+
|
22
|
+
def try_cache: (Query) { () -> TypeName? } -> TypeName?
|
23
|
+
end
|
24
|
+
end
|
data/sig/typename.rbs
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module RBS
|
2
|
+
# TypeName represents name of types in RBS.
|
3
|
+
#
|
4
|
+
# TypeNames are one of the three kind, class, alias, and interface.
|
5
|
+
# *class* type names corresponds to Ruby classes and modules.
|
6
|
+
# There are no corresponding Ruby value to *alias* and *interface* type names.
|
7
|
+
#
|
8
|
+
class TypeName
|
9
|
+
# Type of type names.
|
10
|
+
#
|
11
|
+
type kind = :class | :alias | :interface
|
12
|
+
|
13
|
+
# The namespace the type name is defined in.
|
14
|
+
attr_reader namespace: Namespace
|
15
|
+
|
16
|
+
# Name of type name.
|
17
|
+
attr_reader name: Symbol
|
18
|
+
|
19
|
+
# Kind of the type.
|
20
|
+
attr_reader kind: kind
|
21
|
+
|
22
|
+
# Initializer accepts two keyword args, `namespace` and `name`.
|
23
|
+
# Note that `kind` is automatically determined from its `name`.
|
24
|
+
#
|
25
|
+
# If the name starts with capital alphabet, it is _class_.
|
26
|
+
# If the name starts with lower case alphabet, it is _alias_.
|
27
|
+
# If the name starts with an underscore, it is _interface_.
|
28
|
+
#
|
29
|
+
def initialize: (namespace: Namespace, name: Symbol) -> void
|
30
|
+
|
31
|
+
def ==: (untyped other) -> bool
|
32
|
+
|
33
|
+
def hash: () -> Integer
|
34
|
+
|
35
|
+
def to_s: () -> ::String
|
36
|
+
|
37
|
+
def to_json: (*untyped a) -> untyped
|
38
|
+
|
39
|
+
# Returns a namespace with same components of self.
|
40
|
+
def to_namespace: () -> Namespace
|
41
|
+
|
42
|
+
# Returns true when self is a _class_ type name.
|
43
|
+
def class?: () -> bool
|
44
|
+
|
45
|
+
# Returns true when self is an _alias_ type name.
|
46
|
+
def alias?: () -> bool
|
47
|
+
|
48
|
+
def absolute!: () -> TypeName
|
49
|
+
|
50
|
+
def absolute?: () -> bool
|
51
|
+
|
52
|
+
def relative!: () -> TypeName
|
53
|
+
|
54
|
+
# Returns true when self is an _interface_ type name.
|
55
|
+
def interface?: () -> bool
|
56
|
+
|
57
|
+
# Returns a new type name with a namespace appended to given namespace.
|
58
|
+
#
|
59
|
+
# TypeName("Hello").with_prefix(Namespace("World")) # => World::Hello
|
60
|
+
# TypeName("Foo::Bar").with_prefix(Namespace("::Hello")) # => ::Hello::Foo::Bar
|
61
|
+
# TypeName("::A::B").with_prefix(Namespace("C")) # => ::A::B
|
62
|
+
#
|
63
|
+
def with_prefix: (Namespace namespace) -> TypeName
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
module Kernel
|
68
|
+
# Returns type name with given string representation.
|
69
|
+
def TypeName: (String name) -> RBS::TypeName
|
70
|
+
end
|
data/sig/types.rbs
ADDED
@@ -0,0 +1,361 @@
|
|
1
|
+
module RBS
|
2
|
+
module Types
|
3
|
+
# _TypeBase interface represents the operations common to all of the types.
|
4
|
+
#
|
5
|
+
interface _TypeBase
|
6
|
+
# Location for types in the RBS source code.
|
7
|
+
# `nil` means there is no RBS source code for the type.
|
8
|
+
#
|
9
|
+
def location: () -> Location?
|
10
|
+
|
11
|
+
# Returns names of free variables of a type.
|
12
|
+
# You can pass a Set instance to add the free variables to the set to avoid Set object allocation.
|
13
|
+
#
|
14
|
+
def free_variables: (?Set[Symbol]) -> Set[Symbol]
|
15
|
+
|
16
|
+
# Receives a substitution and returns a new type applied the substitution.
|
17
|
+
#
|
18
|
+
def sub: (Substitution) -> t
|
19
|
+
|
20
|
+
# Maps type names included in the type and returns new instance of type.
|
21
|
+
def map_type_name: () { (TypeName, Location?, t) -> TypeName } -> t
|
22
|
+
|
23
|
+
# Yields all direct sub types included in the type.
|
24
|
+
# It doesn't yield the type itself.
|
25
|
+
#
|
26
|
+
# parse("Hash[String, Array[Symbol]]").each_type do |ty|
|
27
|
+
# ... # Yields String and Array[Symbol]
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
def each_type: () { (t) -> void } -> void
|
31
|
+
| () -> Enumerator[t, void]
|
32
|
+
|
33
|
+
# Returns a JSON representation.
|
34
|
+
#
|
35
|
+
def to_json: (*untyped) -> String
|
36
|
+
|
37
|
+
# Returns a String representation.
|
38
|
+
# `level` is used internally.
|
39
|
+
#
|
40
|
+
# parse("String").to_s # => "String"
|
41
|
+
# parse("String | Integer").to_s() # => "String | Integer"
|
42
|
+
# parse("String | Integer").to_s(1) # => "(String | Integer)"
|
43
|
+
#
|
44
|
+
def to_s: (?Integer level) -> String
|
45
|
+
end
|
46
|
+
|
47
|
+
# t represents union of all possible types.
|
48
|
+
#
|
49
|
+
type t = Bases::Bool | Bases::Void | Bases::Any | Bases::Nil | Bases::Top | Bases::Bottom | Bases::Self | Bases::Instance | Bases::Class
|
50
|
+
| Variable | ClassSingleton | Interface | ClassInstance | Alias | Tuple | Record | Optional | Union | Intersection | Proc | Literal
|
51
|
+
|
52
|
+
module NoFreeVariables
|
53
|
+
def free_variables: (?Set[Symbol]) -> Set[Symbol]
|
54
|
+
end
|
55
|
+
|
56
|
+
module NoSubst
|
57
|
+
def sub: (Substitution) -> self
|
58
|
+
end
|
59
|
+
|
60
|
+
module EmptyEachType
|
61
|
+
def each_type: () { (t) -> void } -> void
|
62
|
+
| () -> Enumerator[t, void]
|
63
|
+
end
|
64
|
+
|
65
|
+
module NoTypeName
|
66
|
+
def map_type_name: () { (TypeName, Location?, t) -> TypeName } -> self
|
67
|
+
end
|
68
|
+
|
69
|
+
module Bases
|
70
|
+
class Base
|
71
|
+
include _TypeBase
|
72
|
+
|
73
|
+
def initialize: (location: Location?) -> void
|
74
|
+
|
75
|
+
def ==: (untyped other) -> bool
|
76
|
+
|
77
|
+
def hash: () -> Integer
|
78
|
+
|
79
|
+
alias eql? ==
|
80
|
+
|
81
|
+
include NoFreeVariables
|
82
|
+
include NoSubst
|
83
|
+
include EmptyEachType
|
84
|
+
include NoTypeName
|
85
|
+
end
|
86
|
+
|
87
|
+
class Bool < Base
|
88
|
+
end
|
89
|
+
|
90
|
+
class Void < Base
|
91
|
+
end
|
92
|
+
|
93
|
+
class Any < Base
|
94
|
+
end
|
95
|
+
|
96
|
+
class Nil < Base
|
97
|
+
end
|
98
|
+
|
99
|
+
class Top < Base
|
100
|
+
end
|
101
|
+
|
102
|
+
class Bottom < Base
|
103
|
+
end
|
104
|
+
|
105
|
+
class Self < Base
|
106
|
+
end
|
107
|
+
|
108
|
+
class Instance < Base
|
109
|
+
def sub: (Substitution sub) -> t
|
110
|
+
end
|
111
|
+
|
112
|
+
class Class < Base
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class Variable
|
117
|
+
attr_reader name: Symbol
|
118
|
+
attr_reader location: Location?
|
119
|
+
|
120
|
+
@@count: Integer
|
121
|
+
|
122
|
+
include _TypeBase
|
123
|
+
|
124
|
+
include NoTypeName
|
125
|
+
include EmptyEachType
|
126
|
+
|
127
|
+
def initialize: (name: Symbol, location: Location?) -> void
|
128
|
+
|
129
|
+
def ==: (untyped other) -> bool
|
130
|
+
|
131
|
+
alias eql? ==
|
132
|
+
|
133
|
+
def hash: () -> Integer
|
134
|
+
|
135
|
+
def self.build: (Symbol) -> Variable
|
136
|
+
| (Array[Symbol]) -> Array[Variable]
|
137
|
+
|
138
|
+
def self.fresh: (?Symbol) -> Variable
|
139
|
+
end
|
140
|
+
|
141
|
+
class ClassSingleton
|
142
|
+
attr_reader name: TypeName
|
143
|
+
attr_reader location: Location?
|
144
|
+
|
145
|
+
include _TypeBase
|
146
|
+
|
147
|
+
def initialize: (name: TypeName, location: Location?) -> void
|
148
|
+
|
149
|
+
def ==: (untyped other) -> bool
|
150
|
+
|
151
|
+
alias eql? ==
|
152
|
+
|
153
|
+
def hash: () -> Integer
|
154
|
+
|
155
|
+
include NoFreeVariables
|
156
|
+
include NoSubst
|
157
|
+
include EmptyEachType
|
158
|
+
end
|
159
|
+
|
160
|
+
module Application
|
161
|
+
attr_reader name: TypeName
|
162
|
+
attr_reader args: Array[t]
|
163
|
+
|
164
|
+
def ==: (untyped) -> bool
|
165
|
+
|
166
|
+
alias eql? ==
|
167
|
+
|
168
|
+
def hash: () -> Integer
|
169
|
+
|
170
|
+
def free_variables: (?Set[Symbol]) -> Set[Symbol]
|
171
|
+
|
172
|
+
def to_s: (?Integer level) -> String
|
173
|
+
|
174
|
+
def each_type: () { (t) -> void } -> void
|
175
|
+
| () -> Enumerator[t, void]
|
176
|
+
end
|
177
|
+
|
178
|
+
class Interface
|
179
|
+
include Application
|
180
|
+
|
181
|
+
attr_reader location: Location?
|
182
|
+
|
183
|
+
def initialize: (name: TypeName, args: Array[t], location: Location?) -> void
|
184
|
+
|
185
|
+
include _TypeBase
|
186
|
+
end
|
187
|
+
|
188
|
+
# ClassInstance represents a type of an instance of a class.
|
189
|
+
#
|
190
|
+
# String # Type of an instance of String class.
|
191
|
+
# Array[String] # Type of an instance of Array class with instances of String.
|
192
|
+
# Kernel # Type of an instance of a class which includes Kernel.
|
193
|
+
#
|
194
|
+
class ClassInstance
|
195
|
+
include Application
|
196
|
+
|
197
|
+
attr_reader location: Location?
|
198
|
+
|
199
|
+
def initialize: (name: TypeName, args: Array[t], location: Location?) -> void
|
200
|
+
|
201
|
+
include _TypeBase
|
202
|
+
end
|
203
|
+
|
204
|
+
class Alias
|
205
|
+
attr_reader location: Location?
|
206
|
+
attr_reader name: TypeName
|
207
|
+
|
208
|
+
def initialize: (name: TypeName, location: Location?) -> void
|
209
|
+
|
210
|
+
include _TypeBase
|
211
|
+
include NoFreeVariables
|
212
|
+
include NoSubst
|
213
|
+
include EmptyEachType
|
214
|
+
end
|
215
|
+
|
216
|
+
class Tuple
|
217
|
+
attr_reader types: Array[t]
|
218
|
+
attr_reader location: Location?
|
219
|
+
|
220
|
+
def initialize: (types: Array[t], location: Location?) -> void
|
221
|
+
|
222
|
+
include _TypeBase
|
223
|
+
end
|
224
|
+
|
225
|
+
class Record
|
226
|
+
attr_reader fields: Hash[Symbol, t]
|
227
|
+
attr_reader location: Location?
|
228
|
+
|
229
|
+
def initialize: (fields: Hash[Symbol, t], location: Location?) -> void
|
230
|
+
|
231
|
+
include _TypeBase
|
232
|
+
end
|
233
|
+
|
234
|
+
class Optional
|
235
|
+
attr_reader type: t
|
236
|
+
attr_reader location: Location?
|
237
|
+
|
238
|
+
def initialize: (type: t, location: Location?) -> void
|
239
|
+
|
240
|
+
include _TypeBase
|
241
|
+
end
|
242
|
+
|
243
|
+
class Union
|
244
|
+
attr_reader types: Array[t]
|
245
|
+
attr_reader location: Location?
|
246
|
+
|
247
|
+
def initialize: (types: Array[t], location: Location?) -> void
|
248
|
+
|
249
|
+
include _TypeBase
|
250
|
+
|
251
|
+
def map_type: () { (t) -> t } -> Union
|
252
|
+
| () -> Enumerator[t, Union]
|
253
|
+
end
|
254
|
+
|
255
|
+
class Intersection
|
256
|
+
attr_reader types: Array[t]
|
257
|
+
attr_reader location: Location?
|
258
|
+
|
259
|
+
def initialize: (types: Array[t], location: Location?) -> void
|
260
|
+
|
261
|
+
include _TypeBase
|
262
|
+
|
263
|
+
def map_type: () { (t) -> t } -> Intersection
|
264
|
+
| () -> Enumerator[t, Intersection]
|
265
|
+
end
|
266
|
+
|
267
|
+
class Function
|
268
|
+
class Param
|
269
|
+
attr_reader type: t
|
270
|
+
attr_reader name: Symbol?
|
271
|
+
|
272
|
+
def initialize: (type: t, name: Symbol?) -> void
|
273
|
+
|
274
|
+
def map_type: { (t) -> t } -> Param
|
275
|
+
| -> Enumerator[t, Param]
|
276
|
+
end
|
277
|
+
|
278
|
+
attr_reader required_positionals: Array[Param]
|
279
|
+
attr_reader optional_positionals: Array[Param]
|
280
|
+
attr_reader rest_positionals: Param?
|
281
|
+
attr_reader trailing_positionals: Array[Param]
|
282
|
+
attr_reader required_keywords: Hash[Symbol, Param]
|
283
|
+
attr_reader optional_keywords: Hash[Symbol, Param]
|
284
|
+
attr_reader rest_keywords: Param?
|
285
|
+
attr_reader return_type: t
|
286
|
+
|
287
|
+
def initialize: (required_positionals: Array[Param],
|
288
|
+
optional_positionals: Array[Param],
|
289
|
+
rest_positionals: Param?,
|
290
|
+
trailing_positionals: Array[Param],
|
291
|
+
required_keywords: Hash[Symbol, Param],
|
292
|
+
optional_keywords: Hash[Symbol, Param],
|
293
|
+
rest_keywords: Param?,
|
294
|
+
return_type: t) -> void
|
295
|
+
|
296
|
+
def free_variables: (?Set[Symbol]) -> Set[Symbol]
|
297
|
+
|
298
|
+
def map_type: { (t) -> t } -> Function
|
299
|
+
| -> Enumerator[t, Function]
|
300
|
+
|
301
|
+
def map_type_name: () { (TypeName, Location?, t) -> TypeName } -> Function
|
302
|
+
|
303
|
+
def each_type: () { (t) -> void } -> void
|
304
|
+
| -> Enumerator[t, void]
|
305
|
+
|
306
|
+
def each_param: () { (Param) -> void } -> void
|
307
|
+
| -> Enumerator[Param, void]
|
308
|
+
|
309
|
+
def to_json: (*untyped) -> String
|
310
|
+
|
311
|
+
def sub: (Substitution) -> Function
|
312
|
+
|
313
|
+
def self.empty: (t) -> instance
|
314
|
+
|
315
|
+
def with_return_type: (t) -> Function
|
316
|
+
|
317
|
+
def update: (?required_positionals: Array[Param],
|
318
|
+
?optional_positionals: Array[Param],
|
319
|
+
?rest_positionals: Param?,
|
320
|
+
?trailing_positionals: Array[Param],
|
321
|
+
?required_keywords: Hash[Symbol, Param],
|
322
|
+
?optional_keywords: Hash[Symbol, Param],
|
323
|
+
?rest_keywords: Param?,
|
324
|
+
?return_type: t) -> Function
|
325
|
+
|
326
|
+
def empty?: () -> bool
|
327
|
+
|
328
|
+
def param_to_s: () -> String
|
329
|
+
def return_to_s: () -> String
|
330
|
+
|
331
|
+
def drop_head: () -> [Param, Function]
|
332
|
+
def drop_tail: () -> [Param, Function]
|
333
|
+
|
334
|
+
def has_keyword?: () -> bool
|
335
|
+
end
|
336
|
+
|
337
|
+
class Proc
|
338
|
+
attr_reader type: Function
|
339
|
+
attr_reader location: Location?
|
340
|
+
|
341
|
+
def initialize: (location: Location?, type: Function) -> void
|
342
|
+
|
343
|
+
include _TypeBase
|
344
|
+
end
|
345
|
+
|
346
|
+
class Literal
|
347
|
+
type literal = String | Integer | Symbol | TrueClass | FalseClass
|
348
|
+
|
349
|
+
attr_reader literal: literal
|
350
|
+
attr_reader location: Location?
|
351
|
+
|
352
|
+
def initialize: (literal: literal, location: Location?) -> void
|
353
|
+
|
354
|
+
include _TypeBase
|
355
|
+
include NoFreeVariables
|
356
|
+
include NoSubst
|
357
|
+
include EmptyEachType
|
358
|
+
include NoTypeName
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|