solargraph 0.54.4 → 0.58.3

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.
Files changed (238) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -0
  3. data/.github/workflows/linting.yml +127 -0
  4. data/.github/workflows/plugins.yml +185 -6
  5. data/.github/workflows/rspec.yml +55 -5
  6. data/.github/workflows/typecheck.yml +8 -3
  7. data/.gitignore +8 -0
  8. data/.overcommit.yml +72 -0
  9. data/.rspec +1 -0
  10. data/.rubocop.yml +66 -0
  11. data/.rubocop_todo.yml +1279 -0
  12. data/.yardopts +1 -0
  13. data/CHANGELOG.md +143 -0
  14. data/README.md +20 -6
  15. data/Rakefile +125 -13
  16. data/bin/solargraph +3 -0
  17. data/lib/solargraph/api_map/cache.rb +110 -109
  18. data/lib/solargraph/api_map/constants.rb +279 -0
  19. data/lib/solargraph/api_map/index.rb +193 -167
  20. data/lib/solargraph/api_map/source_to_yard.rb +97 -88
  21. data/lib/solargraph/api_map/store.rb +384 -241
  22. data/lib/solargraph/api_map.rb +945 -875
  23. data/lib/solargraph/bench.rb +45 -28
  24. data/lib/solargraph/complex_type/type_methods.rb +228 -217
  25. data/lib/solargraph/complex_type/unique_type.rb +482 -386
  26. data/lib/solargraph/complex_type.rb +444 -394
  27. data/lib/solargraph/convention/active_support_concern.rb +111 -0
  28. data/lib/solargraph/convention/base.rb +20 -3
  29. data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -0
  30. data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -0
  31. data/lib/solargraph/convention/data_definition.rb +105 -0
  32. data/lib/solargraph/convention/gemfile.rb +15 -15
  33. data/lib/solargraph/convention/gemspec.rb +23 -22
  34. data/lib/solargraph/convention/rakefile.rb +17 -17
  35. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +61 -0
  36. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +102 -0
  37. data/lib/solargraph/convention/struct_definition.rb +164 -0
  38. data/lib/solargraph/convention.rb +78 -47
  39. data/lib/solargraph/converters/dd.rb +17 -17
  40. data/lib/solargraph/converters/dl.rb +15 -15
  41. data/lib/solargraph/converters/dt.rb +15 -15
  42. data/lib/solargraph/converters/misc.rb +1 -1
  43. data/lib/solargraph/diagnostics/require_not_found.rb +53 -53
  44. data/lib/solargraph/diagnostics/rubocop.rb +118 -113
  45. data/lib/solargraph/diagnostics/rubocop_helpers.rb +68 -66
  46. data/lib/solargraph/diagnostics/type_check.rb +55 -55
  47. data/lib/solargraph/diagnostics/update_errors.rb +41 -41
  48. data/lib/solargraph/doc_map.rb +439 -188
  49. data/lib/solargraph/environ.rb +9 -2
  50. data/lib/solargraph/equality.rb +34 -33
  51. data/lib/solargraph/gem_pins.rb +98 -72
  52. data/lib/solargraph/language_server/error_codes.rb +20 -20
  53. data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
  54. data/lib/solargraph/language_server/host/dispatch.rb +130 -128
  55. data/lib/solargraph/language_server/host/message_worker.rb +112 -106
  56. data/lib/solargraph/language_server/host/sources.rb +99 -99
  57. data/lib/solargraph/language_server/host.rb +878 -861
  58. data/lib/solargraph/language_server/message/base.rb +97 -96
  59. data/lib/solargraph/language_server/message/client/register_capability.rb +15 -15
  60. data/lib/solargraph/language_server/message/completion_item/resolve.rb +60 -60
  61. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +114 -112
  62. data/lib/solargraph/language_server/message/extended/document.rb +23 -20
  63. data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
  64. data/lib/solargraph/language_server/message/extended/download_core.rb +19 -19
  65. data/lib/solargraph/language_server/message/extended/search.rb +20 -20
  66. data/lib/solargraph/language_server/message/initialize.rb +191 -191
  67. data/lib/solargraph/language_server/message/text_document/completion.rb +56 -56
  68. data/lib/solargraph/language_server/message/text_document/definition.rb +40 -38
  69. data/lib/solargraph/language_server/message/text_document/document_highlight.rb +16 -16
  70. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +26 -26
  71. data/lib/solargraph/language_server/message/text_document/formatting.rb +148 -131
  72. data/lib/solargraph/language_server/message/text_document/hover.rb +58 -58
  73. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +11 -11
  74. data/lib/solargraph/language_server/message/text_document/references.rb +16 -16
  75. data/lib/solargraph/language_server/message/text_document/rename.rb +19 -19
  76. data/lib/solargraph/language_server/message/text_document/signature_help.rb +24 -24
  77. data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -24
  78. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +35 -35
  79. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +40 -40
  80. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +26 -24
  81. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +23 -23
  82. data/lib/solargraph/language_server/message.rb +94 -94
  83. data/lib/solargraph/language_server/progress.rb +8 -0
  84. data/lib/solargraph/language_server/request.rb +27 -24
  85. data/lib/solargraph/language_server/transport/data_reader.rb +74 -74
  86. data/lib/solargraph/language_server/uri_helpers.rb +49 -49
  87. data/lib/solargraph/library.rb +683 -662
  88. data/lib/solargraph/location.rb +82 -58
  89. data/lib/solargraph/logging.rb +37 -27
  90. data/lib/solargraph/page.rb +92 -89
  91. data/lib/solargraph/parser/comment_ripper.rb +69 -56
  92. data/lib/solargraph/parser/flow_sensitive_typing.rb +255 -0
  93. data/lib/solargraph/parser/node_processor/base.rb +92 -87
  94. data/lib/solargraph/parser/node_processor.rb +62 -45
  95. data/lib/solargraph/parser/parser_gem/class_methods.rb +149 -157
  96. data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -18
  97. data/lib/solargraph/parser/parser_gem/node_chainer.rb +166 -164
  98. data/lib/solargraph/parser/parser_gem/node_methods.rb +486 -495
  99. data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +2 -1
  100. data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -0
  101. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +59 -57
  102. data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +15 -15
  103. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -43
  104. data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +2 -1
  105. data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +2 -1
  106. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +53 -50
  107. data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +37 -36
  108. data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +2 -1
  109. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +23 -0
  110. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +40 -38
  111. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +29 -28
  112. data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +59 -53
  113. data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +8 -7
  114. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -0
  115. data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -16
  116. data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +38 -36
  117. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +52 -42
  118. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +291 -259
  119. data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +3 -1
  120. data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -0
  121. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -0
  122. data/lib/solargraph/parser/parser_gem/node_processors.rb +70 -56
  123. data/lib/solargraph/parser/parser_gem.rb +12 -12
  124. data/lib/solargraph/parser/region.rb +69 -66
  125. data/lib/solargraph/parser/snippet.rb +17 -15
  126. data/lib/solargraph/parser.rb +23 -22
  127. data/lib/solargraph/pin/base.rb +729 -378
  128. data/lib/solargraph/pin/base_variable.rb +126 -118
  129. data/lib/solargraph/pin/block.rb +104 -101
  130. data/lib/solargraph/pin/breakable.rb +9 -0
  131. data/lib/solargraph/pin/callable.rb +231 -147
  132. data/lib/solargraph/pin/closure.rb +72 -57
  133. data/lib/solargraph/pin/common.rb +79 -70
  134. data/lib/solargraph/pin/constant.rb +45 -43
  135. data/lib/solargraph/pin/conversions.rb +123 -123
  136. data/lib/solargraph/pin/delegated_method.rb +120 -101
  137. data/lib/solargraph/pin/documenting.rb +114 -98
  138. data/lib/solargraph/pin/instance_variable.rb +34 -34
  139. data/lib/solargraph/pin/keyword.rb +20 -15
  140. data/lib/solargraph/pin/local_variable.rb +75 -67
  141. data/lib/solargraph/pin/method.rb +672 -527
  142. data/lib/solargraph/pin/method_alias.rb +34 -31
  143. data/lib/solargraph/pin/namespace.rb +115 -107
  144. data/lib/solargraph/pin/parameter.rb +275 -212
  145. data/lib/solargraph/pin/proxy_type.rb +39 -29
  146. data/lib/solargraph/pin/reference/override.rb +47 -29
  147. data/lib/solargraph/pin/reference/require.rb +2 -2
  148. data/lib/solargraph/pin/reference/superclass.rb +15 -10
  149. data/lib/solargraph/pin/reference.rb +39 -22
  150. data/lib/solargraph/pin/search.rb +61 -56
  151. data/lib/solargraph/pin/signature.rb +61 -17
  152. data/lib/solargraph/pin/singleton.rb +1 -1
  153. data/lib/solargraph/pin/symbol.rb +53 -47
  154. data/lib/solargraph/pin/until.rb +18 -0
  155. data/lib/solargraph/pin/while.rb +18 -0
  156. data/lib/solargraph/pin.rb +44 -41
  157. data/lib/solargraph/pin_cache.rb +245 -0
  158. data/lib/solargraph/position.rb +132 -107
  159. data/lib/solargraph/range.rb +112 -98
  160. data/lib/solargraph/rbs_map/conversions.rb +823 -646
  161. data/lib/solargraph/rbs_map/core_fills.rb +84 -50
  162. data/lib/solargraph/rbs_map/core_map.rb +58 -28
  163. data/lib/solargraph/rbs_map/stdlib_map.rb +43 -33
  164. data/lib/solargraph/rbs_map.rb +163 -93
  165. data/lib/solargraph/server_methods.rb +16 -16
  166. data/lib/solargraph/shell.rb +363 -269
  167. data/lib/solargraph/source/chain/array.rb +37 -33
  168. data/lib/solargraph/source/chain/block_symbol.rb +1 -1
  169. data/lib/solargraph/source/chain/block_variable.rb +1 -1
  170. data/lib/solargraph/source/chain/call.rb +337 -303
  171. data/lib/solargraph/source/chain/class_variable.rb +13 -13
  172. data/lib/solargraph/source/chain/constant.rb +26 -89
  173. data/lib/solargraph/source/chain/global_variable.rb +13 -13
  174. data/lib/solargraph/source/chain/hash.rb +34 -33
  175. data/lib/solargraph/source/chain/head.rb +1 -1
  176. data/lib/solargraph/source/chain/if.rb +28 -28
  177. data/lib/solargraph/source/chain/instance_variable.rb +13 -13
  178. data/lib/solargraph/source/chain/link.rb +109 -98
  179. data/lib/solargraph/source/chain/literal.rb +48 -28
  180. data/lib/solargraph/source/chain/or.rb +23 -23
  181. data/lib/solargraph/source/chain/q_call.rb +11 -11
  182. data/lib/solargraph/source/chain/variable.rb +13 -13
  183. data/lib/solargraph/source/chain/z_super.rb +30 -30
  184. data/lib/solargraph/source/chain.rb +291 -252
  185. data/lib/solargraph/source/change.rb +82 -82
  186. data/lib/solargraph/source/cursor.rb +166 -167
  187. data/lib/solargraph/source/encoding_fixes.rb +23 -23
  188. data/lib/solargraph/source/source_chainer.rb +194 -194
  189. data/lib/solargraph/source/updater.rb +55 -55
  190. data/lib/solargraph/source.rb +498 -495
  191. data/lib/solargraph/source_map/clip.rb +226 -232
  192. data/lib/solargraph/source_map/data.rb +34 -30
  193. data/lib/solargraph/source_map/mapper.rb +259 -255
  194. data/lib/solargraph/source_map.rb +212 -217
  195. data/lib/solargraph/type_checker/checks.rb +124 -120
  196. data/lib/solargraph/type_checker/param_def.rb +37 -35
  197. data/lib/solargraph/type_checker/problem.rb +32 -32
  198. data/lib/solargraph/type_checker/rules.rb +84 -62
  199. data/lib/solargraph/type_checker.rb +814 -672
  200. data/lib/solargraph/version.rb +5 -5
  201. data/lib/solargraph/views/_method.erb +10 -10
  202. data/lib/solargraph/views/_namespace.erb +3 -3
  203. data/lib/solargraph/views/document.erb +10 -10
  204. data/lib/solargraph/workspace/config.rb +255 -239
  205. data/lib/solargraph/workspace/require_paths.rb +97 -0
  206. data/lib/solargraph/workspace.rb +220 -239
  207. data/lib/solargraph/yard_map/helpers.rb +44 -16
  208. data/lib/solargraph/yard_map/mapper/to_constant.rb +7 -5
  209. data/lib/solargraph/yard_map/mapper/to_method.rb +130 -94
  210. data/lib/solargraph/yard_map/mapper/to_namespace.rb +31 -28
  211. data/lib/solargraph/yard_map/mapper.rb +79 -78
  212. data/lib/solargraph/yard_map/to_method.rb +89 -86
  213. data/lib/solargraph/yard_tags.rb +20 -20
  214. data/lib/solargraph/yardoc.rb +87 -52
  215. data/lib/solargraph.rb +105 -72
  216. data/rbs/fills/bundler/0/bundler.rbs +4271 -0
  217. data/rbs/fills/open3/0/open3.rbs +172 -0
  218. data/rbs/fills/rubygems/0/basic_specification.rbs +326 -0
  219. data/rbs/fills/rubygems/0/errors.rbs +364 -0
  220. data/rbs/fills/rubygems/0/spec_fetcher.rbs +107 -0
  221. data/rbs/fills/rubygems/0/specification.rbs +1753 -0
  222. data/rbs/fills/tuple/tuple.rbs +149 -0
  223. data/rbs/shims/ast/0/node.rbs +5 -0
  224. data/rbs/shims/ast/2.4/.rbs_meta.yaml +9 -0
  225. data/rbs/shims/ast/2.4/ast.rbs +73 -0
  226. data/rbs/shims/parser/3.2.0.1/builders/default.rbs +195 -0
  227. data/rbs/shims/parser/3.2.0.1/manifest.yaml +7 -0
  228. data/rbs/shims/parser/3.2.0.1/parser.rbs +201 -0
  229. data/rbs/shims/parser/3.2.0.1/polyfill.rbs +4 -0
  230. data/rbs/shims/thor/1.2.0.1/.rbs_meta.yaml +9 -0
  231. data/rbs/shims/thor/1.2.0.1/manifest.yaml +7 -0
  232. data/rbs/shims/thor/1.2.0.1/thor.rbs +17 -0
  233. data/rbs_collection.yaml +19 -0
  234. data/solargraph.gemspec +27 -5
  235. metadata +215 -18
  236. data/lib/.rubocop.yml +0 -22
  237. data/lib/solargraph/cache.rb +0 -77
  238. data/lib/solargraph/parser/node_methods.rb +0 -83
@@ -1,386 +1,482 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class ComplexType
5
- # An individual type signature. A complex type can consist of multiple
6
- # unique types.
7
- #
8
- class UniqueType
9
- include TypeMethods
10
- include Equality
11
-
12
- attr_reader :all_params, :subtypes, :key_types
13
-
14
- # @sg-ignore Fix "Not enough arguments to Module#protected"
15
- protected def equality_fields
16
- [@name, @all_params, @subtypes, @key_types]
17
- end
18
-
19
- # Create a UniqueType with the specified name and an optional substring.
20
- # The substring is the parameter section of a parametrized type, e.g.,
21
- # for the type `Array<String>`, the name is `Array` and the substring is
22
- # `<String>`.
23
- #
24
- # @param name [String] The name of the type
25
- # @param substring [String] The substring of the type
26
- # @param make_rooted [Boolean, nil]
27
- # @return [UniqueType]
28
- def self.parse name, substring = '', make_rooted: nil
29
- if name.start_with?(':::')
30
- raise "Illegal prefix: #{name}"
31
- end
32
- if name.start_with?('::')
33
- name = name[2..-1]
34
- rooted = true
35
- elsif !can_root_name?(name)
36
- rooted = true
37
- else
38
- rooted = false
39
- end
40
- rooted = make_rooted unless make_rooted.nil?
41
-
42
- # @type [Array<ComplexType>]
43
- key_types = []
44
- # @type [Array<ComplexType>]
45
- subtypes = []
46
- parameters_type = nil
47
- unless substring.empty?
48
- subs = ComplexType.parse(substring[1..-2], partial: true)
49
- parameters_type = PARAMETERS_TYPE_BY_STARTING_TAG.fetch(substring[0])
50
- if parameters_type == :hash
51
- raise ComplexTypeError, "Bad hash type" unless !subs.is_a?(ComplexType) and subs.length == 2 and !subs[0].is_a?(UniqueType) and !subs[1].is_a?(UniqueType)
52
- # @todo should be able to resolve map; both types have it
53
- # with same return type
54
- # @sg-ignore
55
- key_types.concat(subs[0].map { |u| ComplexType.new([u]) })
56
- # @sg-ignore
57
- subtypes.concat(subs[1].map { |u| ComplexType.new([u]) })
58
- else
59
- subtypes.concat subs
60
- end
61
- end
62
- new(name, key_types, subtypes, rooted: rooted, parameters_type: parameters_type)
63
- end
64
-
65
- # @param name [String]
66
- # @param key_types [Array<ComplexType>]
67
- # @param subtypes [Array<ComplexType>]
68
- # @param rooted [Boolean]
69
- # @param parameters_type [Symbol, nil]
70
- def initialize(name, key_types = [], subtypes = [], rooted:, parameters_type: nil)
71
- if parameters_type.nil?
72
- raise "You must supply parameters_type if you provide parameters" unless key_types.empty? && subtypes.empty?
73
- end
74
- raise "Please remove leading :: and set rooted instead - #{name.inspect}" if name.start_with?('::')
75
- @name = name
76
- @key_types = key_types
77
- @subtypes = subtypes
78
- @rooted = rooted
79
- @all_params = []
80
- @all_params.concat key_types
81
- @all_params.concat subtypes
82
- @parameters_type = parameters_type
83
- end
84
-
85
- def to_s
86
- tag
87
- end
88
-
89
- def eql?(other)
90
- self.class == other.class &&
91
- @name == other.name &&
92
- @key_types == other.key_types &&
93
- @subtypes == other.subtypes &&
94
- @rooted == other.rooted? &&
95
- @all_params == other.all_params &&
96
- @parameters_type == other.parameters_type
97
- end
98
-
99
- def ==(other)
100
- eql?(other)
101
- end
102
-
103
- def hash
104
- [self.class, @name, @key_types, @sub_types, @rooted, @all_params, @parameters_type].hash
105
- end
106
-
107
- # @return [Array<UniqueType>]
108
- def items
109
- [self]
110
- end
111
-
112
- # @return [String]
113
- def rbs_name
114
- if name == 'undefined'
115
- 'untyped'
116
- else
117
- rooted_name
118
- end
119
- end
120
-
121
- def desc
122
- rooted_tags
123
- end
124
-
125
- # @return [String]
126
- def to_rbs
127
- if duck_type?
128
- 'untyped'
129
- elsif name == 'Boolean'
130
- 'bool'
131
- elsif name.downcase == 'nil'
132
- 'nil'
133
- elsif name == GENERIC_TAG_NAME
134
- all_params.first.name
135
- elsif ['Class', 'Module'].include?(name)
136
- rbs_name
137
- elsif ['Tuple', 'Array'].include?(name) && fixed_parameters?
138
- # tuples don't have a name; they're just [foo, bar, baz].
139
- if substring == '()'
140
- # but there are no zero element tuples, so we go with an array
141
- if rooted?
142
- '::Array[]'
143
- else
144
- 'Array[]'
145
- end
146
- else
147
- # already generated surrounded by []
148
- parameters_as_rbs
149
- end
150
- else
151
- "#{rbs_name}#{parameters_as_rbs}"
152
- end
153
- end
154
-
155
- # @return [Boolean]
156
- def parameters?
157
- !all_params.empty?
158
- end
159
-
160
- # @param types [Array<UniqueType, ComplexType>]
161
- # @return [String]
162
- def rbs_union(types)
163
- if types.length == 1
164
- types.first.to_rbs
165
- else
166
- "(#{types.map(&:to_rbs).join(' | ')})"
167
- end
168
- end
169
-
170
- # @return [String]
171
- def parameters_as_rbs
172
- return '' unless parameters?
173
-
174
- return "[#{all_params.map(&:to_rbs).join(', ')}]" if key_types.empty?
175
-
176
- # handle, e.g., Hash[K, V] case
177
- key_types_str = rbs_union(key_types)
178
- subtypes_str = rbs_union(subtypes)
179
- "[#{key_types_str}, #{subtypes_str}]"
180
- end
181
-
182
- def generic?
183
- name == GENERIC_TAG_NAME || all_params.any?(&:generic?)
184
- end
185
-
186
- # @param generics_to_resolve [Enumerable<String>]
187
- # @param context_type [UniqueType, nil]
188
- # @param resolved_generic_values [Hash{String => ComplexType}] Added to as types are encountered or resolved
189
- # @return [UniqueType, ComplexType]
190
- def resolve_generics_from_context generics_to_resolve, context_type, resolved_generic_values: {}
191
- if name == ComplexType::GENERIC_TAG_NAME
192
- type_param = subtypes.first&.name
193
- return self unless generics_to_resolve.include? type_param
194
- unless context_type.nil? || !resolved_generic_values[type_param].nil?
195
- new_binding = true
196
- resolved_generic_values[type_param] = context_type
197
- end
198
- if new_binding
199
- resolved_generic_values.transform_values! do |complex_type|
200
- complex_type.resolve_generics_from_context(generics_to_resolve, nil, resolved_generic_values: resolved_generic_values)
201
- end
202
- end
203
- return resolved_generic_values[type_param] || self
204
- end
205
-
206
- # @todo typechecking should complain when the method being called has no @yieldparam tag
207
- new_key_types = resolve_param_generics_from_context(generics_to_resolve, context_type, resolved_generic_values, &:key_types)
208
- new_subtypes = resolve_param_generics_from_context(generics_to_resolve, context_type, resolved_generic_values, &:subtypes)
209
- recreate(new_key_types: new_key_types, new_subtypes: new_subtypes)
210
- end
211
-
212
- # @param generics_to_resolve [Enumerable<String>]
213
- # @param context_type [UniqueType]
214
- # @param resolved_generic_values [Hash{String => ComplexType}]
215
- # @yieldreturn [Array<ComplexType>]
216
- # @return [Array<ComplexType>]
217
- def resolve_param_generics_from_context(generics_to_resolve, context_type, resolved_generic_values)
218
- types = yield self
219
- types.each_with_index.flat_map do |ct, i|
220
- ct.items.flat_map do |ut|
221
- context_params = yield context_type if context_type
222
- if context_params && context_params[i]
223
- type_arg = context_params[i]
224
- type_arg.map do |new_unique_context_type|
225
- ut.resolve_generics_from_context generics_to_resolve, new_unique_context_type, resolved_generic_values: resolved_generic_values
226
- end
227
- else
228
- ut.resolve_generics_from_context generics_to_resolve, nil, resolved_generic_values: resolved_generic_values
229
- end
230
- end
231
- end
232
- end
233
-
234
- # Probe the concrete type for each of the generic type
235
- # parameters used in this type, and return a new type if
236
- # possible.
237
- #
238
- # @param definitions [Pin::Namespace, Pin::Method] The module/class/method which uses generic types
239
- # @param context_type [ComplexType] The receiver type
240
- # @return [UniqueType, ComplexType]
241
- def resolve_generics definitions, context_type
242
- return self if definitions.nil? || definitions.generics.empty?
243
-
244
- transform(name) do |t|
245
- if t.name == GENERIC_TAG_NAME
246
- idx = definitions.generics.index(t.subtypes.first&.name)
247
- next t if idx.nil?
248
- if context_type.parameters_type == :hash
249
- if idx == 0
250
- next ComplexType.new(context_type.key_types)
251
- elsif idx == 1
252
- next ComplexType.new(context_type.subtypes)
253
- else
254
- next ComplexType::UNDEFINED
255
- end
256
- else
257
- context_type.all_params[idx] || ComplexType::UNDEFINED
258
- end
259
- else
260
- t
261
- end
262
- end
263
- end
264
-
265
- # @yieldparam t [self]
266
- # @yieldreturn [self]
267
- # @return [Array<self>]
268
- def map &block
269
- [block.yield(self)]
270
- end
271
-
272
- # @return [Array<UniqueType>]
273
- def to_a
274
- [self]
275
- end
276
-
277
- # @param new_name [String, nil]
278
- # @param make_rooted [Boolean, nil]
279
- # @param new_key_types [Array<UniqueType>, nil]
280
- # @param rooted [Boolean, nil]
281
- # @param new_subtypes [Array<UniqueType>, nil]
282
- # @return [self]
283
- def recreate(new_name: nil, make_rooted: nil, new_key_types: nil, new_subtypes: nil)
284
- raise "Please remove leading :: and set rooted instead - #{new_name}" if new_name&.start_with?('::')
285
-
286
- new_name ||= name
287
- new_key_types ||= @key_types
288
- new_subtypes ||= @subtypes
289
- make_rooted = @rooted if make_rooted.nil?
290
- UniqueType.new(new_name, new_key_types, new_subtypes, rooted: make_rooted, parameters_type: parameters_type)
291
- end
292
-
293
- # @return [String]
294
- def rooted_tags
295
- rooted_tag
296
- end
297
-
298
- # @return [String]
299
- def tags
300
- tag
301
- end
302
-
303
- # @return [self]
304
- def force_rooted
305
- transform do |t|
306
- t.recreate(make_rooted: true)
307
- end
308
- end
309
-
310
- # Apply the given transformation to each subtype and then finally to this type
311
- #
312
- # @param new_name [String, nil]
313
- # @yieldparam t [UniqueType]
314
- # @yieldreturn [self]
315
- # @return [self]
316
- def transform(new_name = nil, &transform_type)
317
- raise "Please remove leading :: and set rooted with recreate() instead - #{new_name}" if new_name&.start_with?('::')
318
- if name == ComplexType::GENERIC_TAG_NAME
319
- # doesn't make sense to manipulate the name of the generic
320
- new_key_types = @key_types
321
- new_subtypes = @subtypes
322
- else
323
- new_key_types = @key_types.flat_map { |ct| ct.items.map { |ut| ut.transform(&transform_type) } }
324
- new_subtypes = @subtypes.flat_map { |ct| ct.items.map { |ut| ut.transform(&transform_type) } }
325
- end
326
- new_type = recreate(new_name: new_name || name, new_key_types: new_key_types, new_subtypes: new_subtypes, make_rooted: @rooted)
327
- yield new_type
328
- end
329
-
330
- # Generate a ComplexType that fully qualifies this type's namespaces.
331
- #
332
- # @param api_map [ApiMap] The ApiMap that performs qualification
333
- # @param context [String] The namespace from which to resolve names
334
- # @return [self, ComplexType, UniqueType] The generated ComplexType
335
- def qualify api_map, context = ''
336
- transform do |t|
337
- next t if t.name == GENERIC_TAG_NAME
338
- next t if t.duck_type? || t.void? || t.undefined?
339
- recon = (t.rooted? ? '' : context)
340
- fqns = api_map.qualify(t.name, recon)
341
- if fqns.nil?
342
- next UniqueType::BOOLEAN if t.tag == 'Boolean'
343
- next UniqueType::UNDEFINED
344
- end
345
- t.recreate(new_name: fqns, make_rooted: true)
346
- end
347
- end
348
-
349
- def selfy?
350
- @name == 'self' || @key_types.any?(&:selfy?) || @subtypes.any?(&:selfy?)
351
- end
352
-
353
- # @param dst [ComplexType]
354
- # @return [self]
355
- def self_to_type dst
356
- object_type_dst = dst.reduce_class_type
357
- transform do |t|
358
- next t if t.name != 'self'
359
- object_type_dst
360
- end
361
- end
362
-
363
- def all_rooted?
364
- return true if name == GENERIC_TAG_NAME
365
- rooted? && all_params.all?(&:rooted?)
366
- end
367
-
368
- def rooted?
369
- !can_root_name? || @rooted
370
- end
371
-
372
- def can_root_name?(name_to_check = name)
373
- self.class.can_root_name?(name_to_check)
374
- end
375
-
376
- # @param name [String]
377
- def self.can_root_name?(name)
378
- # name is not lowercase
379
- !name.empty? && name != name.downcase
380
- end
381
-
382
- UNDEFINED = UniqueType.new('undefined', rooted: false)
383
- BOOLEAN = UniqueType.new('Boolean', rooted: true)
384
- end
385
- end
386
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ class ComplexType
5
+ # An individual type signature. A complex type can consist of multiple
6
+ # unique types.
7
+ #
8
+ class UniqueType
9
+ include TypeMethods
10
+ include Equality
11
+
12
+ attr_reader :all_params, :subtypes, :key_types
13
+
14
+ # @sg-ignore Fix "Not enough arguments to Module#protected"
15
+ protected def equality_fields
16
+ [@name, @all_params, @subtypes, @key_types]
17
+ end
18
+
19
+ # Create a UniqueType with the specified name and an optional substring.
20
+ # The substring is the parameter section of a parametrized type, e.g.,
21
+ # for the type `Array<String>`, the name is `Array` and the substring is
22
+ # `<String>`.
23
+ #
24
+ # @param name [String] The name of the type
25
+ # @param substring [String] The substring of the type
26
+ # @param make_rooted [Boolean, nil]
27
+ # @return [UniqueType]
28
+ def self.parse name, substring = '', make_rooted: nil
29
+ if name.start_with?(':::')
30
+ raise ComplexTypeError, "Illegal prefix: #{name}"
31
+ end
32
+ if name.start_with?('::')
33
+ name = name[2..-1]
34
+ rooted = true
35
+ elsif !can_root_name?(name)
36
+ rooted = true
37
+ else
38
+ rooted = false
39
+ end
40
+ rooted = make_rooted unless make_rooted.nil?
41
+
42
+ # @type [Array<ComplexType>]
43
+ key_types = []
44
+ # @type [Array<ComplexType>]
45
+ subtypes = []
46
+ parameters_type = nil
47
+ unless substring.empty?
48
+ subs = ComplexType.parse(substring[1..-2], partial: true)
49
+ parameters_type = PARAMETERS_TYPE_BY_STARTING_TAG.fetch(substring[0])
50
+ if parameters_type == :hash
51
+ raise ComplexTypeError, "Bad hash type: name=#{name}, substring=#{substring}" unless !subs.is_a?(ComplexType) and subs.length == 2 and !subs[0].is_a?(UniqueType) and !subs[1].is_a?(UniqueType)
52
+ key_types.concat(subs[0].map { |u| ComplexType.new([u]) })
53
+ subtypes.concat(subs[1].map { |u| ComplexType.new([u]) })
54
+ elsif parameters_type == :list && name == 'Hash'
55
+ # Treat Hash<A, B> as Hash{A => B}
56
+ if subs.length != 2
57
+ raise ComplexTypeError, "Bad hash type: name=#{name}, substring=#{substring} - must have exactly two parameters"
58
+ end
59
+ key_types.concat(subs[0].map { |u| ComplexType.new([u]) })
60
+ subtypes.concat(subs[1].map { |u| ComplexType.new([u]) })
61
+ else
62
+ subtypes.concat subs
63
+ end
64
+ end
65
+ new(name, key_types, subtypes, rooted: rooted, parameters_type: parameters_type)
66
+ end
67
+
68
+ # @param name [String]
69
+ # @param key_types [Array<ComplexType>]
70
+ # @param subtypes [Array<ComplexType>]
71
+ # @param rooted [Boolean]
72
+ # @param parameters_type [Symbol, nil]
73
+ def initialize(name, key_types = [], subtypes = [], rooted:, parameters_type: nil)
74
+ if parameters_type.nil?
75
+ raise "You must supply parameters_type if you provide parameters" unless key_types.empty? && subtypes.empty?
76
+ end
77
+ raise "Please remove leading :: and set rooted instead - #{name.inspect}" if name.start_with?('::')
78
+ @name = name
79
+ @parameters_type = parameters_type
80
+ if implicit_union?
81
+ @key_types = key_types.uniq
82
+ @subtypes = subtypes.uniq
83
+ else
84
+ @key_types = key_types
85
+ @subtypes = subtypes
86
+ end
87
+ @rooted = rooted
88
+ @all_params = []
89
+ @all_params.concat @key_types
90
+ @all_params.concat @subtypes
91
+ end
92
+
93
+ def implicit_union?
94
+ # @todo use api_map to establish number of generics in type;
95
+ # if only one is allowed but multiple are passed in, treat
96
+ # those as implicit unions
97
+ ['Hash', 'Array', 'Set', '_ToAry', 'Enumerable', '_Each'].include?(name) && parameters_type != :fixed
98
+ end
99
+
100
+ def to_s
101
+ tag
102
+ end
103
+
104
+ # @return [self]
105
+ def simplify_literals
106
+ transform do |t|
107
+ next t unless t.literal?
108
+ t.recreate(new_name: t.non_literal_name)
109
+ end
110
+ end
111
+
112
+ def literal?
113
+ non_literal_name != name
114
+ end
115
+
116
+ # @return [String]
117
+ def non_literal_name
118
+ @non_literal_name ||= determine_non_literal_name
119
+ end
120
+
121
+ # @return [String]
122
+ def determine_non_literal_name
123
+ # https://github.com/ruby/rbs/blob/master/docs/syntax.md
124
+ #
125
+ # _literal_ ::= _string-literal_
126
+ # | _symbol-literal_
127
+ # | _integer-literal_
128
+ # | `true`
129
+ # | `false`
130
+ return name if name.empty?
131
+ return 'NilClass' if name == 'nil'
132
+ return 'Boolean' if ['true', 'false'].include?(name)
133
+ return 'Symbol' if name[0] == ':'
134
+ return 'String' if ['"', "'"].include?(name[0])
135
+ return 'Integer' if name.match?(/^-?\d+$/)
136
+ name
137
+ end
138
+
139
+ def eql?(other)
140
+ self.class == other.class &&
141
+ # @sg-ignore https://github.com/castwide/solargraph/pull/1114
142
+ @name == other.name &&
143
+ # @sg-ignore https://github.com/castwide/solargraph/pull/1114
144
+ @key_types == other.key_types &&
145
+ # @sg-ignore https://github.com/castwide/solargraph/pull/1114
146
+ @subtypes == other.subtypes &&
147
+ # @sg-ignore https://github.com/castwide/solargraph/pull/1114
148
+ @rooted == other.rooted? &&
149
+ # @sg-ignore https://github.com/castwide/solargraph/pull/1114
150
+ @all_params == other.all_params &&
151
+ # @sg-ignore https://github.com/castwide/solargraph/pull/1114
152
+ @parameters_type == other.parameters_type
153
+ end
154
+
155
+ def ==(other)
156
+ eql?(other)
157
+ end
158
+
159
+ def hash
160
+ [self.class, @name, @key_types, @sub_types, @rooted, @all_params, @parameters_type].hash
161
+ end
162
+
163
+ # @return [Array<UniqueType>]
164
+ def items
165
+ [self]
166
+ end
167
+
168
+ # @return [String]
169
+ def rbs_name
170
+ if name == 'undefined'
171
+ 'untyped'
172
+ elsif literal?
173
+ name
174
+ else
175
+ rooted_name
176
+ end
177
+ end
178
+
179
+ # @return [String]
180
+ def desc
181
+ rooted_tags
182
+ end
183
+
184
+ # @return [String]
185
+ def to_rbs
186
+ if duck_type?
187
+ 'untyped'
188
+ elsif name == 'Boolean'
189
+ 'bool'
190
+ elsif name.downcase == 'nil'
191
+ 'nil'
192
+ elsif name == GENERIC_TAG_NAME
193
+ all_params.first.name
194
+ elsif ['Class', 'Module'].include?(name)
195
+ rbs_name
196
+ elsif ['Tuple', 'Array'].include?(name) && fixed_parameters?
197
+ # tuples don't have a name; they're just [foo, bar, baz].
198
+ if substring == '()'
199
+ # but there are no zero element tuples, so we go with an array
200
+ if rooted?
201
+ '::Array[]'
202
+ else
203
+ 'Array[]'
204
+ end
205
+ else
206
+ # already generated surrounded by []
207
+ parameters_as_rbs
208
+ end
209
+ else
210
+ "#{rbs_name}#{parameters_as_rbs}"
211
+ end
212
+ end
213
+
214
+ # @return [Boolean]
215
+ def parameters?
216
+ !all_params.empty?
217
+ end
218
+
219
+ # @param types [Array<UniqueType, ComplexType>]
220
+ # @return [String]
221
+ def rbs_union(types)
222
+ if types.length == 1
223
+ types.first.to_rbs
224
+ else
225
+ "(#{types.map(&:to_rbs).join(' | ')})"
226
+ end
227
+ end
228
+
229
+ # @return [String]
230
+ def parameters_as_rbs
231
+ return '' unless parameters?
232
+
233
+ return "[#{all_params.map(&:to_rbs).join(', ')}]" if key_types.empty?
234
+
235
+ # handle, e.g., Hash[K, V] case
236
+ key_types_str = rbs_union(key_types)
237
+ subtypes_str = rbs_union(subtypes)
238
+ "[#{key_types_str}, #{subtypes_str}]"
239
+ end
240
+
241
+ def generic?
242
+ name == GENERIC_TAG_NAME || all_params.any?(&:generic?)
243
+ end
244
+
245
+ # @param api_map [ApiMap] The ApiMap that performs qualification
246
+ # @param atype [ComplexType] type which may be assigned to this type
247
+ def can_assign?(api_map, atype)
248
+ logger.debug { "UniqueType#can_assign?(self=#{rooted_tags.inspect}, atype=#{atype.rooted_tags.inspect})" }
249
+ downcasted_atype = atype.downcast_to_literal_if_possible
250
+ out = downcasted_atype.all? do |autype|
251
+ autype.name == name || api_map.super_and_sub?(name, autype.name)
252
+ end
253
+ logger.debug { "UniqueType#can_assign?(self=#{rooted_tags.inspect}, atype=#{atype.rooted_tags.inspect}) => #{out}" }
254
+ out
255
+ end
256
+
257
+ # @return [UniqueType]
258
+ def downcast_to_literal_if_possible
259
+ SINGLE_SUBTYPE.fetch(rooted_tag, self)
260
+ end
261
+
262
+ # @param generics_to_resolve [Enumerable<String>]
263
+ # @param context_type [UniqueType, nil]
264
+ # @param resolved_generic_values [Hash{String => ComplexType, ComplexType::UniqueType}] Added to as types are encountered or resolved
265
+ # @return [UniqueType, ComplexType]
266
+ def resolve_generics_from_context generics_to_resolve, context_type, resolved_generic_values: {}
267
+ if name == ComplexType::GENERIC_TAG_NAME
268
+ type_param = subtypes.first&.name
269
+ return self unless generics_to_resolve.include? type_param
270
+ unless context_type.nil? || !resolved_generic_values[type_param].nil?
271
+ new_binding = true
272
+ resolved_generic_values[type_param] = context_type
273
+ end
274
+ if new_binding
275
+ resolved_generic_values.transform_values! do |complex_type|
276
+ complex_type.resolve_generics_from_context(generics_to_resolve, nil, resolved_generic_values: resolved_generic_values)
277
+ end
278
+ end
279
+ return resolved_generic_values[type_param] || self
280
+ end
281
+
282
+ # @todo typechecking should complain when the method being called has no @yieldparam tag
283
+ new_key_types = resolve_param_generics_from_context(generics_to_resolve, context_type, resolved_generic_values, &:key_types)
284
+ new_subtypes = resolve_param_generics_from_context(generics_to_resolve, context_type, resolved_generic_values, &:subtypes)
285
+ recreate(new_key_types: new_key_types, new_subtypes: new_subtypes)
286
+ end
287
+
288
+ # @param generics_to_resolve [Enumerable<String>]
289
+ # @param context_type [UniqueType, nil]
290
+ # @param resolved_generic_values [Hash{String => ComplexType}]
291
+ # @yieldreturn [Array<ComplexType>]
292
+ # @return [Array<ComplexType>]
293
+ def resolve_param_generics_from_context(generics_to_resolve, context_type, resolved_generic_values)
294
+ types = yield self
295
+ types.each_with_index.flat_map do |ct, i|
296
+ ct.items.flat_map do |ut|
297
+ context_params = yield context_type if context_type
298
+ if context_params && context_params[i]
299
+ type_arg = context_params[i]
300
+ type_arg.map do |new_unique_context_type|
301
+ ut.resolve_generics_from_context generics_to_resolve, new_unique_context_type, resolved_generic_values: resolved_generic_values
302
+ end
303
+ else
304
+ ut.resolve_generics_from_context generics_to_resolve, nil, resolved_generic_values: resolved_generic_values
305
+ end
306
+ end
307
+ end
308
+ end
309
+
310
+ # Probe the concrete type for each of the generic type
311
+ # parameters used in this type, and return a new type if
312
+ # possible.
313
+ #
314
+ # @param definitions [Pin::Namespace, Pin::Method] The module/class/method which uses generic types
315
+ # @param context_type [ComplexType] The receiver type
316
+ # @return [UniqueType, ComplexType]
317
+ def resolve_generics definitions, context_type
318
+ return self if definitions.nil? || definitions.generics.empty?
319
+
320
+ transform(name) do |t|
321
+ if t.name == GENERIC_TAG_NAME
322
+ generic_name = t.subtypes.first&.name
323
+ idx = definitions.generics.index(generic_name)
324
+ next t if idx.nil?
325
+ if context_type.parameters_type == :hash
326
+ if idx == 0
327
+ next ComplexType.new(context_type.key_types)
328
+ elsif idx == 1
329
+ next ComplexType.new(context_type.subtypes)
330
+ else
331
+ next ComplexType::UNDEFINED
332
+ end
333
+ elsif context_type.all?(&:implicit_union?)
334
+ if idx == 0 && !context_type.all_params.empty?
335
+ ComplexType.new(context_type.all_params)
336
+ else
337
+ ComplexType::UNDEFINED
338
+ end
339
+ else
340
+ context_type.all_params[idx] || definitions.generic_defaults[generic_name] || ComplexType::UNDEFINED
341
+ end
342
+ else
343
+ t
344
+ end
345
+ end
346
+ end
347
+
348
+ # @yieldparam t [self]
349
+ # @yieldreturn [self]
350
+ # @return [Array<self>]
351
+ def map &block
352
+ [block.yield(self)]
353
+ end
354
+
355
+ # @return [Array<UniqueType>]
356
+ def to_a
357
+ [self]
358
+ end
359
+
360
+ # @param new_name [String, nil]
361
+ # @param make_rooted [Boolean, nil]
362
+ # @param new_key_types [Array<ComplexType>, nil]
363
+ # @param rooted [Boolean, nil]
364
+ # @param new_subtypes [Array<ComplexType>, nil]
365
+ # @return [self]
366
+ def recreate(new_name: nil, make_rooted: nil, new_key_types: nil, new_subtypes: nil)
367
+ raise "Please remove leading :: and set rooted instead - #{new_name}" if new_name&.start_with?('::')
368
+
369
+ new_name ||= name
370
+ new_key_types ||= @key_types
371
+ new_subtypes ||= @subtypes
372
+ make_rooted = @rooted if make_rooted.nil?
373
+ UniqueType.new(new_name, new_key_types, new_subtypes, rooted: make_rooted, parameters_type: parameters_type)
374
+ end
375
+
376
+ # @return [String]
377
+ def rooted_tags
378
+ rooted_tag
379
+ end
380
+
381
+ # @return [String]
382
+ def tags
383
+ tag
384
+ end
385
+
386
+ # @return [self]
387
+ def force_rooted
388
+ transform do |t|
389
+ t.recreate(make_rooted: true)
390
+ end
391
+ end
392
+
393
+ # Apply the given transformation to each subtype and then finally to this type
394
+ #
395
+ # @param new_name [String, nil]
396
+ # @yieldparam t [UniqueType]
397
+ # @yieldreturn [self]
398
+ # @return [self]
399
+ def transform(new_name = nil, &transform_type)
400
+ raise "Please remove leading :: and set rooted with recreate() instead - #{new_name}" if new_name&.start_with?('::')
401
+ if name == ComplexType::GENERIC_TAG_NAME
402
+ # doesn't make sense to manipulate the name of the generic
403
+ new_key_types = @key_types
404
+ new_subtypes = @subtypes
405
+ else
406
+ new_key_types = @key_types.flat_map { |ct| ct.items.map { |ut| ut.transform(&transform_type) } }
407
+ new_subtypes = @subtypes.flat_map { |ct| ct.items.map { |ut| ut.transform(&transform_type) } }
408
+ end
409
+ new_type = recreate(new_name: new_name || name, new_key_types: new_key_types, new_subtypes: new_subtypes, make_rooted: @rooted)
410
+ yield new_type
411
+ end
412
+
413
+ # Generate a ComplexType that fully qualifies this type's namespaces.
414
+ #
415
+ # @param api_map [ApiMap] The ApiMap that performs qualification
416
+ # @param context [String] The namespace from which to resolve names
417
+ # @return [self, ComplexType, UniqueType] The generated ComplexType
418
+ def qualify api_map, *gates
419
+ transform do |t|
420
+ next t if t.name == GENERIC_TAG_NAME
421
+ next t if t.duck_type? || t.void? || t.undefined? || t.literal?
422
+ open = t.rooted? ? [''] : gates
423
+ fqns = api_map.qualify(t.non_literal_name, *open)
424
+ if fqns.nil?
425
+ next UniqueType::BOOLEAN if t.tag == 'Boolean'
426
+ next UniqueType::UNDEFINED
427
+ end
428
+ t.recreate(new_name: fqns, make_rooted: true)
429
+ end
430
+ end
431
+
432
+ def selfy?
433
+ @name == 'self' || @key_types.any?(&:selfy?) || @subtypes.any?(&:selfy?)
434
+ end
435
+
436
+ # @param dst [ComplexType]
437
+ # @return [self]
438
+ def self_to_type dst
439
+ object_type_dst = dst.reduce_class_type
440
+ transform do |t|
441
+ next t if t.name != 'self'
442
+ object_type_dst
443
+ end
444
+ end
445
+
446
+ def all_rooted?
447
+ return true if name == GENERIC_TAG_NAME
448
+ rooted? && all_params.all?(&:rooted?)
449
+ end
450
+
451
+ def rooted?
452
+ !can_root_name? || @rooted
453
+ end
454
+
455
+ # @param name_to_check [String]
456
+ def can_root_name?(name_to_check = name)
457
+ self.class.can_root_name?(name_to_check)
458
+ end
459
+
460
+ # @param name [String]
461
+ def self.can_root_name?(name)
462
+ # name is not lowercase
463
+ !name.empty? && name != name.downcase
464
+ end
465
+
466
+ UNDEFINED = UniqueType.new('undefined', rooted: false)
467
+ BOOLEAN = UniqueType.new('Boolean', rooted: true)
468
+ TRUE = UniqueType.new('true', rooted: true)
469
+ FALSE = UniqueType.new('false', rooted: true)
470
+ NIL = UniqueType.new('nil', rooted: true)
471
+ # @type [Hash{String => UniqueType}]
472
+ SINGLE_SUBTYPE = {
473
+ '::TrueClass' => UniqueType::TRUE,
474
+ '::FalseClass' => UniqueType::FALSE,
475
+ '::NilClass' => UniqueType::NIL
476
+ }.freeze
477
+
478
+
479
+ include Logging
480
+ end
481
+ end
482
+ end