puppet 4.4.1 → 4.4.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (556) hide show
  1. data/lib/puppet/application/ca.rb +1 -0
  2. data/lib/puppet/application/lookup.rb +4 -16
  3. data/lib/puppet/application/resource.rb +0 -4
  4. data/lib/puppet/data_providers/hiera_interpolate.rb +8 -2
  5. data/lib/puppet/data_providers/json_data_provider_factory.rb +1 -1
  6. data/lib/puppet/defaults.rb +32 -16
  7. data/lib/puppet/file_system/uniquefile.rb +2 -2
  8. data/lib/puppet/file_system/windows.rb +1 -15
  9. data/lib/puppet/functions/assert_type.rb +1 -1
  10. data/lib/puppet/functions/lookup.rb +0 -3
  11. data/lib/puppet/indirector/catalog/compiler.rb +2 -1
  12. data/lib/puppet/indirector/msgpack.rb +1 -1
  13. data/lib/puppet/indirector/terminus.rb +4 -4
  14. data/lib/puppet/module.rb +3 -3
  15. data/lib/puppet/module_tool/applications/builder.rb +2 -2
  16. data/lib/puppet/network/auth_config_parser.rb +1 -1
  17. data/lib/puppet/network/http/api/indirected_routes.rb +0 -2
  18. data/lib/puppet/network/http/rack/rest.rb +10 -1
  19. data/lib/puppet/parser/functions/lookup.rb +0 -3
  20. data/lib/puppet/pops/evaluator/access_operator.rb +25 -1
  21. data/lib/puppet/pops/evaluator/closure.rb +10 -5
  22. data/lib/puppet/pops/merge_strategy.rb +0 -10
  23. data/lib/puppet/pops/types/recursion_guard.rb +10 -0
  24. data/lib/puppet/pops/types/type_asserter.rb +2 -2
  25. data/lib/puppet/pops/types/type_calculator.rb +1 -1
  26. data/lib/puppet/pops/types/type_formatter.rb +14 -2
  27. data/lib/puppet/pops/types/type_mismatch_describer.rb +22 -10
  28. data/lib/puppet/pops/types/types.rb +240 -98
  29. data/lib/puppet/provider/package/puppet_gem.rb +0 -0
  30. data/lib/puppet/provider/user/user_role_add.rb +3 -1
  31. data/lib/puppet/settings.rb +1 -1
  32. data/lib/puppet/ssl/oids.rb +24 -2
  33. data/lib/puppet/util/monkey_patches.rb +10 -5
  34. data/lib/puppet/util/windows.rb +1 -0
  35. data/lib/puppet/util/windows/file.rb +40 -10
  36. data/lib/puppet/version.rb +1 -1
  37. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/third_utf8.json +3 -0
  38. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/utf8.yaml +3 -0
  39. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/hiera.yaml +5 -1
  40. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/manifests/site.pp +2 -2
  41. data/spec/fixtures/unit/parser/lexer/subclass_name_duplication.pp +0 -0
  42. data/spec/fixtures/unit/pops/parser/lexer/subclass_name_duplication.pp +0 -0
  43. data/spec/integration/agent/logging_spec.rb +0 -0
  44. data/spec/integration/application/apply_spec.rb +0 -0
  45. data/spec/integration/application/doc_spec.rb +0 -0
  46. data/spec/integration/configurer_spec.rb +0 -0
  47. data/spec/integration/data_binding_spec.rb +0 -0
  48. data/spec/integration/defaults_spec.rb +0 -0
  49. data/spec/integration/faces/ca_spec.rb +0 -0
  50. data/spec/integration/faces/documentation_spec.rb +0 -0
  51. data/spec/integration/file_serving/fileset_spec.rb +0 -0
  52. data/spec/integration/file_serving/terminus_helper_spec.rb +0 -0
  53. data/spec/integration/indirector/catalog/compiler_spec.rb +0 -0
  54. data/spec/integration/indirector/direct_file_server_spec.rb +0 -0
  55. data/spec/integration/indirector/file_content/file_server_spec.rb +0 -0
  56. data/spec/integration/indirector/file_metadata/file_server_spec.rb +0 -0
  57. data/spec/integration/indirector/node/ldap_spec.rb +0 -0
  58. data/spec/integration/network/formats_spec.rb +0 -0
  59. data/spec/integration/node/environment_spec.rb +0 -0
  60. data/spec/integration/node/facts_spec.rb +0 -0
  61. data/spec/integration/node_spec.rb +0 -0
  62. data/spec/integration/parser/collection_spec.rb +0 -0
  63. data/spec/integration/parser/compiler_spec.rb +0 -0
  64. data/spec/integration/parser/functions/require_spec.rb +0 -0
  65. data/spec/integration/parser/parameter_defaults_spec.rb +19 -1
  66. data/spec/integration/provider/mailalias/aliases_spec.rb +0 -0
  67. data/spec/integration/provider/mount_spec.rb +0 -0
  68. data/spec/integration/provider/package_spec.rb +0 -0
  69. data/spec/integration/provider/service/init_spec.rb +0 -0
  70. data/spec/integration/provider/ssh_authorized_key_spec.rb +0 -0
  71. data/spec/integration/reference/providers_spec.rb +0 -0
  72. data/spec/integration/reports_spec.rb +0 -0
  73. data/spec/integration/resource/catalog_spec.rb +0 -0
  74. data/spec/integration/resource/type_collection_spec.rb +0 -0
  75. data/spec/integration/ssl/certificate_authority_spec.rb +0 -0
  76. data/spec/integration/ssl/certificate_request_spec.rb +0 -0
  77. data/spec/integration/ssl/certificate_revocation_list_spec.rb +0 -0
  78. data/spec/integration/ssl/host_spec.rb +0 -0
  79. data/spec/integration/transaction/report_spec.rb +0 -0
  80. data/spec/integration/transaction_spec.rb +0 -0
  81. data/spec/integration/type/exec_spec.rb +0 -0
  82. data/spec/integration/type/file_spec.rb +0 -0
  83. data/spec/integration/type/package_spec.rb +0 -0
  84. data/spec/integration/type/tidy_spec.rb +0 -0
  85. data/spec/integration/type_spec.rb +0 -0
  86. data/spec/integration/util/autoload_spec.rb +0 -0
  87. data/spec/integration/util/rdoc/parser_spec.rb +0 -0
  88. data/spec/integration/util/settings_spec.rb +26 -0
  89. data/spec/integration/util/windows/registry_spec.rb +0 -0
  90. data/spec/integration/util/windows/security_spec.rb +0 -0
  91. data/spec/integration/util/windows/user_spec.rb +0 -0
  92. data/spec/integration/util_spec.rb +0 -0
  93. data/spec/lib/puppet/face/1.0.0/huzzah.rb +0 -0
  94. data/spec/lib/puppet/face/basetest.rb +0 -0
  95. data/spec/lib/puppet/face/huzzah.rb +0 -0
  96. data/spec/lib/puppet_spec/files.rb +0 -0
  97. data/spec/lib/puppet_spec/fixtures.rb +0 -0
  98. data/spec/lib/puppet_spec/verbose.rb +0 -0
  99. data/spec/shared_behaviours/all_parsedfile_providers.rb +0 -0
  100. data/spec/shared_behaviours/file_server_terminus.rb +0 -0
  101. data/spec/shared_behaviours/file_serving.rb +0 -0
  102. data/spec/shared_behaviours/memory_terminus.rb +0 -0
  103. data/spec/shared_behaviours/path_parameters.rb +0 -0
  104. data/spec/shared_behaviours/things_that_declare_options.rb +0 -0
  105. data/spec/spec_helper.rb +0 -0
  106. data/spec/unit/agent/locker_spec.rb +0 -0
  107. data/spec/unit/agent_spec.rb +0 -0
  108. data/spec/unit/application/agent_spec.rb +0 -0
  109. data/spec/unit/application/apply_spec.rb +0 -0
  110. data/spec/unit/application/cert_spec.rb +0 -0
  111. data/spec/unit/application/certificate_spec.rb +0 -0
  112. data/spec/unit/application/config_spec.rb +0 -0
  113. data/spec/unit/application/describe_spec.rb +0 -0
  114. data/spec/unit/application/device_spec.rb +0 -0
  115. data/spec/unit/application/doc_spec.rb +0 -0
  116. data/spec/unit/application/face_base_spec.rb +0 -0
  117. data/spec/unit/application/facts_spec.rb +0 -0
  118. data/spec/unit/application/filebucket_spec.rb +0 -0
  119. data/spec/unit/application/indirection_base_spec.rb +0 -0
  120. data/spec/unit/application/inspect_spec.rb +0 -0
  121. data/spec/unit/application/lookup_spec.rb +1 -1
  122. data/spec/unit/application/master_spec.rb +0 -0
  123. data/spec/unit/application/resource_spec.rb +0 -0
  124. data/spec/unit/application_spec.rb +0 -0
  125. data/spec/unit/configurer/downloader_factory_spec.rb +0 -0
  126. data/spec/unit/configurer/downloader_spec.rb +0 -0
  127. data/spec/unit/configurer/fact_handler_spec.rb +0 -0
  128. data/spec/unit/configurer/plugin_handler_spec.rb +0 -0
  129. data/spec/unit/configurer_spec.rb +0 -0
  130. data/spec/unit/confine/exists_spec.rb +0 -0
  131. data/spec/unit/confine/false_spec.rb +0 -0
  132. data/spec/unit/confine/feature_spec.rb +0 -0
  133. data/spec/unit/confine/true_spec.rb +0 -0
  134. data/spec/unit/confine/variable_spec.rb +0 -0
  135. data/spec/unit/confine_collection_spec.rb +0 -0
  136. data/spec/unit/confine_spec.rb +0 -0
  137. data/spec/unit/confiner_spec.rb +0 -0
  138. data/spec/unit/daemon_spec.rb +0 -0
  139. data/spec/unit/data_providers/hiera_data_provider_spec.rb +1 -1
  140. data/spec/unit/data_providers/hiera_interpolation_spec.rb +6 -0
  141. data/spec/unit/external/pson_spec.rb +0 -0
  142. data/spec/unit/face/catalog_spec.rb +0 -0
  143. data/spec/unit/face/certificate_spec.rb +0 -0
  144. data/spec/unit/face/config_spec.rb +0 -0
  145. data/spec/unit/face/facts_spec.rb +0 -0
  146. data/spec/unit/face/file_spec.rb +0 -0
  147. data/spec/unit/face/help_spec.rb +0 -0
  148. data/spec/unit/face/node_spec.rb +0 -0
  149. data/spec/unit/face/plugin_spec.rb +0 -0
  150. data/spec/unit/face_spec.rb +0 -0
  151. data/spec/unit/file_bucket/dipper_spec.rb +0 -0
  152. data/spec/unit/file_bucket/file_spec.rb +0 -0
  153. data/spec/unit/file_serving/base_spec.rb +0 -0
  154. data/spec/unit/file_serving/configuration/parser_spec.rb +0 -0
  155. data/spec/unit/file_serving/configuration_spec.rb +0 -0
  156. data/spec/unit/file_serving/content_spec.rb +0 -0
  157. data/spec/unit/file_serving/fileset_spec.rb +0 -0
  158. data/spec/unit/file_serving/metadata_spec.rb +0 -0
  159. data/spec/unit/file_serving/mount/file_spec.rb +0 -0
  160. data/spec/unit/file_serving/mount/modules_spec.rb +0 -0
  161. data/spec/unit/file_serving/mount/pluginfacts_spec.rb +0 -0
  162. data/spec/unit/file_serving/mount/plugins_spec.rb +0 -0
  163. data/spec/unit/file_serving/mount_spec.rb +0 -0
  164. data/spec/unit/file_serving/terminus_helper_spec.rb +0 -0
  165. data/spec/unit/file_serving/terminus_selector_spec.rb +0 -0
  166. data/spec/unit/file_system/uniquefile_spec.rb +20 -0
  167. data/spec/unit/file_system_spec.rb +61 -0
  168. data/spec/unit/functions/assert_type_spec.rb +8 -0
  169. data/spec/unit/functions/defined_spec.rb +0 -0
  170. data/spec/unit/functions/hiera_spec.rb +0 -0
  171. data/spec/unit/functions/lookup_spec.rb +3 -3
  172. data/spec/unit/functions/regsubst_spec.rb +0 -0
  173. data/spec/unit/functions/split_spec.rb +0 -0
  174. data/spec/unit/functions/versioncmp_spec.rb +0 -0
  175. data/spec/unit/graph/relationship_graph_spec.rb +0 -0
  176. data/spec/unit/graph/simple_graph_spec.rb +0 -0
  177. data/spec/unit/indirector/catalog/compiler_spec.rb +7 -0
  178. data/spec/unit/indirector/catalog/json_spec.rb +0 -0
  179. data/spec/unit/indirector/catalog/msgpack_spec.rb +0 -0
  180. data/spec/unit/indirector/catalog/rest_spec.rb +0 -0
  181. data/spec/unit/indirector/catalog/static_compiler_spec.rb +0 -0
  182. data/spec/unit/indirector/catalog/store_configs_spec.rb +0 -0
  183. data/spec/unit/indirector/catalog/yaml_spec.rb +0 -0
  184. data/spec/unit/indirector/certificate/ca_spec.rb +0 -0
  185. data/spec/unit/indirector/certificate/disabled_ca_spec.rb +0 -0
  186. data/spec/unit/indirector/certificate/file_spec.rb +0 -0
  187. data/spec/unit/indirector/certificate/rest_spec.rb +0 -0
  188. data/spec/unit/indirector/certificate_request/ca_spec.rb +0 -0
  189. data/spec/unit/indirector/certificate_request/disabled_ca_spec.rb +0 -0
  190. data/spec/unit/indirector/certificate_request/file_spec.rb +0 -0
  191. data/spec/unit/indirector/certificate_request/rest_spec.rb +0 -0
  192. data/spec/unit/indirector/certificate_revocation_list/ca_spec.rb +0 -0
  193. data/spec/unit/indirector/certificate_revocation_list/disabled_ca_spec.rb +0 -0
  194. data/spec/unit/indirector/certificate_revocation_list/file_spec.rb +0 -0
  195. data/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +0 -0
  196. data/spec/unit/indirector/certificate_status/file_spec.rb +0 -0
  197. data/spec/unit/indirector/certificate_status/rest_spec.rb +0 -0
  198. data/spec/unit/indirector/code_spec.rb +0 -0
  199. data/spec/unit/indirector/direct_file_server_spec.rb +0 -0
  200. data/spec/unit/indirector/envelope_spec.rb +0 -0
  201. data/spec/unit/indirector/exec_spec.rb +0 -0
  202. data/spec/unit/indirector/face_spec.rb +0 -0
  203. data/spec/unit/indirector/facts/facter_spec.rb +0 -0
  204. data/spec/unit/indirector/facts/network_device_spec.rb +0 -0
  205. data/spec/unit/indirector/facts/store_configs_spec.rb +0 -0
  206. data/spec/unit/indirector/facts/yaml_spec.rb +0 -0
  207. data/spec/unit/indirector/file_bucket_file/file_spec.rb +0 -0
  208. data/spec/unit/indirector/file_bucket_file/rest_spec.rb +0 -0
  209. data/spec/unit/indirector/file_content/file_server_spec.rb +0 -0
  210. data/spec/unit/indirector/file_content/file_spec.rb +0 -0
  211. data/spec/unit/indirector/file_content/rest_spec.rb +0 -0
  212. data/spec/unit/indirector/file_metadata/file_server_spec.rb +0 -0
  213. data/spec/unit/indirector/file_metadata/file_spec.rb +0 -0
  214. data/spec/unit/indirector/file_metadata/rest_spec.rb +0 -0
  215. data/spec/unit/indirector/file_server_spec.rb +0 -0
  216. data/spec/unit/indirector/indirection_spec.rb +0 -0
  217. data/spec/unit/indirector/json_spec.rb +0 -0
  218. data/spec/unit/indirector/key/ca_spec.rb +0 -0
  219. data/spec/unit/indirector/key/disabled_ca_spec.rb +0 -0
  220. data/spec/unit/indirector/key/file_spec.rb +0 -0
  221. data/spec/unit/indirector/ldap_spec.rb +0 -0
  222. data/spec/unit/indirector/memory_spec.rb +0 -0
  223. data/spec/unit/indirector/msgpack_spec.rb +11 -1
  224. data/spec/unit/indirector/node/exec_spec.rb +0 -0
  225. data/spec/unit/indirector/node/ldap_spec.rb +0 -0
  226. data/spec/unit/indirector/node/memory_spec.rb +0 -0
  227. data/spec/unit/indirector/node/msgpack_spec.rb +0 -0
  228. data/spec/unit/indirector/node/plain_spec.rb +0 -0
  229. data/spec/unit/indirector/node/rest_spec.rb +0 -0
  230. data/spec/unit/indirector/node/store_configs_spec.rb +0 -0
  231. data/spec/unit/indirector/node/yaml_spec.rb +0 -0
  232. data/spec/unit/indirector/plain_spec.rb +0 -0
  233. data/spec/unit/indirector/report/msgpack_spec.rb +0 -0
  234. data/spec/unit/indirector/report/processor_spec.rb +0 -0
  235. data/spec/unit/indirector/report/rest_spec.rb +0 -0
  236. data/spec/unit/indirector/report/yaml_spec.rb +0 -0
  237. data/spec/unit/indirector/request_spec.rb +0 -0
  238. data/spec/unit/indirector/resource/ral_spec.rb +0 -0
  239. data/spec/unit/indirector/resource/store_configs_spec.rb +0 -0
  240. data/spec/unit/indirector/resource_type/parser_spec.rb +0 -0
  241. data/spec/unit/indirector/resource_type/rest_spec.rb +0 -0
  242. data/spec/unit/indirector/rest_spec.rb +0 -0
  243. data/spec/unit/indirector/ssl_file_spec.rb +0 -0
  244. data/spec/unit/indirector/status/rest_spec.rb +0 -0
  245. data/spec/unit/indirector/store_configs_spec.rb +0 -0
  246. data/spec/unit/indirector/terminus_spec.rb +0 -0
  247. data/spec/unit/indirector/yaml_spec.rb +0 -0
  248. data/spec/unit/indirector_spec.rb +0 -0
  249. data/spec/unit/interface/action_builder_spec.rb +0 -0
  250. data/spec/unit/interface/action_manager_spec.rb +0 -0
  251. data/spec/unit/interface/action_spec.rb +0 -0
  252. data/spec/unit/interface/documentation_spec.rb +0 -0
  253. data/spec/unit/interface/face_collection_spec.rb +0 -0
  254. data/spec/unit/interface/option_builder_spec.rb +0 -0
  255. data/spec/unit/interface/option_spec.rb +0 -0
  256. data/spec/unit/interface_spec.rb +0 -0
  257. data/spec/unit/man_spec.rb +0 -0
  258. data/spec/unit/module_spec.rb +30 -6
  259. data/spec/unit/module_tool/applications/builder_spec.rb +23 -3
  260. data/spec/unit/module_tool_spec.rb +0 -0
  261. data/spec/unit/network/auth_config_parser_spec.rb +16 -0
  262. data/spec/unit/network/authconfig_spec.rb +0 -0
  263. data/spec/unit/network/authstore_spec.rb +0 -0
  264. data/spec/unit/network/format_handler_spec.rb +0 -0
  265. data/spec/unit/network/format_spec.rb +0 -0
  266. data/spec/unit/network/formats_spec.rb +0 -0
  267. data/spec/unit/network/http/api/indirected_routes_spec.rb +21 -13
  268. data/spec/unit/network/http/api/master/v3_spec.rb +0 -0
  269. data/spec/unit/network/http/compression_spec.rb +0 -0
  270. data/spec/unit/network/http/connection_spec.rb +0 -0
  271. data/spec/unit/network/http/factory_spec.rb +0 -0
  272. data/spec/unit/network/http/handler_spec.rb +0 -0
  273. data/spec/unit/network/http/nocache_pool_spec.rb +0 -0
  274. data/spec/unit/network/http/pool_spec.rb +0 -0
  275. data/spec/unit/network/http/rack/rest_spec.rb +7 -0
  276. data/spec/unit/network/http/rack_spec.rb +0 -0
  277. data/spec/unit/network/http/session_spec.rb +0 -0
  278. data/spec/unit/network/http/site_spec.rb +0 -0
  279. data/spec/unit/network/http/webrick/rest_spec.rb +0 -0
  280. data/spec/unit/network/http/webrick_spec.rb +0 -0
  281. data/spec/unit/network/http_pool_spec.rb +0 -0
  282. data/spec/unit/network/http_spec.rb +0 -0
  283. data/spec/unit/network/resolver_spec.rb +0 -0
  284. data/spec/unit/network/rights_spec.rb +0 -0
  285. data/spec/unit/network/server_spec.rb +0 -0
  286. data/spec/unit/node/environment_spec.rb +0 -0
  287. data/spec/unit/node/facts_spec.rb +0 -0
  288. data/spec/unit/node_spec.rb +0 -0
  289. data/spec/unit/other/selinux_spec.rb +0 -0
  290. data/spec/unit/parameter/path_spec.rb +0 -0
  291. data/spec/unit/parameter/value_collection_spec.rb +0 -0
  292. data/spec/unit/parameter/value_spec.rb +0 -0
  293. data/spec/unit/parameter_spec.rb +0 -0
  294. data/spec/unit/parser/ast/leaf_spec.rb +0 -0
  295. data/spec/unit/parser/compiler_spec.rb +0 -0
  296. data/spec/unit/parser/files_spec.rb +0 -0
  297. data/spec/unit/parser/functions/create_resources_spec.rb +0 -0
  298. data/spec/unit/parser/functions/defined_spec.rb +0 -0
  299. data/spec/unit/parser/functions/digest_spec.rb +0 -0
  300. data/spec/unit/parser/functions/fail_spec.rb +0 -0
  301. data/spec/unit/parser/functions/file_spec.rb +0 -0
  302. data/spec/unit/parser/functions/fqdn_rand_spec.rb +0 -0
  303. data/spec/unit/parser/functions/generate_spec.rb +0 -0
  304. data/spec/unit/parser/functions/hiera_spec.rb +0 -0
  305. data/spec/unit/parser/functions/include_spec.rb +0 -0
  306. data/spec/unit/parser/functions/inline_template_spec.rb +0 -0
  307. data/spec/unit/parser/functions/realize_spec.rb +0 -0
  308. data/spec/unit/parser/functions/regsubst_spec.rb +0 -0
  309. data/spec/unit/parser/functions/require_spec.rb +0 -0
  310. data/spec/unit/parser/functions/scanf_spec.rb +0 -0
  311. data/spec/unit/parser/functions/shellquote_spec.rb +0 -0
  312. data/spec/unit/parser/functions/split_spec.rb +0 -0
  313. data/spec/unit/parser/functions/sprintf_spec.rb +0 -0
  314. data/spec/unit/parser/functions/tag_spec.rb +0 -0
  315. data/spec/unit/parser/functions/template_spec.rb +0 -0
  316. data/spec/unit/parser/functions/versioncmp_spec.rb +0 -0
  317. data/spec/unit/parser/functions_spec.rb +0 -0
  318. data/spec/unit/parser/relationship_spec.rb +0 -0
  319. data/spec/unit/parser/resource/param_spec.rb +0 -0
  320. data/spec/unit/parser/resource_spec.rb +0 -0
  321. data/spec/unit/parser/scope_spec.rb +0 -0
  322. data/spec/unit/parser/templatewrapper_spec.rb +0 -0
  323. data/spec/unit/parser/type_loader_spec.rb +0 -0
  324. data/spec/unit/pops/loaders/loaders_spec.rb +8 -8
  325. data/spec/unit/pops/types/type_asserter_spec.rb +3 -3
  326. data/spec/unit/pops/types/type_calculator_spec.rb +32 -6
  327. data/spec/unit/pops/types/type_factory_spec.rb +26 -0
  328. data/spec/unit/pops/types/type_formatter_spec.rb +7 -2
  329. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +25 -0
  330. data/spec/unit/pops/types/type_parser_spec.rb +1 -1
  331. data/spec/unit/pops/types/types_spec.rb +215 -0
  332. data/spec/unit/property/ensure_spec.rb +0 -0
  333. data/spec/unit/property/keyvalue_spec.rb +0 -0
  334. data/spec/unit/property/list_spec.rb +0 -0
  335. data/spec/unit/property/ordered_list_spec.rb +0 -0
  336. data/spec/unit/property_spec.rb +0 -0
  337. data/spec/unit/provider/augeas/augeas_spec.rb +0 -0
  338. data/spec/unit/provider/cisco_spec.rb +0 -0
  339. data/spec/unit/provider/command_spec.rb +0 -0
  340. data/spec/unit/provider/cron/crontab_spec.rb +0 -0
  341. data/spec/unit/provider/exec/posix_spec.rb +0 -0
  342. data/spec/unit/provider/exec/shell_spec.rb +0 -0
  343. data/spec/unit/provider/exec/windows_spec.rb +0 -0
  344. data/spec/unit/provider/exec_spec.rb +0 -0
  345. data/spec/unit/provider/file/posix_spec.rb +0 -0
  346. data/spec/unit/provider/file/windows_spec.rb +0 -0
  347. data/spec/unit/provider/group/groupadd_spec.rb +0 -0
  348. data/spec/unit/provider/group/ldap_spec.rb +0 -0
  349. data/spec/unit/provider/group/pw_spec.rb +0 -0
  350. data/spec/unit/provider/group/windows_adsi_spec.rb +0 -0
  351. data/spec/unit/provider/host/parsed_spec.rb +0 -0
  352. data/spec/unit/provider/interface/cisco_spec.rb +0 -0
  353. data/spec/unit/provider/ldap_spec.rb +0 -0
  354. data/spec/unit/provider/macauthorization_spec.rb +0 -0
  355. data/spec/unit/provider/mcx/mcxcontent_spec.rb +0 -0
  356. data/spec/unit/provider/mount/parsed_spec.rb +0 -0
  357. data/spec/unit/provider/mount_spec.rb +0 -0
  358. data/spec/unit/provider/naginator_spec.rb +0 -0
  359. data/spec/unit/provider/nameservice/directoryservice_spec.rb +0 -0
  360. data/spec/unit/provider/nameservice_spec.rb +0 -0
  361. data/spec/unit/provider/network_device_spec.rb +0 -0
  362. data/spec/unit/provider/package/aix_spec.rb +0 -0
  363. data/spec/unit/provider/package/appdmg_spec.rb +0 -0
  364. data/spec/unit/provider/package/apt_spec.rb +0 -0
  365. data/spec/unit/provider/package/aptitude_spec.rb +0 -0
  366. data/spec/unit/provider/package/aptrpm_spec.rb +0 -0
  367. data/spec/unit/provider/package/dpkg_spec.rb +0 -0
  368. data/spec/unit/provider/package/freebsd_spec.rb +0 -0
  369. data/spec/unit/provider/package/gem_spec.rb +0 -0
  370. data/spec/unit/provider/package/hpux_spec.rb +0 -0
  371. data/spec/unit/provider/package/macports_spec.rb +0 -0
  372. data/spec/unit/provider/package/nim_spec.rb +0 -0
  373. data/spec/unit/provider/package/openbsd_spec.rb +0 -0
  374. data/spec/unit/provider/package/opkg_spec.rb +0 -0
  375. data/spec/unit/provider/package/pacman_spec.rb +0 -0
  376. data/spec/unit/provider/package/pip3_spec.rb +0 -0
  377. data/spec/unit/provider/package/pip_spec.rb +0 -0
  378. data/spec/unit/provider/package/pkg_spec.rb +0 -0
  379. data/spec/unit/provider/package/pkgutil_spec.rb +0 -0
  380. data/spec/unit/provider/package/puppet_gem_spec.rb +0 -0
  381. data/spec/unit/provider/package/rpm_spec.rb +0 -0
  382. data/spec/unit/provider/package/sun_spec.rb +0 -0
  383. data/spec/unit/provider/package/windows/package_spec.rb +0 -0
  384. data/spec/unit/provider/package/windows_spec.rb +0 -0
  385. data/spec/unit/provider/package/yum_spec.rb +0 -0
  386. data/spec/unit/provider/package/zypper_spec.rb +0 -0
  387. data/spec/unit/provider/parsedfile_spec.rb +0 -0
  388. data/spec/unit/provider/selboolean_spec.rb +0 -0
  389. data/spec/unit/provider/selmodule_spec.rb +0 -0
  390. data/spec/unit/provider/service/base_spec.rb +0 -0
  391. data/spec/unit/provider/service/bsd_spec.rb +0 -0
  392. data/spec/unit/provider/service/daemontools_spec.rb +0 -0
  393. data/spec/unit/provider/service/debian_spec.rb +0 -0
  394. data/spec/unit/provider/service/freebsd_spec.rb +0 -0
  395. data/spec/unit/provider/service/gentoo_spec.rb +0 -0
  396. data/spec/unit/provider/service/init_spec.rb +0 -0
  397. data/spec/unit/provider/service/launchd_spec.rb +0 -0
  398. data/spec/unit/provider/service/openbsd_spec.rb +0 -0
  399. data/spec/unit/provider/service/openrc_spec.rb +0 -0
  400. data/spec/unit/provider/service/openwrt_spec.rb +0 -0
  401. data/spec/unit/provider/service/rcng_spec.rb +0 -0
  402. data/spec/unit/provider/service/redhat_spec.rb +0 -0
  403. data/spec/unit/provider/service/runit_spec.rb +0 -0
  404. data/spec/unit/provider/service/smf_spec.rb +0 -0
  405. data/spec/unit/provider/service/src_spec.rb +0 -0
  406. data/spec/unit/provider/service/systemd_spec.rb +0 -0
  407. data/spec/unit/provider/service/upstart_spec.rb +0 -0
  408. data/spec/unit/provider/service/windows_spec.rb +0 -0
  409. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +0 -0
  410. data/spec/unit/provider/sshkey/parsed_spec.rb +0 -0
  411. data/spec/unit/provider/user/directoryservice_spec.rb +0 -0
  412. data/spec/unit/provider/user/hpux_spec.rb +0 -0
  413. data/spec/unit/provider/user/ldap_spec.rb +0 -0
  414. data/spec/unit/provider/user/openbsd_spec.rb +0 -0
  415. data/spec/unit/provider/user/pw_spec.rb +0 -0
  416. data/spec/unit/provider/user/user_role_add_spec.rb +0 -0
  417. data/spec/unit/provider/user/useradd_spec.rb +0 -0
  418. data/spec/unit/provider/user/windows_adsi_spec.rb +0 -0
  419. data/spec/unit/provider/vlan/cisco_spec.rb +0 -0
  420. data/spec/unit/provider/zfs/zfs_spec.rb +0 -0
  421. data/spec/unit/provider/zone/solaris_spec.rb +0 -0
  422. data/spec/unit/provider/zpool/zpool_spec.rb +0 -0
  423. data/spec/unit/provider_spec.rb +0 -0
  424. data/spec/unit/puppet_spec.rb +0 -0
  425. data/spec/unit/relationship_spec.rb +0 -0
  426. data/spec/unit/reports/http_spec.rb +0 -0
  427. data/spec/unit/reports/store_spec.rb +0 -0
  428. data/spec/unit/reports_spec.rb +0 -0
  429. data/spec/unit/resource/catalog_spec.rb +0 -0
  430. data/spec/unit/resource/status_spec.rb +0 -0
  431. data/spec/unit/resource/type_collection_helper_spec.rb +0 -0
  432. data/spec/unit/resource/type_collection_spec.rb +0 -0
  433. data/spec/unit/resource/type_spec.rb +0 -0
  434. data/spec/unit/resource_spec.rb +0 -0
  435. data/spec/unit/settings/directory_setting_spec.rb +0 -0
  436. data/spec/unit/settings/duration_setting_spec.rb +0 -0
  437. data/spec/unit/settings/file_setting_spec.rb +0 -0
  438. data/spec/unit/settings/path_setting_spec.rb +0 -0
  439. data/spec/unit/settings/priority_setting_spec.rb +0 -0
  440. data/spec/unit/settings_spec.rb +1 -1
  441. data/spec/unit/ssl/base_spec.rb +0 -0
  442. data/spec/unit/ssl/certificate_authority/interface_spec.rb +0 -0
  443. data/spec/unit/ssl/certificate_authority_spec.rb +0 -0
  444. data/spec/unit/ssl/certificate_factory_spec.rb +0 -0
  445. data/spec/unit/ssl/certificate_request_spec.rb +0 -0
  446. data/spec/unit/ssl/certificate_revocation_list_spec.rb +0 -0
  447. data/spec/unit/ssl/certificate_spec.rb +0 -0
  448. data/spec/unit/ssl/configuration_spec.rb +0 -0
  449. data/spec/unit/ssl/host_spec.rb +0 -0
  450. data/spec/unit/ssl/inventory_spec.rb +0 -0
  451. data/spec/unit/ssl/key_spec.rb +0 -0
  452. data/spec/unit/status_spec.rb +0 -0
  453. data/spec/unit/transaction/event_manager_spec.rb +0 -0
  454. data/spec/unit/transaction/event_spec.rb +0 -0
  455. data/spec/unit/transaction/report_spec.rb +0 -0
  456. data/spec/unit/transaction/resource_harness_spec.rb +0 -0
  457. data/spec/unit/transaction_spec.rb +0 -0
  458. data/spec/unit/type/augeas_spec.rb +0 -0
  459. data/spec/unit/type/component_spec.rb +0 -0
  460. data/spec/unit/type/computer_spec.rb +0 -0
  461. data/spec/unit/type/cron_spec.rb +0 -0
  462. data/spec/unit/type/exec_spec.rb +0 -0
  463. data/spec/unit/type/file/checksum_spec.rb +0 -0
  464. data/spec/unit/type/file/checksum_value_spec.rb +0 -0
  465. data/spec/unit/type/file/content_spec.rb +0 -0
  466. data/spec/unit/type/file/ctime_spec.rb +0 -0
  467. data/spec/unit/type/file/ensure_spec.rb +0 -0
  468. data/spec/unit/type/file/group_spec.rb +0 -0
  469. data/spec/unit/type/file/mode_spec.rb +0 -0
  470. data/spec/unit/type/file/mtime_spec.rb +0 -0
  471. data/spec/unit/type/file/owner_spec.rb +0 -0
  472. data/spec/unit/type/file/selinux_spec.rb +0 -0
  473. data/spec/unit/type/file/source_spec.rb +0 -0
  474. data/spec/unit/type/file/type_spec.rb +0 -0
  475. data/spec/unit/type/file_spec.rb +0 -0
  476. data/spec/unit/type/filebucket_spec.rb +0 -0
  477. data/spec/unit/type/group_spec.rb +0 -0
  478. data/spec/unit/type/host_spec.rb +0 -0
  479. data/spec/unit/type/interface_spec.rb +0 -0
  480. data/spec/unit/type/k5login_spec.rb +0 -0
  481. data/spec/unit/type/macauthorization_spec.rb +0 -0
  482. data/spec/unit/type/mailalias_spec.rb +0 -0
  483. data/spec/unit/type/maillist_spec.rb +0 -0
  484. data/spec/unit/type/mcx_spec.rb +0 -0
  485. data/spec/unit/type/mount_spec.rb +0 -0
  486. data/spec/unit/type/nagios_spec.rb +0 -0
  487. data/spec/unit/type/noop_metaparam_spec.rb +0 -0
  488. data/spec/unit/type/package/package_settings_spec.rb +0 -0
  489. data/spec/unit/type/package_spec.rb +0 -0
  490. data/spec/unit/type/resources_spec.rb +0 -0
  491. data/spec/unit/type/schedule_spec.rb +0 -0
  492. data/spec/unit/type/selboolean_spec.rb +0 -0
  493. data/spec/unit/type/selmodule_spec.rb +0 -0
  494. data/spec/unit/type/service_spec.rb +0 -0
  495. data/spec/unit/type/ssh_authorized_key_spec.rb +0 -0
  496. data/spec/unit/type/sshkey_spec.rb +0 -0
  497. data/spec/unit/type/stage_spec.rb +0 -0
  498. data/spec/unit/type/tidy_spec.rb +0 -0
  499. data/spec/unit/type/user_spec.rb +0 -0
  500. data/spec/unit/type/vlan_spec.rb +0 -0
  501. data/spec/unit/type/whit_spec.rb +0 -0
  502. data/spec/unit/type/yumrepo_spec.rb +0 -0
  503. data/spec/unit/type/zfs_spec.rb +0 -0
  504. data/spec/unit/type/zone_spec.rb +0 -0
  505. data/spec/unit/type/zpool_spec.rb +0 -0
  506. data/spec/unit/type_spec.rb +0 -0
  507. data/spec/unit/util/autoload_spec.rb +0 -0
  508. data/spec/unit/util/backups_spec.rb +0 -0
  509. data/spec/unit/util/checksums_spec.rb +0 -0
  510. data/spec/unit/util/colors_spec.rb +0 -0
  511. data/spec/unit/util/command_line_spec.rb +0 -0
  512. data/spec/unit/util/constant_inflector_spec.rb +0 -0
  513. data/spec/unit/util/diff_spec.rb +0 -0
  514. data/spec/unit/util/errors_spec.rb +0 -0
  515. data/spec/unit/util/execution_spec.rb +0 -0
  516. data/spec/unit/util/execution_stub_spec.rb +0 -0
  517. data/spec/unit/util/feature_spec.rb +0 -0
  518. data/spec/unit/util/filetype_spec.rb +0 -0
  519. data/spec/unit/util/ldap/connection_spec.rb +0 -0
  520. data/spec/unit/util/ldap/generator_spec.rb +0 -0
  521. data/spec/unit/util/ldap/manager_spec.rb +0 -0
  522. data/spec/unit/util/log/destinations_spec.rb +0 -0
  523. data/spec/unit/util/log_spec.rb +0 -0
  524. data/spec/unit/util/logging_spec.rb +0 -0
  525. data/spec/unit/util/metric_spec.rb +0 -0
  526. data/spec/unit/util/monkey_patches_spec.rb +19 -3
  527. data/spec/unit/util/nagios_maker_spec.rb +0 -0
  528. data/spec/unit/util/network_device/cisco/device_spec.rb +0 -0
  529. data/spec/unit/util/network_device/cisco/facts_spec.rb +0 -0
  530. data/spec/unit/util/network_device/cisco/interface_spec.rb +0 -0
  531. data/spec/unit/util/network_device/config_spec.rb +0 -0
  532. data/spec/unit/util/network_device/ipcalc_spec.rb +0 -0
  533. data/spec/unit/util/network_device/transport/base_spec.rb +0 -0
  534. data/spec/unit/util/network_device/transport/ssh_spec.rb +0 -0
  535. data/spec/unit/util/network_device/transport/telnet_spec.rb +0 -0
  536. data/spec/unit/util/package_spec.rb +0 -0
  537. data/spec/unit/util/posix_spec.rb +0 -0
  538. data/spec/unit/util/rdoc_spec.rb +0 -0
  539. data/spec/unit/util/resource_template_spec.rb +0 -0
  540. data/spec/unit/util/retry_action_spec.rb +0 -0
  541. data/spec/unit/util/run_mode_spec.rb +0 -0
  542. data/spec/unit/util/selinux_spec.rb +0 -0
  543. data/spec/unit/util/storage_spec.rb +0 -0
  544. data/spec/unit/util/suidmanager_spec.rb +0 -0
  545. data/spec/unit/util/symbolic_file_mode_spec.rb +0 -0
  546. data/spec/unit/util/tagging_spec.rb +0 -0
  547. data/spec/unit/util/user_attr_spec.rb +0 -0
  548. data/spec/unit/util/warnings_spec.rb +0 -0
  549. data/spec/unit/util/windows/adsi_spec.rb +0 -0
  550. data/spec/unit/util/windows/file_spec.rb +34 -0
  551. data/spec/unit/util/windows/root_certs_spec.rb +0 -0
  552. data/spec/unit/util/windows/sid_spec.rb +0 -0
  553. data/spec/unit/util_spec.rb +0 -0
  554. data/spec/watchr.rb +0 -0
  555. metadata +3372 -3358
  556. checksums.yaml +0 -7
@@ -54,6 +54,16 @@ class RecursionGuard
54
54
  @state
55
55
  end
56
56
 
57
+ # @return the number of objects added to the `this` map
58
+ def this_count
59
+ this_map.size
60
+ end
61
+
62
+ # @return the number of objects added to the `that` map
63
+ def that_count
64
+ that_map.size
65
+ end
66
+
57
67
  private
58
68
 
59
69
  def map_put(map, o)
@@ -30,7 +30,7 @@ module TypeAsserter
30
30
  # @api public
31
31
  def self.assert_instance_of(subject, expected_type, value, nil_ok = false, &block)
32
32
  unless value.nil? && nil_ok
33
- report_type_mismatch(subject, expected_type, TypeCalculator.singleton.infer_set(value).generalize, &block) unless expected_type.instance?(value)
33
+ report_type_mismatch(subject, expected_type, TypeCalculator.singleton.infer_set(value), &block) unless expected_type.instance?(value)
34
34
  end
35
35
  value
36
36
  end
@@ -39,7 +39,7 @@ module TypeAsserter
39
39
  subject = yield(subject) if block_given?
40
40
  subject = subject[0] % subject[1..-1] if subject.is_a?(Array)
41
41
  raise TypeAssertionError.new(
42
- TypeMismatchDescriber.singleton.describe_mismatch("#{subject} has wrong type,", expected_type, actual_type), expected_type, actual_type)
42
+ TypeMismatchDescriber.singleton.describe_mismatch("#{subject} had wrong type,", expected_type, actual_type), expected_type, actual_type)
43
43
  end
44
44
  private_class_method :report_type_mismatch
45
45
  end
@@ -697,7 +697,7 @@ class TypeCalculator
697
697
  if o.empty?
698
698
  PHashType::EMPTY
699
699
  elsif o.keys.all? {|k| PStringType::NON_EMPTY.instance?(k) }
700
- PStructType.new(o.each_pair.map { |k,v| PStructElement.new(PStringType.new(nil, [k]), infer_set(v)) })
700
+ PStructType.new(o.each_pair.map { |k,v| PStructElement.new(PStringType.new(size_as_type(k), [k]), infer_set(v)) })
701
701
  else
702
702
  ktype = PVariantType.new(o.keys.map {|k| infer_set(k) })
703
703
  etype = PVariantType.new(o.values.map {|e| infer_set(e) })
@@ -206,14 +206,26 @@ class TypeFormatter
206
206
  append_array('Runtime', [string(t.runtime), string(t.runtime_type_name)])
207
207
  end
208
208
 
209
+ def is_empty_range?(from, to)
210
+ from == 0 && to == 0
211
+ end
212
+
209
213
  # @api private
210
214
  def string_PArrayType(t)
211
- append_array('Array', t == PArrayType::DATA ? EMPTY_ARRAY : [string(t.element_type)] + range_array_part(t.size_type))
215
+ if t.has_empty_range?
216
+ append_array('Array', ['0', '0'])
217
+ else
218
+ append_array('Array', t == PArrayType::DATA ? EMPTY_ARRAY : [string(t.element_type)] + range_array_part(t.size_type))
219
+ end
212
220
  end
213
221
 
214
222
  # @api private
215
223
  def string_PHashType(t)
216
- append_array('Hash', t == PHashType::DATA ? EMPTY_ARRAY : [string(t.key_type), string(t.element_type)] + range_array_part(t.size_type))
224
+ if t.has_empty_range?
225
+ append_array('Hash', ['0', '0'])
226
+ else
227
+ append_array('Hash', t == PHashType::DATA ? EMPTY_ARRAY : [string(t.key_type), string(t.element_type)] + range_array_part(t.size_type))
228
+ end
217
229
  end
218
230
 
219
231
  # @api private
@@ -28,13 +28,13 @@ module Types
28
28
 
29
29
  class MemberPathElement < TypePathElement
30
30
  def to_s
31
- "struct member #{key}"
31
+ "struct member '#{key}'"
32
32
  end
33
33
  end
34
34
 
35
35
  class MemberKeyPathElement < TypePathElement
36
36
  def to_s
37
- "struct member key #{key}"
37
+ "struct member key '#{key}'"
38
38
  end
39
39
  end
40
40
 
@@ -301,6 +301,22 @@ module Types
301
301
 
302
302
  private
303
303
 
304
+ # Answers the question if `e` is a specialized type of `a`
305
+ # @param e [PAnyType] the expected type
306
+ # @param a [PAnyType] the actual type
307
+ # @return [Boolean] `true` when the _e_ is a specialization of _a_
308
+ #
309
+ def specialization(e, a)
310
+ case e
311
+ when PStructType
312
+ a.is_a?(PHashType)
313
+ when PTupleType
314
+ a.is_a?(PArrayType)
315
+ else
316
+ false
317
+ end
318
+ end
319
+
304
320
  # Decides whether or not the report must be fully detailed, or if generalization can be permitted
305
321
  # in the mismatch report. All comparisons are made using resolved aliases rather than the alias
306
322
  # itself.
@@ -313,7 +329,7 @@ module Types
313
329
  if e.is_a?(Array)
314
330
  e.any? { |t| always_fully_detailed?(t, a) }
315
331
  else
316
- e.class == a.class || e.is_a?(PTypeAliasType) || a.is_a?(PTypeAliasType)
332
+ e.class == a.class || e.is_a?(PTypeAliasType) || a.is_a?(PTypeAliasType) || specialization(e, a)
317
333
  end
318
334
  end
319
335
 
@@ -713,15 +729,11 @@ module Types
713
729
  h2.each_key { |key| descriptions << ExtraneousKey.new(path, key) }
714
730
  elsif actual.is_a?(PHashType)
715
731
  actual_size = actual.size_type || PCollectionType::DEFAULT_SIZE
716
- expected_size = PIntegerType.new(elements.count { |e| !e.type.assignable?(PUndefType::DEFAULT) }, elements.size)
732
+ expected_size = PIntegerType.new(elements.count { |e| !e.key_type.assignable?(PUndefType::DEFAULT) }, elements.size)
717
733
  if expected_size.assignable?(actual_size)
718
- if actual_size.to == 0 || PStringType::NON_EMPTY.assignable?(actual.key_type)
719
- descriptions.concat(describe(e.type, actual.element_type, path + [MemberPathElement.new(e.key)]))
720
- else
721
- descriptions << TypeMismatch(path, @non_empty_string_, actual.key_type)
722
- end
734
+ descriptions << TypeMismatch.new(path, expected, actual)
723
735
  else
724
- descriptions << SizeMismatch(path, expected_size, actual_size)
736
+ descriptions << SizeMismatch.new(path, expected_size, actual_size)
725
737
  end
726
738
  else
727
739
  descriptions << TypeMismatch.new(path, expected, actual)
@@ -64,7 +64,7 @@ class PAnyType < TypedModelObject
64
64
  # @api public
65
65
  def assignable?(o, guard = nil)
66
66
  case o
67
- when Class
67
+ when Class
68
68
  # Safe to call _assignable directly since a Class never is a Unit or Variant
69
69
  _assignable?(TypeCalculator.singleton.type(o), guard)
70
70
  when PUnitType
@@ -177,11 +177,22 @@ class PAnyType < TypedModelObject
177
177
  end
178
178
 
179
179
  # Returns true if the given argument _o_ is an instance of this type
180
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
180
181
  # @return [Boolean]
181
- def instance?(o)
182
+ # @api public
183
+ def instance?(o, guard = nil)
182
184
  true
183
185
  end
184
186
 
187
+ # An object is considered to really be an instance of a type when something other than a
188
+ # TypeAlias or a Variant responds true to a call to {#instance?}.
189
+ #
190
+ # @return [Integer] -1 = is not instance, 0 = recursion detected, 1 = is instance
191
+ # @api private
192
+ def really_instance?(o, guard = nil)
193
+ instance?(o, guard) ? 1 : -1
194
+ end
195
+
185
196
  def eql?(o)
186
197
  self.class == o.class
187
198
  end
@@ -238,7 +249,7 @@ class PAnyType < TypedModelObject
238
249
  #
239
250
  # @api private
240
251
  #
241
- def tuple_entry_at(tuple_t, from, to, index)
252
+ def tuple_entry_at(tuple_t, to, index)
242
253
  regular = (tuple_t.types.size - 1)
243
254
  if index < regular
244
255
  tuple_t.types[index]
@@ -336,11 +347,11 @@ end
336
347
  # @api public
337
348
  #
338
349
  class PType < PTypeWithContainedType
339
- def instance?(o)
350
+ def instance?(o, guard = nil)
340
351
  if o.is_a?(PAnyType)
341
- type.nil? || type.assignable?(o)
352
+ type.nil? || type.assignable?(o, guard)
342
353
  else
343
- assignable?(TypeCalculator.infer(o))
354
+ assignable?(TypeCalculator.infer(o), guard)
344
355
  end
345
356
  end
346
357
 
@@ -398,8 +409,8 @@ class PNotUndefType < PTypeWithContainedType
398
409
  super(type.class == PAnyType ? nil : type)
399
410
  end
400
411
 
401
- def instance?(o)
402
- !(o.nil? || o == :undef) && (@type.nil? || @type.instance?(o))
412
+ def instance?(o, guard = nil)
413
+ !(o.nil? || o == :undef) && (@type.nil? || @type.instance?(o, guard))
403
414
  end
404
415
 
405
416
  def normalize(guard = nil)
@@ -409,7 +420,7 @@ class PNotUndefType < PTypeWithContainedType
409
420
  else
410
421
  if n.type.is_a?(POptionalType)
411
422
  # No point in having an optional in a NotUndef
412
- PNotUndef.new(n.type.type).normalize
423
+ PNotUndefType.new(n.type.type).normalize
413
424
  elsif !n.type.assignable?(PUndefType::DEFAULT)
414
425
  # THe type is NotUndef anyway, so it can be stripped of
415
426
  n.type
@@ -432,7 +443,7 @@ end
432
443
  # @api public
433
444
  #
434
445
  class PUndefType < PAnyType
435
- def instance?(o)
446
+ def instance?(o, guard = nil)
436
447
  o.nil? || o == :undef
437
448
  end
438
449
 
@@ -455,7 +466,7 @@ end
455
466
  # @api private
456
467
  #
457
468
  class PUnitType < PAnyType
458
- def instance?(o)
469
+ def instance?(o, guard = nil)
459
470
  true
460
471
  end
461
472
 
@@ -471,7 +482,7 @@ end
471
482
  # @api public
472
483
  #
473
484
  class PDefaultType < PAnyType
474
- def instance?(o)
485
+ def instance?(o, guard = nil)
475
486
  o == :default
476
487
  end
477
488
 
@@ -493,8 +504,8 @@ class PDataType < PAnyType
493
504
  self.class == o.class || o == PVariantType::DATA
494
505
  end
495
506
 
496
- def instance?(o)
497
- PVariantType::DATA.instance?(o)
507
+ def instance?(o, guard = nil)
508
+ PVariantType::DATA.instance?(o, guard)
498
509
  end
499
510
 
500
511
  DEFAULT = PDataType.new
@@ -521,8 +532,8 @@ end
521
532
  #
522
533
  class PScalarType < PAnyType
523
534
 
524
- def instance?(o)
525
- assignable?(TypeCalculator.infer(o))
535
+ def instance?(o, guard = nil)
536
+ assignable?(TypeCalculator.infer(o), guard)
526
537
  end
527
538
 
528
539
  DEFAULT = PScalarType.new
@@ -609,7 +620,7 @@ class PNumericType < PScalarType
609
620
  # @return [Boolean] `true` if this range intersects with the other range
610
621
  # @api public
611
622
  def intersect?(o)
612
- self.class == o.class && !(@to < o.from || o.to < @from)
623
+ self.class == o.class && !(@to < o.numeric_from || o.numeric_to < @from)
613
624
  end
614
625
 
615
626
  # Returns the lower bound of the numeric range or `nil` if no lower bound is set.
@@ -644,7 +655,7 @@ class PNumericType < PScalarType
644
655
  self.class == o.class && @from == o.numeric_from && @to == o.numeric_to
645
656
  end
646
657
 
647
- def instance?(o)
658
+ def instance?(o, guard = nil)
648
659
  o.is_a?(Numeric) && o >= @from && o <= @to
649
660
  end
650
661
 
@@ -678,7 +689,7 @@ class PIntegerType < PNumericType
678
689
  DEFAULT
679
690
  end
680
691
 
681
- def instance?(o)
692
+ def instance?(o, guard = nil)
682
693
  o.is_a?(Integer) && o >= numeric_from && o <= numeric_to
683
694
  end
684
695
 
@@ -699,8 +710,8 @@ class PIntegerType < PNumericType
699
710
  # @api public
700
711
  def merge(o)
701
712
  if intersect?(o) || adjacent?(o)
702
- min = @from <= o.from ? @from : o.from
703
- max = @to >= o.to ? @to : o.to
713
+ min = @from <= o.numeric_from ? @from : o.numeric_from
714
+ max = @to >= o.numeric_to ? @to : o.numeric_to
704
715
  PIntegerType.new(min, max)
705
716
  else
706
717
  nil
@@ -752,7 +763,7 @@ class PFloatType < PNumericType
752
763
  DEFAULT
753
764
  end
754
765
 
755
- def instance?(o)
766
+ def instance?(o, guard = nil)
756
767
  o.is_a?(Float) && o >= numeric_from && o <= numeric_to
757
768
  end
758
769
 
@@ -783,6 +794,9 @@ class PCollectionType < PAnyType
783
794
  def initialize(element_type, size_type = nil)
784
795
  @element_type = element_type
785
796
  @size_type = size_type
797
+ if has_empty_range? && !@element_type.is_a?(PUnitType)
798
+ raise ArgumentError, 'An empty collection may not specify an element type'
799
+ end
786
800
  end
787
801
 
788
802
  def accept(visitor, guard)
@@ -809,8 +823,8 @@ class PCollectionType < PAnyType
809
823
  end
810
824
  end
811
825
 
812
- def instance?(o)
813
- assignable?(TypeCalculator.infer(o))
826
+ def instance?(o, guard = nil)
827
+ assignable?(TypeCalculator.infer(o), guard)
814
828
  end
815
829
 
816
830
  # Returns an array with from (min) size to (max) size
@@ -818,6 +832,11 @@ class PCollectionType < PAnyType
818
832
  (@size_type || DEFAULT_SIZE).range
819
833
  end
820
834
 
835
+ def has_empty_range?
836
+ from, to = size_range
837
+ from == 0 && to == 0
838
+ end
839
+
821
840
  def hash
822
841
  @element_type.hash ^ @size_type.hash
823
842
  end
@@ -867,8 +886,8 @@ class PIterableType < PTypeWithContainedType
867
886
  @type
868
887
  end
869
888
 
870
- def instance?(o)
871
- if @type.nil? || @type.assignable?(PAnyType::DEFAULT)
889
+ def instance?(o, guard = nil)
890
+ if @type.nil? || @type.assignable?(PAnyType::DEFAULT, guard)
872
891
  # Any element_type will do
873
892
  case o
874
893
  when Iterable, String, Hash, Array, Range, PEnumType
@@ -881,7 +900,7 @@ class PIterableType < PTypeWithContainedType
881
900
  false
882
901
  end
883
902
  else
884
- assignable?(TypeCalculator.infer(o))
903
+ assignable?(TypeCalculator.infer(o), guard)
885
904
  end
886
905
  end
887
906
 
@@ -916,8 +935,8 @@ class PIteratorType < PTypeWithContainedType
916
935
  @type
917
936
  end
918
937
 
919
- def instance?(o)
920
- o.is_a?(Iterable) && (@element_type.nil? || @element_type.assignable?(o.element_type))
938
+ def instance?(o, guard = nil)
939
+ o.is_a?(Iterable) && (@type.nil? || @type.assignable?(o.element_type, guard))
921
940
  end
922
941
 
923
942
  def iterable?(guard = nil)
@@ -925,7 +944,7 @@ class PIteratorType < PTypeWithContainedType
925
944
  end
926
945
 
927
946
  def iterable_type(guard = nil)
928
- @type.nil? ? PIteratbleType::DEFAULT : PIterableType.new(@element_type)
947
+ @type.nil? ? PIterableType::DEFAULT : PIterableType.new(@type)
929
948
  end
930
949
 
931
950
  DEFAULT = PIteratorType.new(nil)
@@ -934,7 +953,7 @@ class PIteratorType < PTypeWithContainedType
934
953
 
935
954
  # @api private
936
955
  def _assignable?(o, guard)
937
- o.is_a?(PIteratorType) && (@element_type.nil? || @element_type.assignable?(o.element_type, guard))
956
+ o.is_a?(PIteratorType) && (@type.nil? || @type.assignable?(o.element_type, guard))
938
957
  end
939
958
  end
940
959
 
@@ -973,9 +992,9 @@ class PStringType < PScalarType
973
992
  self.class == o.class && @size_type == o.size_type && @values == o.values
974
993
  end
975
994
 
976
- def instance?(o)
995
+ def instance?(o, guard = nil)
977
996
  # true if size compliant
978
- if o.is_a?(String) && (@size_type.nil? || @size_type.instance?(o.size))
997
+ if o.is_a?(String) && (@size_type.nil? || @size_type.instance?(o.size, guard))
979
998
  @values.empty? || @values.include?(o)
980
999
  else
981
1000
  false
@@ -1123,7 +1142,7 @@ end
1123
1142
  #
1124
1143
  class PBooleanType < PScalarType
1125
1144
 
1126
- def instance?(o)
1145
+ def instance?(o, guard = nil)
1127
1146
  o == true || o == false
1128
1147
  end
1129
1148
 
@@ -1180,7 +1199,11 @@ class PStructElement < TypedModelObject
1180
1199
  end
1181
1200
 
1182
1201
  def eql?(o)
1183
- self.class == o.class && value_type == o.value_type && key_type == o.key_type
1202
+ self == o
1203
+ end
1204
+
1205
+ def ==(o)
1206
+ self.class == o.class && value_type == o.value_type && key_type == o.key_type
1184
1207
  end
1185
1208
  end
1186
1209
 
@@ -1255,7 +1278,7 @@ class PStructType < PAnyType
1255
1278
  @elements
1256
1279
  end
1257
1280
 
1258
- def instance?(o)
1281
+ def instance?(o, guard = nil)
1259
1282
  return false unless o.is_a?(Hash)
1260
1283
  matched = 0
1261
1284
  @elements.all? do |e|
@@ -1263,10 +1286,10 @@ class PStructType < PAnyType
1263
1286
  v = o[key]
1264
1287
  if v.nil? && !o.include?(key)
1265
1288
  # Entry is missing. Only OK when key is optional
1266
- e.key_type.assignable?(PUndefType::DEFAULT)
1289
+ e.key_type.assignable?(PUndefType::DEFAULT, guard)
1267
1290
  else
1268
1291
  matched += 1
1269
- e.value_type.instance?(v)
1292
+ e.value_type.instance?(v, guard)
1270
1293
  end
1271
1294
  end && matched == o.size
1272
1295
  end
@@ -1292,16 +1315,26 @@ class PStructType < PAnyType
1292
1315
  elsif o.is_a?(Types::PHashType)
1293
1316
  required = 0
1294
1317
  required_elements_assignable = elements.all? do |e|
1295
- if e.key_type.assignable?(PUndefType::DEFAULT)
1318
+ key_type = e.key_type
1319
+ if key_type.assignable?(PUndefType::DEFAULT)
1320
+ # Element is optional so Hash does not need to provide it
1296
1321
  true
1297
1322
  else
1298
1323
  required += 1
1299
- e.value_type.assignable?(o.element_type, guard)
1324
+ if e.value_type.assignable?(o.element_type, guard)
1325
+ # Hash must have something that is assignable. We don't care about the name or size of the key though
1326
+ # because we have no instance of a hash to compare against.
1327
+ key_type.generalize.assignable?(o.key_type)
1328
+ else
1329
+ false
1330
+ end
1300
1331
  end
1301
1332
  end
1302
1333
  if required_elements_assignable
1303
- size_o = o.size_type || collection_default_size_t
1334
+ size_o = o.size_type || PCollectionType::DEFAULT_SIZE
1304
1335
  PIntegerType.new(required, elements.size).assignable?(size_o, guard)
1336
+ else
1337
+ false
1305
1338
  end
1306
1339
  else
1307
1340
  false
@@ -1391,14 +1424,14 @@ class PTupleType < PAnyType
1391
1424
  end
1392
1425
  end
1393
1426
 
1394
- def instance?(o)
1427
+ def instance?(o, guard = nil)
1395
1428
  return false unless o.is_a?(Array)
1396
1429
  # compute the tuple's min/max size, and check if that size matches
1397
1430
  size_t = size_type || PIntegerType.new(*size_range)
1398
1431
 
1399
- return false unless size_t.instance?(o.size)
1432
+ return false unless size_t.instance?(o.size, guard)
1400
1433
  o.each_with_index do |element, index|
1401
- return false unless (types[index] || types[-1]).instance?(element)
1434
+ return false unless (types[index] || types[-1]).instance?(element, guard)
1402
1435
  end
1403
1436
  true
1404
1437
  end
@@ -1415,7 +1448,7 @@ class PTupleType < PAnyType
1415
1448
  def size_range
1416
1449
  if @size_type.nil?
1417
1450
  types_size = @types.size
1418
- [types_size, types_size]
1451
+ types_size == 0 ? [0, Float::INFINITY] : [types_size, types_size]
1419
1452
  else
1420
1453
  @size_type.range
1421
1454
  end
@@ -1452,36 +1485,33 @@ class PTupleType < PAnyType
1452
1485
  # @api private
1453
1486
  def _assignable?(o, guard)
1454
1487
  return true if self == o
1488
+ return false unless o.is_a?(PTupleType) || o.is_a?(PArrayType)
1455
1489
  s_types = types
1456
- return true if s_types.empty? && (o.is_a?(PArrayType))
1457
1490
  size_s = size_type || PIntegerType.new(*size_range)
1458
1491
 
1459
1492
  if o.is_a?(PTupleType)
1460
1493
  size_o = o.size_type || PIntegerType.new(*o.size_range)
1461
-
1462
- # not assignable if the number of types in o is outside number of types in t1
1463
- if size_s.assignable?(size_o, guard)
1494
+ return false unless size_s.assignable?(size_o, guard)
1495
+ unless s_types.empty?
1464
1496
  o_types = o.types
1497
+ return false if o_types.empty?
1465
1498
  o_types.size.times do |index|
1466
1499
  return false unless (s_types[index] || s_types[-1]).assignable?(o_types[index], guard)
1467
1500
  end
1468
- return true
1469
- else
1470
- return false
1471
1501
  end
1472
- elsif o.is_a?(PArrayType)
1473
- o_entry = o.element_type
1474
- # Array of anything can not be assigned (unless tuple is tuple of anything) - this case
1475
- # was handled at the top of this method.
1476
- #
1477
- return false if o_entry.nil?
1502
+ else
1478
1503
  size_o = o.size_type || PCollectionType::DEFAULT_SIZE
1479
1504
  return false unless size_s.assignable?(size_o, guard)
1480
- [s_types.size, size_o.range[1]].min.times { |index| return false unless (s_types[index] || s_types[-1]).assignable?(o_entry, guard) }
1481
- true
1482
- else
1483
- false
1505
+ unless s_types.empty?
1506
+ o_entry = o.element_type
1507
+ # Array of anything can not be assigned (unless tuple is tuple of anything) - this case
1508
+ # was handled at the top of this method.
1509
+ #
1510
+ return false if o_entry.nil?
1511
+ [s_types.size, size_o.range[1]].min.times { |index| return false unless (s_types[index] || s_types[-1]).assignable?(o_entry, guard) }
1512
+ end
1484
1513
  end
1514
+ true
1485
1515
  end
1486
1516
  end
1487
1517
 
@@ -1531,8 +1561,8 @@ class PCallableType < PAnyType
1531
1561
  end
1532
1562
  end
1533
1563
 
1534
- def instance?(o)
1535
- assignable?(TypeCalculator.infer(o))
1564
+ def instance?(o, guard = nil)
1565
+ assignable?(TypeCalculator.infer(o), guard)
1536
1566
  end
1537
1567
 
1538
1568
  # @api private
@@ -1589,7 +1619,9 @@ class PCallableType < PAnyType
1589
1619
 
1590
1620
  # NOTE: these tests are made in reverse as it is calling the callable that is constrained
1591
1621
  # (it's lower bound), not its upper bound
1592
- return false unless o.param_types.assignable?(@param_types, guard)
1622
+ other_param_types = o.param_types
1623
+
1624
+ return false if other_param_types.nil? || !other_param_types.assignable?(@param_types, guard)
1593
1625
  # names are ignored, they are just information
1594
1626
  # Blocks must be compatible
1595
1627
  this_block_t = @block_type || PUndefType::DEFAULT
@@ -1626,12 +1658,12 @@ class PArrayType < PCollectionType
1626
1658
  end
1627
1659
  end
1628
1660
 
1629
- def instance?(o)
1661
+ def instance?(o, guard = nil)
1630
1662
  return false unless o.is_a?(Array)
1631
1663
  element_t = element_type
1632
- return false unless element_t.nil? || o.all? {|element| element_t.instance?(element) }
1664
+ return false unless element_t.nil? || o.all? {|element| element_t.instance?(element, guard) }
1633
1665
  size_t = size_type
1634
- size_t.nil? || size_t.instance?(o.size)
1666
+ size_t.nil? || size_t.instance?(o.size, guard)
1635
1667
  end
1636
1668
 
1637
1669
  DATA = PArrayType.new(PDataType::DEFAULT, DEFAULT_SIZE)
@@ -1664,7 +1696,7 @@ class PArrayType < PCollectionType
1664
1696
  return false if o_regular.size + o_to > max
1665
1697
  # each tuple type must be assignable to the element type
1666
1698
  o_required.times do |index|
1667
- o_entry = tuple_entry_at(o, o_from, o_to, index)
1699
+ o_entry = tuple_entry_at(o, o_to, index)
1668
1700
  return false unless s_entry.assignable?(o_entry, guard)
1669
1701
  end
1670
1702
  # ... and so must the last, possibly optional (ranged) type
@@ -1685,6 +1717,9 @@ class PHashType < PCollectionType
1685
1717
  def initialize(key_type, value_type, size_type = nil)
1686
1718
  super(value_type, size_type)
1687
1719
  @key_type = key_type
1720
+ if has_empty_range? && !@key_type.is_a?(PUnitType)
1721
+ raise ArgumentError, 'An empty hash may not specify a key type'
1722
+ end
1688
1723
  end
1689
1724
 
1690
1725
  def accept(visitor, guard)
@@ -1720,14 +1755,14 @@ class PHashType < PCollectionType
1720
1755
  super ^ @key_type.hash
1721
1756
  end
1722
1757
 
1723
- def instance?(o)
1758
+ def instance?(o, guard = nil)
1724
1759
  return false unless o.is_a?(Hash)
1725
1760
  key_t = key_type
1726
1761
  element_t = element_type
1727
- if (key_t.nil? || o.keys.all? {|key| key_t.instance?(key) }) &&
1728
- (element_t.nil? || o.values.all? {|value| element_t.instance?(value) })
1762
+ if (key_t.nil? || o.keys.all? {|key| key_t.instance?(key, guard) }) &&
1763
+ (element_t.nil? || o.values.all? {|value| element_t.instance?(value, guard) })
1729
1764
  size_t = size_type
1730
- size_t.nil? || size_t.instance?(o.size)
1765
+ size_t.nil? || size_t.instance?(o.size, guard)
1731
1766
  else
1732
1767
  false
1733
1768
  end
@@ -1775,8 +1810,8 @@ class PHashType < PCollectionType
1775
1810
  # hash must accept all value types
1776
1811
  # hash must accept the size of the struct
1777
1812
  o_elements = o.elements
1778
- (size_type || DEFAULT_SIZE).instance?(o_elements.size) &&
1779
- o_elements.all? {|e| (key_type.nil? || key_type.instance?(e.name)) && (element_type.nil? || element_type.assignable?(e.value_type, guard)) }
1813
+ (size_type || DEFAULT_SIZE).instance?(o_elements.size, guard) &&
1814
+ o_elements.all? {|e| (key_type.nil? || key_type.instance?(e.name, guard)) && (element_type.nil? || element_type.assignable?(e.value_type, guard)) }
1780
1815
  else
1781
1816
  false
1782
1817
  end
@@ -1813,7 +1848,7 @@ class PVariantType < PAnyType
1813
1848
  if self == DEFAULT || self == DATA
1814
1849
  self
1815
1850
  else
1816
- alter_type_array(@types, :generalize) { |altered| PVariantType.new(mod_types) }
1851
+ alter_type_array(@types, :generalize) { |altered| PVariantType.new(altered) }
1817
1852
  end
1818
1853
  end
1819
1854
 
@@ -1868,9 +1903,17 @@ class PVariantType < PAnyType
1868
1903
  @types.hash
1869
1904
  end
1870
1905
 
1871
- def instance?(o)
1906
+ def instance?(o, guard = nil)
1872
1907
  # instance of variant if o is instance? of any of variant's types
1873
- @types.any? { |type| type.instance?(o) }
1908
+ @types.any? { |type| type.instance?(o, guard) }
1909
+ end
1910
+
1911
+ def really_instance?(o, guard = nil)
1912
+ @types.inject(-1) do |memo, type|
1913
+ ri = type.really_instance?(o, guard)
1914
+ memo = ri if ri > memo
1915
+ memo
1916
+ end
1874
1917
  end
1875
1918
 
1876
1919
  def kind_of_callable?(optional = true, guard = nil)
@@ -1993,7 +2036,7 @@ class PVariantType < PAnyType
1993
2036
  # @api private
1994
2037
  def merge_ranges(ranges)
1995
2038
  result = []
1996
- while !ranges.empty?
2039
+ until ranges.empty?
1997
2040
  unmerged = []
1998
2041
  x = ranges.pop
1999
2042
  result << ranges.inject(x) do |memo, y|
@@ -2029,8 +2072,8 @@ class PRuntimeType < PAnyType
2029
2072
  self.class == o.class && @runtime == o.runtime && @runtime_type_name == o.runtime_type_name
2030
2073
  end
2031
2074
 
2032
- def instance?(o)
2033
- assignable?(TypeCalculator.infer(o))
2075
+ def instance?(o, guard = nil)
2076
+ assignable?(TypeCalculator.infer(o), guard)
2034
2077
  end
2035
2078
 
2036
2079
  def iterable?(guard = nil)
@@ -2070,8 +2113,8 @@ class PCatalogEntryType < PAnyType
2070
2113
 
2071
2114
  DEFAULT = PCatalogEntryType.new
2072
2115
 
2073
- def instance?(o)
2074
- assignable?(TypeCalculator.infer(o))
2116
+ def instance?(o, guard = nil)
2117
+ assignable?(TypeCalculator.infer(o), guard)
2075
2118
  end
2076
2119
 
2077
2120
  protected
@@ -2158,8 +2201,8 @@ class POptionalType < PTypeWithContainedType
2158
2201
  optional && !@type.nil? && @type.kind_of_callable?(optional, guard)
2159
2202
  end
2160
2203
 
2161
- def instance?(o)
2162
- PUndefType::DEFAULT.instance?(o) || (!@type.nil? && @type.instance?(o))
2204
+ def instance?(o, guard = nil)
2205
+ PUndefType::DEFAULT.instance?(o, guard) || (!@type.nil? && @type.instance?(o, guard))
2163
2206
  end
2164
2207
 
2165
2208
  def normalize(guard = nil)
@@ -2207,7 +2250,7 @@ class PTypeReferenceType < PAnyType
2207
2250
  false
2208
2251
  end
2209
2252
 
2210
- def instance?(o)
2253
+ def instance?(o, guard = nil)
2211
2254
  false
2212
2255
  end
2213
2256
 
@@ -2248,6 +2291,14 @@ class PTypeAliasType < PAnyType
2248
2291
  @self_recursion = false
2249
2292
  end
2250
2293
 
2294
+ def assignable?(o, guard = nil)
2295
+ if @self_recursion
2296
+ guard ||= RecursionGuard.new
2297
+ return true if guard.add_this(self) == RecursionGuard::SELF_RECURSION_IN_BOTH
2298
+ end
2299
+ super(o, guard)
2300
+ end
2301
+
2251
2302
  # Returns the resolved type. The type must have been resolved by a call prior to calls to this
2252
2303
  # method or an error will be raised.
2253
2304
  #
@@ -2266,9 +2317,8 @@ class PTypeAliasType < PAnyType
2266
2317
  guarded_recursion(guard, false) { |g| resolved_type.kind_of_callable?(optional, g) }
2267
2318
  end
2268
2319
 
2269
- def instance?(o)
2270
- # No value can ever be recursive so no guard is needed here
2271
- resolved_type.instance?(o)
2320
+ def instance?(o, guard = nil)
2321
+ really_instance?(o, guard) == 1
2272
2322
  end
2273
2323
 
2274
2324
  def iterable?(guard = nil)
@@ -2283,6 +2333,44 @@ class PTypeAliasType < PAnyType
2283
2333
  @name.hash
2284
2334
  end
2285
2335
 
2336
+ # Acceptor used when checking for self recursion and that a type contains
2337
+ # something other than aliases or type references
2338
+ #
2339
+ # @api private
2340
+ class AssertOtherTypeAcceptor
2341
+ def initialize
2342
+ @other_type_detected = false
2343
+ end
2344
+
2345
+ def visit(type, _)
2346
+ unless type.is_a?(PTypeAliasType) || type.is_a?(PVariantType) || type.is_a?(PTypeReferenceType)
2347
+ @other_type_detected = true
2348
+ end
2349
+ end
2350
+
2351
+ def other_type_detected?
2352
+ @other_type_detected
2353
+ end
2354
+ end
2355
+
2356
+ # Acceptor used when re-checking for self recursion after a self recursion has been detected
2357
+ #
2358
+ # @api private
2359
+ class AssertSelfRecursionStatusAcceptor
2360
+ def visit(type, _)
2361
+ type.set_self_recursion_status if type.is_a?(PTypeAliasType)
2362
+ end
2363
+ end
2364
+
2365
+ def set_self_recursion_status
2366
+ return if @self_recursion || @resolved_type.is_a?(PTypeReferenceType)
2367
+ @self_recursion = true
2368
+ guard = RecursionGuard.new
2369
+ accept(NoopTypeAcceptor::INSTANCE, guard)
2370
+ @self_recursion = guard.recursive_this?(self)
2371
+ when_self_recursion_detected if @self_recursion # no difference
2372
+ end
2373
+
2286
2374
  # Called from the TypeParser once it has found a type using the Loader. The TypeParser will
2287
2375
  # interpret the contained expression and the resolved type is remembered. This method also
2288
2376
  # checks and remembers if the resolve type contains self recursion.
@@ -2303,8 +2391,17 @@ class PTypeAliasType < PAnyType
2303
2391
  # on several methods and this knowledge is used to avoid that for non-recursive
2304
2392
  # types.
2305
2393
  guard = RecursionGuard.new
2306
- accept(NoopTypeAcceptor::INSTANCE, guard)
2394
+ real_type_asserter = AssertOtherTypeAcceptor.new
2395
+ accept(real_type_asserter, guard)
2396
+ unless real_type_asserter.other_type_detected?
2397
+ raise ArgumentError, "Type alias '#{name}' cannot be resolved to a real type"
2398
+ end
2307
2399
  @self_recursion = guard.recursive_this?(self)
2400
+ # All aliases involved must re-check status since this alias is now resolved
2401
+ if @self_recursion
2402
+ accept(AssertSelfRecursionStatusAcceptor.new, RecursionGuard.new)
2403
+ when_self_recursion_detected
2404
+ end
2308
2405
  rescue
2309
2406
  @resolved_type = nil
2310
2407
  raise
@@ -2328,17 +2425,38 @@ class PTypeAliasType < PAnyType
2328
2425
  @self_recursion
2329
2426
  end
2330
2427
 
2428
+ # Returns the expanded string the form of the alias, e.g. <alias name> = <resolved type>
2429
+ #
2430
+ # @return [String] the expanded form of this alias
2431
+ # @api public
2432
+ def to_s
2433
+ TypeFormatter.singleton.alias_expanded_string(self)
2434
+ end
2435
+
2436
+ # Delegates to resolved type
2437
+ def respond_to_missing?(name, include_private)
2438
+ resolved_type.respond_to?(name, include_private)
2439
+ end
2440
+
2441
+ # Delegates to resolved type
2442
+ def method_missing(name, *arguments, &block)
2443
+ resolved_type.send(name, *arguments, &block)
2444
+ end
2445
+
2446
+ # @api private
2447
+ def really_instance?(o, guard = nil)
2448
+ if @self_recursion
2449
+ guard ||= RecursionGuard.new
2450
+ guard.add_that(o)
2451
+ return 0 if guard.add_this(self) == RecursionGuard::SELF_RECURSION_IN_BOTH
2452
+ end
2453
+ resolved_type.really_instance?(o, guard)
2454
+ end
2455
+
2331
2456
  protected
2332
2457
 
2333
2458
  def _assignable?(o, guard)
2334
- guard ||= RecursionGuard.new
2335
- if guard.add_this(self) == RecursionGuard::SELF_RECURSION_IN_BOTH
2336
- # Recursion detected both in self and other. This means that other is assignable
2337
- # to self. This point would not have been reached otherwise
2338
- true
2339
- else
2340
- resolved_type.assignable?(o, guard)
2341
- end
2459
+ resolved_type.assignable?(o, guard)
2342
2460
  end
2343
2461
 
2344
2462
  private
@@ -2352,6 +2470,30 @@ class PTypeAliasType < PAnyType
2352
2470
  end
2353
2471
  end
2354
2472
 
2473
+ def when_self_recursion_detected
2474
+ if @resolved_type.is_a?(PVariantType)
2475
+ # Drop variants that are not real types
2476
+ resolved_types = @resolved_type.types
2477
+ real_types = resolved_types.select do |type|
2478
+ next false if type == self
2479
+ real_type_asserter = AssertOtherTypeAcceptor.new
2480
+ accept(real_type_asserter, RecursionGuard.new)
2481
+ real_type_asserter.other_type_detected?
2482
+ end
2483
+ if real_types.size != resolved_types.size
2484
+ if real_types.size == 1
2485
+ @resolved_type = real_types[0]
2486
+ else
2487
+ @resolved_type = PVariantType.new(real_types)
2488
+ end
2489
+ # Drop self recursion status in case it's not self recursive anymore
2490
+ guard = RecursionGuard.new
2491
+ accept(NoopTypeAcceptor::INSTANCE, guard)
2492
+ @self_recursion = guard.recursive_this?(self)
2493
+ end
2494
+ end
2495
+ end
2496
+
2355
2497
  DEFAULT = PTypeAliasType.new('UnresolvedAlias', nil, PTypeReferenceType::DEFAULT)
2356
2498
  end
2357
2499
  end