puppet 4.8.2-x64-mingw32 → 4.9.0-x64-mingw32
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.
- checksums.yaml +15 -0
- data/CONTRIBUTING.md +25 -1
- data/Gemfile +6 -0
- data/Rakefile +1 -0
- data/ext/project_data.yaml +5 -1
- data/ext/windows/service/daemon.rb +2 -1
- data/install.rb +43 -6
- data/lib/hiera/puppet_function.rb +15 -17
- data/lib/hiera/scope.rb +12 -14
- data/lib/puppet.rb +52 -0
- data/lib/puppet/application/face_base.rb +4 -0
- data/lib/puppet/application/lookup.rb +4 -2
- data/lib/puppet/application/resource.rb +1 -1
- data/lib/puppet/data_providers.rb +6 -3
- data/lib/puppet/data_providers/data_adapter.rb +6 -0
- data/lib/puppet/data_providers/data_function_support.rb +7 -0
- data/lib/puppet/data_providers/function_env_data_provider.rb +7 -0
- data/lib/puppet/data_providers/function_module_data_provider.rb +6 -0
- data/lib/puppet/data_providers/hiera_config.rb +31 -10
- data/lib/puppet/data_providers/hiera_env_data_provider.rb +6 -0
- data/lib/puppet/data_providers/hiera_interpolate.rb +2 -1
- data/lib/puppet/data_providers/hiera_module_data_provider.rb +6 -0
- data/lib/puppet/data_providers/hiera_support.rb +6 -0
- data/lib/puppet/data_providers/json_data_provider_factory.rb +12 -0
- data/lib/puppet/data_providers/yaml_data_provider_factory.rb +12 -0
- data/lib/puppet/defaults.rb +25 -4
- data/lib/puppet/face/ca.rb +2 -0
- data/lib/puppet/face/certificate_request.rb +2 -0
- data/lib/puppet/face/certificate_revocation_list.rb +2 -0
- data/lib/puppet/face/file.rb +3 -0
- data/lib/puppet/face/help.rb +19 -17
- data/lib/puppet/face/help/face.erb +3 -0
- data/lib/puppet/face/key.rb +1 -0
- data/lib/puppet/face/man.rb +4 -2
- data/lib/puppet/face/module/generate.rb +1 -1
- data/lib/puppet/face/status.rb +2 -0
- data/lib/puppet/feature/base.rb +9 -2
- data/lib/puppet/feature/hocon.rb +3 -0
- data/lib/puppet/file_system.rb +15 -3
- data/lib/puppet/file_system/windows.rb +8 -0
- data/lib/puppet/forge.rb +6 -6
- data/lib/puppet/forge/repository.rb +1 -2
- data/lib/puppet/functions/binary_file.rb +4 -10
- data/lib/puppet/functions/hiera_array.rb +1 -1
- data/lib/puppet/functions/hiera_include.rb +1 -1
- data/lib/puppet/functions/hocon_data.rb +24 -0
- data/lib/puppet/functions/json_data.rb +18 -0
- data/lib/puppet/functions/yaml_data.rb +21 -0
- data/lib/puppet/generate/type.rb +1 -1
- data/lib/puppet/graph/simple_graph.rb +4 -2
- data/lib/puppet/indirector/file_bucket_file/file.rb +10 -2
- data/lib/puppet/indirector/request.rb +5 -1
- data/lib/puppet/interface.rb +14 -2
- data/lib/puppet/interface/face_collection.rb +1 -1
- data/lib/puppet/module.rb +14 -2
- data/lib/puppet/module_tool.rb +4 -4
- data/lib/puppet/module_tool/applications/builder.rb +3 -2
- data/lib/puppet/module_tool/applications/installer.rb +14 -14
- data/lib/puppet/module_tool/applications/upgrader.rb +13 -13
- data/lib/puppet/module_tool/installed_modules.rb +7 -7
- data/lib/puppet/module_tool/local_tarball.rb +3 -3
- data/lib/puppet/module_tool/metadata.rb +1 -1
- data/lib/puppet/network/http/connection.rb +2 -0
- data/lib/puppet/network/http/webrick.rb +2 -1
- data/lib/puppet/parser/functions/hiera.rb +14 -0
- data/lib/puppet/parser/functions/hiera_array.rb +14 -0
- data/lib/puppet/parser/functions/hiera_hash.rb +14 -0
- data/lib/puppet/parser/functions/hiera_include.rb +14 -0
- data/lib/puppet/parser/scope.rb +14 -20
- data/lib/puppet/plugins/data_providers.rb +2 -0
- data/lib/puppet/plugins/data_providers/data_provider.rb +108 -17
- data/lib/puppet/plugins/data_providers/registry.rb +2 -36
- data/lib/puppet/pops.rb +6 -9
- data/lib/puppet/pops/adaptable.rb +0 -3
- data/lib/puppet/pops/binder/producers.rb +3 -3
- data/lib/puppet/pops/evaluator/access_operator.rb +4 -4
- data/lib/puppet/pops/evaluator/closure.rb +1 -1
- data/lib/puppet/pops/evaluator/compare_operator.rb +4 -4
- data/lib/puppet/pops/evaluator/evaluator_impl.rb +1 -1
- data/lib/puppet/pops/issues.rb +4 -0
- data/lib/puppet/pops/label_provider.rb +14 -0
- data/lib/puppet/pops/loader/loader_paths.rb +3 -1
- data/lib/puppet/pops/loader/module_loaders.rb +21 -7
- data/lib/puppet/pops/loader/typed_name.rb +0 -2
- data/lib/puppet/pops/loaders.rb +31 -12
- data/lib/puppet/pops/lookup.rb +4 -3
- data/lib/puppet/pops/lookup/configured_data_provider.rb +87 -0
- data/lib/puppet/pops/lookup/context.rb +121 -71
- data/lib/puppet/pops/lookup/data_adapter.rb +27 -0
- data/lib/puppet/pops/lookup/data_dig_function_provider.rb +55 -0
- data/lib/puppet/pops/lookup/data_hash_function_provider.rb +111 -0
- data/lib/puppet/pops/lookup/data_provider.rb +102 -0
- data/lib/puppet/pops/lookup/environment_data_provider.rb +27 -0
- data/lib/puppet/pops/lookup/explainer.rb +122 -82
- data/lib/puppet/pops/lookup/function_provider.rb +82 -0
- data/lib/puppet/pops/lookup/global_data_provider.rb +49 -0
- data/lib/puppet/pops/lookup/hiera_config.rb +601 -0
- data/lib/puppet/pops/lookup/interpolation.rb +56 -35
- data/lib/puppet/pops/lookup/invocation.rb +179 -101
- data/lib/puppet/pops/lookup/location_resolver.rb +72 -0
- data/lib/puppet/pops/lookup/lookup_adapter.rb +451 -0
- data/lib/puppet/pops/lookup/lookup_key.rb +99 -0
- data/lib/puppet/pops/lookup/lookup_key_function_provider.rb +119 -0
- data/lib/puppet/pops/lookup/module_data_provider.rb +58 -0
- data/lib/puppet/pops/lookup/sub_lookup.rb +8 -4
- data/lib/puppet/pops/merge_strategy.rb +120 -39
- data/lib/puppet/pops/parser/egrammar.ra +2 -0
- data/lib/puppet/pops/parser/eparser.rb +816 -808
- data/lib/puppet/pops/parser/locator.rb +3 -3
- data/lib/puppet/pops/parser/slurp_support.rb +4 -3
- data/lib/puppet/pops/pcore.rb +21 -12
- data/lib/puppet/pops/serialization/abstract_reader.rb +17 -7
- data/lib/puppet/pops/serialization/abstract_writer.rb +27 -12
- data/lib/puppet/pops/serialization/deserializer.rb +17 -4
- data/lib/puppet/pops/serialization/extension.rb +37 -8
- data/lib/puppet/pops/serialization/object.rb +14 -6
- data/lib/puppet/pops/serialization/rgen.rb +2 -1
- data/lib/puppet/pops/serialization/serializer.rb +30 -7
- data/lib/puppet/pops/types/implementation_registry.rb +1 -1
- data/lib/puppet/pops/types/p_object_type.rb +55 -12
- data/lib/puppet/pops/types/p_sem_ver_range_type.rb +27 -27
- data/lib/puppet/pops/types/p_sem_ver_type.rb +12 -12
- data/lib/puppet/pops/types/p_timespan_type.rb +6 -6
- data/lib/puppet/pops/types/p_timestamp_type.rb +2 -2
- data/lib/puppet/pops/types/p_type_set_type.rb +7 -16
- data/lib/puppet/pops/types/recursion_guard.rb +64 -20
- data/lib/puppet/pops/types/ruby_generator.rb +10 -0
- data/lib/puppet/pops/types/type_calculator.rb +23 -13
- data/lib/puppet/pops/types/type_factory.rb +20 -9
- data/lib/puppet/pops/types/type_formatter.rb +37 -17
- data/lib/puppet/pops/types/type_mismatch_describer.rb +7 -6
- data/lib/puppet/pops/types/type_parser.rb +6 -0
- data/lib/puppet/pops/types/types.rb +225 -132
- data/lib/puppet/pops/validation.rb +1 -1
- data/lib/puppet/pops/validation/checker4_0.rb +12 -2
- data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
- data/lib/puppet/pops/visitor.rb +4 -3
- data/lib/puppet/provider/mcx/mcxcontent.rb +2 -1
- data/lib/puppet/provider/nameservice.rb +15 -0
- data/lib/puppet/provider/package/appdmg.rb +1 -1
- data/lib/puppet/provider/package/dnf.rb +1 -1
- data/lib/puppet/provider/package/pkg.rb +1 -1
- data/lib/puppet/provider/package/pkgdmg.rb +1 -1
- data/lib/puppet/provider/package/pkgng.rb +1 -1
- data/lib/puppet/provider/package/rpm.rb +2 -2
- data/lib/puppet/provider/service/smf.rb +3 -3
- data/lib/puppet/provider/service/systemd.rb +5 -1
- data/lib/puppet/provider/user/directoryservice.rb +1 -0
- data/lib/puppet/provider/user/user_role_add.rb +15 -0
- data/lib/puppet/provider/yumrepo/inifile.rb +2 -2
- data/lib/puppet/provider/zone/solaris.rb +4 -1
- data/lib/puppet/reference/indirection.rb +1 -1
- data/lib/puppet/resource.rb +2 -3
- data/lib/puppet/resource/catalog.rb +12 -4
- data/lib/puppet/resource/type.rb +3 -3
- data/lib/puppet/settings.rb +1 -1
- data/lib/puppet/settings/config_file.rb +2 -1
- data/lib/puppet/settings/directory_setting.rb +6 -0
- data/lib/puppet/settings/environment_conf.rb +6 -2
- data/lib/puppet/settings/file_or_directory_setting.rb +6 -0
- data/lib/puppet/settings/file_setting.rb +10 -0
- data/lib/puppet/ssl/certificate_authority.rb +13 -2
- data/lib/puppet/ssl/host.rb +23 -1
- data/lib/puppet/transaction/additional_resource_generator.rb +7 -0
- data/lib/puppet/type/user.rb +16 -3
- data/lib/puppet/util.rb +1 -0
- data/lib/puppet/util/execution.rb +3 -3
- data/lib/puppet/util/filetype.rb +11 -5
- data/lib/puppet/util/logging.rb +2 -1
- data/lib/puppet/util/network_device/config.rb +1 -1
- data/lib/puppet/util/plist.rb +6 -0
- data/lib/puppet/util/profiler/aggregate.rb +1 -1
- data/lib/puppet/util/rdoc/generators/puppet_generator.rb +2 -2
- data/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +2 -1
- data/lib/puppet/util/windows/adsi.rb +15 -12
- data/lib/puppet/vendor/load_semantic_puppet.rb +1 -0
- data/lib/puppet/vendor/pathspec/lib/pathspec.rb +2 -1
- data/lib/puppet/vendor/require_vendored.rb +0 -1
- data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet.rb +17 -0
- data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency.rb +7 -7
- data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency/graph.rb +2 -2
- data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency/graph_node.rb +2 -2
- data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/module_release.rb +58 -0
- data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency/source.rb +2 -2
- data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency/unsatisfiable_graph.rb +2 -2
- data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/gem_version.rb +3 -0
- data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/locales/config.yaml +21 -0
- data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/version.rb +48 -21
- data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/version_range.rb +15 -17
- data/lib/puppet/version.rb +1 -1
- data/lib/semver.rb +19 -12
- data/locales/config.yaml +29 -0
- data/locales/puppet.pot +79 -0
- data/man/man5/puppet.conf.5 +1 -1
- data/spec/fixtures/unit/application/environments/puppet_func_provider/functions/{data.pp → environment/data.pp} +0 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_misc/data/common.yaml +2 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/data/common.yaml +1 -1
- data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/hiera.yaml +5 -0
- data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/lib/puppet/bindings/backend/default.rb +9 -0
- data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/lib/puppet_x/backend/special_data_provider_factory.rb +23 -0
- data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/manifests/init.pp +5 -0
- data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/metadata.json +9 -0
- data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/lib/puppet_x/helindbe/sample_env_data.rb +1 -0
- data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/manifests/init.pp +1 -1
- data/spec/fixtures/unit/functions/lookup/data/common.yaml +19 -0
- data/spec/fixtures/unit/functions/lookup_fixture/data/common.yaml +19 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/environment.conf +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/lib/puppet/functions/environment/data.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/abc/lib/puppet/bindings/abc/default.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/abc/lib/puppet/functions/abc/data.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/abc/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bad_data/lib/puppet/bindings/bad_data/default.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bad_data/lib/puppet/functions/bad_data/data.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bad_data/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bca/lib/puppet/bindings/bca/default.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bca/lib/puppet/functions/bca/data.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bca/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_json/data/empty.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_json/hiera.yaml +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_json/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_json/metadata.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_json/data/empty_key.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_json/hiera.yaml +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_json/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_json/metadata.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_yaml/data/empty_key.yaml +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_yaml/hiera.yaml +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_yaml/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_yaml/metadata.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_yaml/data/empty.yaml +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_yaml/hiera.yaml +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_yaml/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_yaml/metadata.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/hieraprovider/data/first.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/hieraprovider/hiera.yaml +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/hieraprovider/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/hieraprovider/metadata.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/meta/lib/puppet/functions/meta/data.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/meta/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/meta/metadata.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/metawcp/lib/puppet/bindings/metawcp/default.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/metawcp/lib/puppet_x/thallgren/sample_module_data.rb +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/metawcp/manifests/init.pp +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/metawcp/metadata.json +0 -0
- data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/no_provider/manifests/init.pp +0 -0
- data/spec/integration/application/apply_spec.rb +88 -2
- data/spec/integration/application/lookup_spec.rb +155 -0
- data/spec/integration/data_binding_spec.rb +5 -5
- data/spec/integration/defaults_spec.rb +13 -0
- data/spec/integration/environments/default_manifest_spec.rb +16 -16
- data/spec/integration/environments/setting_hooks_spec.rb +1 -1
- data/spec/integration/test/test_helper_spec.rb +6 -2
- data/spec/integration/transaction_spec.rb +74 -0
- data/spec/integration/util/execution_spec.rb +8 -0
- data/spec/lib/puppet_spec/module_tool/shared_functions.rb +2 -2
- data/spec/lib/puppet_spec/module_tool/stub_source.rb +1 -1
- data/spec/lib/puppet_spec/unindent.rb +2 -2
- data/spec/unit/application/face_base_spec.rb +16 -0
- data/spec/unit/application/lookup_spec.rb +262 -227
- data/spec/unit/data_providers/{sample_data_provider_spec.rb → custom_data_provider_spec.rb} +14 -16
- data/spec/unit/data_providers/function_data_provider_spec.rb +2 -2
- data/spec/unit/data_providers/hiera_data_provider_spec.rb +60 -97
- data/spec/unit/defaults_spec.rb +1 -1
- data/spec/unit/face/ca_spec.rb +10 -0
- data/spec/unit/face/certificate_request_spec.rb +10 -0
- data/spec/unit/face/certificate_revocation_list_spec.rb +10 -0
- data/spec/unit/face/file_spec.rb +4 -0
- data/spec/unit/face/help_spec.rb +17 -0
- data/spec/unit/face/key_spec.rb +10 -0
- data/spec/unit/face/status_spec.rb +10 -0
- data/spec/unit/file_system_spec.rb +143 -6
- data/spec/unit/functions/binary_file_spec.rb +1 -1
- data/spec/unit/functions/hiera_spec.rb +257 -47
- data/spec/unit/functions/lookup_fixture_spec.rb +693 -0
- data/spec/unit/functions/lookup_spec.rb +1319 -608
- data/spec/unit/functions/new_spec.rb +3 -3
- data/spec/unit/graph/rb_tree_map_spec.rb +1 -1
- data/spec/unit/graph/simple_graph_spec.rb +1 -1
- data/spec/unit/hiera/scope_spec.rb +4 -4
- data/spec/unit/indirector/request_spec.rb +9 -0
- data/spec/unit/interface_spec.rb +27 -0
- data/spec/unit/man_spec.rb +1 -1
- data/spec/unit/module_spec.rb +1 -1
- data/spec/unit/module_tool/applications/builder_spec.rb +16 -1
- data/spec/unit/module_tool/applications/installer_spec.rb +1 -1
- data/spec/unit/module_tool/applications/upgrader_spec.rb +1 -1
- data/spec/unit/module_tool/installed_modules_spec.rb +6 -6
- data/spec/unit/module_tool_spec.rb +3 -3
- data/spec/unit/network/http/connection_spec.rb +10 -0
- data/spec/unit/network/http/webrick_spec.rb +1 -1
- data/spec/unit/pops/evaluator/access_ops_spec.rb +2 -2
- data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +9 -9
- data/spec/unit/pops/loaders/environment_loader_spec.rb +172 -0
- data/spec/unit/pops/lookup/context_spec.rb +45 -16
- data/spec/unit/pops/lookup/interpolation_spec.rb +28 -20
- data/spec/unit/pops/lookup/lookup_spec.rb +197 -0
- data/spec/unit/pops/merge_strategy_spec.rb +18 -0
- data/spec/unit/pops/parser/lexer2_spec.rb +16 -1
- data/spec/unit/pops/parser/parse_site_spec.rb +4 -0
- data/spec/unit/pops/serialization/packer_spec.rb +4 -23
- data/spec/unit/pops/serialization/serialization_spec.rb +32 -8
- data/spec/unit/pops/types/p_object_type_spec.rb +68 -3
- data/spec/unit/pops/types/p_sem_ver_type_spec.rb +4 -4
- data/spec/unit/pops/types/p_type_set_type_spec.rb +31 -2
- data/spec/unit/pops/types/type_acceptor_spec.rb +18 -17
- data/spec/unit/pops/types/type_calculator_spec.rb +39 -40
- data/spec/unit/pops/types/type_factory_spec.rb +3 -3
- data/spec/unit/pops/types/type_formatter_spec.rb +7 -3
- data/spec/unit/pops/types/type_mismatch_describer_spec.rb +13 -2
- data/spec/unit/pops/types/types_spec.rb +25 -2
- data/spec/unit/pops/validator/validator_spec.rb +60 -4
- data/spec/unit/provider/nameservice_spec.rb +42 -0
- data/spec/unit/provider/package/aptrpm_spec.rb +1 -1
- data/spec/unit/provider/package/pkg_spec.rb +22 -0
- data/spec/unit/provider/package/pkgng_spec.rb +12 -0
- data/spec/unit/provider/package/rpm_spec.rb +8 -8
- data/spec/unit/provider/service/smf_spec.rb +13 -11
- data/spec/unit/provider/service/systemd_spec.rb +8 -1
- data/spec/unit/provider/user/useradd_spec.rb +1 -0
- data/spec/unit/puppet_spec.rb +14 -0
- data/spec/unit/resource/catalog_spec.rb +15 -9
- data/spec/unit/resource_spec.rb +20 -17
- data/spec/unit/semver_spec.rb +14 -0
- data/spec/unit/ssl/certificate_authority_spec.rb +12 -1
- data/spec/unit/transaction/additional_resource_generator_spec.rb +11 -0
- data/spec/unit/type/user_spec.rb +32 -6
- data/spec/unit/util/filetype_spec.rb +3 -3
- data/spec/unit/util/yaml_spec.rb +1 -1
- data/spec/unit/util_spec.rb +10 -2
- data/tasks/i18n.rake +20 -0
- metadata +2661 -2607
- data/lib/puppet/data_providers/lookup_adapter.rb +0 -254
- data/lib/puppet/vendor/load_semantic.rb +0 -1
- data/lib/puppet/vendor/semantic/Gemfile +0 -20
- data/lib/puppet/vendor/semantic/PUPPET_README.md +0 -6
- data/lib/puppet/vendor/semantic/Rakefile +0 -69
- data/lib/puppet/vendor/semantic/lib/semantic.rb +0 -7
- data/lib/puppet/vendor/semantic/lib/semantic/dependency/module_release.rb +0 -60
- data/lib/puppet/vendor/semantic/spec/spec_helper.rb +0 -24
- data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/graph_node_spec.rb +0 -141
- data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/graph_spec.rb +0 -162
- data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/module_release_spec.rb +0 -143
- data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/source_spec.rb +0 -5
- data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/unsatisfiable_graph_spec.rb +0 -44
- data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency_spec.rb +0 -383
- data/lib/puppet/vendor/semantic/spec/unit/semantic/version_range_spec.rb +0 -307
- data/lib/puppet/vendor/semantic/spec/unit/semantic/version_spec.rb +0 -608
- data/spec/fixtures/unit/data_providers/environments/sample/manifests/site.pp +0 -6
@@ -210,6 +210,16 @@ class RubyGenerator < TypeFormatter
|
|
210
210
|
init_params.each { |a| bld << ' @' << a.name << ' = ' << a.name << "\n" if a.container.equal?(obj) }
|
211
211
|
bld << " end\n\n"
|
212
212
|
|
213
|
+
bld << " def i12n_hash\n result = "
|
214
|
+
bld << (obj.parent.nil? ? '{}' : 'super')
|
215
|
+
bld << "\n"
|
216
|
+
init_params.each { |a| bld << " result['" << a.name << "'] = @" << a.name << "\n" if a.container.equal?(obj) }
|
217
|
+
bld << " result\n end\n\n"
|
218
|
+
|
219
|
+
bld << " def to_s\n"
|
220
|
+
bld << " " << namespace_relative(segments, TypeFormatter.name) << ".string(self)\n"
|
221
|
+
bld << " end\n\n"
|
222
|
+
|
213
223
|
# Output attr_readers
|
214
224
|
others.each do |a|
|
215
225
|
next unless a.container.equal?(obj)
|
@@ -312,7 +312,7 @@ class TypeCalculator
|
|
312
312
|
infer_set_Array(o)
|
313
313
|
when Hash
|
314
314
|
infer_set_Hash(o)
|
315
|
-
when
|
315
|
+
when SemanticPuppet::Version
|
316
316
|
infer_set_Version(o)
|
317
317
|
else
|
318
318
|
infer_set_Object(o)
|
@@ -389,8 +389,8 @@ class TypeCalculator
|
|
389
389
|
# when both are hashes, return a hash with common key- and element type
|
390
390
|
if t1.is_a?(PHashType) && t2.is_a?(PHashType)
|
391
391
|
key_type = common_type(t1.key_type, t2.key_type)
|
392
|
-
|
393
|
-
return PHashType.new(key_type,
|
392
|
+
value_type = common_type(t1.value_type, t2.value_type)
|
393
|
+
return PHashType.new(key_type, value_type)
|
394
394
|
end
|
395
395
|
|
396
396
|
# when both are host-classes, reduce to PHostClass[] (since one was not assignable to the other)
|
@@ -414,19 +414,29 @@ class TypeCalculator
|
|
414
414
|
return PFloatType.new([t1.numeric_from, t2.numeric_from].min, [t1.numeric_to, t2.numeric_to].max)
|
415
415
|
end
|
416
416
|
|
417
|
-
if t1.is_a?(PStringType) && t2.is_a?(PStringType)
|
418
|
-
|
419
|
-
|
420
|
-
|
417
|
+
if t1.is_a?(PStringType) && (t2.is_a?(PStringType) || t2.is_a?(PEnumType))
|
418
|
+
if(t2.is_a?(PEnumType))
|
419
|
+
return t1.value.nil? ? PEnumType::DEFAULT : PEnumType.new(t2.values | [t1.value])
|
420
|
+
end
|
421
|
+
|
422
|
+
if t1.size_type.nil? || t2.size_type.nil?
|
423
|
+
return t1.value.nil? || t2.value.nil? ? PStringType::DEFAULT : PEnumType.new([t1.value, t2.value])
|
424
|
+
end
|
425
|
+
|
426
|
+
return PStringType.new(common_type(t1.size_type, t2.size_type))
|
421
427
|
end
|
422
428
|
|
423
429
|
if t1.is_a?(PPatternType) && t2.is_a?(PPatternType)
|
424
430
|
return PPatternType.new(t1.patterns | t2.patterns)
|
425
431
|
end
|
426
432
|
|
427
|
-
if t1.is_a?(PEnumType) && t2.is_a?(PEnumType)
|
433
|
+
if t1.is_a?(PEnumType) && (t2.is_a?(PStringType) || t2.is_a?(PEnumType))
|
428
434
|
# The common type is one that complies with either set
|
429
|
-
|
435
|
+
if t2.is_a?(PEnumType)
|
436
|
+
return PEnumType.new(t1.values | t2.values)
|
437
|
+
end
|
438
|
+
|
439
|
+
return t2.value.nil? ? PEnumType::DEFAULT : PEnumType.new(t1.values | [t2.value])
|
430
440
|
end
|
431
441
|
|
432
442
|
if t1.is_a?(PVariantType) && t2.is_a?(PVariantType)
|
@@ -437,7 +447,7 @@ class TypeCalculator
|
|
437
447
|
if t1.is_a?(PRegexpType) && t2.is_a?(PRegexpType)
|
438
448
|
# if they were identical, the general rule would return a parameterized regexp
|
439
449
|
# since they were not, the result is a generic regexp type
|
440
|
-
return
|
450
|
+
return PRegexpType::DEFAULT
|
441
451
|
end
|
442
452
|
|
443
453
|
if t1.is_a?(PCallableType) && t2.is_a?(PCallableType)
|
@@ -581,7 +591,7 @@ class TypeCalculator
|
|
581
591
|
|
582
592
|
# @api private
|
583
593
|
def infer_String(o)
|
584
|
-
PStringType.new(
|
594
|
+
PStringType.new(o)
|
585
595
|
end
|
586
596
|
|
587
597
|
# @api private
|
@@ -735,7 +745,7 @@ class TypeCalculator
|
|
735
745
|
if o.empty?
|
736
746
|
PHashType::EMPTY
|
737
747
|
elsif o.keys.all? {|k| PStringType::NON_EMPTY.instance?(k) }
|
738
|
-
PStructType.new(o.each_pair.map { |k,v| PStructElement.new(PStringType.new(
|
748
|
+
PStructType.new(o.each_pair.map { |k,v| PStructElement.new(PStringType.new(k), infer_set(v)) })
|
739
749
|
else
|
740
750
|
ktype = PVariantType.maybe_create(o.keys.map {|k| infer_set(k) })
|
741
751
|
etype = PVariantType.maybe_create(o.values.map {|e| infer_set(e) })
|
@@ -745,7 +755,7 @@ class TypeCalculator
|
|
745
755
|
|
746
756
|
# @api private
|
747
757
|
def infer_set_Version(o)
|
748
|
-
PSemVerType.new([
|
758
|
+
PSemVerType.new([SemanticPuppet::VersionRange.new(o, o)])
|
749
759
|
end
|
750
760
|
|
751
761
|
def unwrap_single_variant(possible_variant)
|
@@ -75,11 +75,20 @@ module TypeFactory
|
|
75
75
|
@type_calculator.string(t)
|
76
76
|
end
|
77
77
|
|
78
|
-
# Produces the String type
|
78
|
+
# Produces the String type based on nothing, a string value that becomes an exact match constraint, or a parameterized
|
79
|
+
# Integer type that constraints the size.
|
80
|
+
#
|
79
81
|
# @api public
|
80
82
|
#
|
81
|
-
def self.string(
|
82
|
-
|
83
|
+
def self.string(size_type_or_value = nil, *deprecated_second_argument)
|
84
|
+
if deprecated_second_argument.empty?
|
85
|
+
size_type_or_value.nil? ? PStringType::DEFAULT : PStringType.new(size_type_or_value)
|
86
|
+
else
|
87
|
+
if Puppet[:strict] != :off
|
88
|
+
Puppet.warn_once(:deprecatation, "TypeFactory#string_multi_args", "Passing more than one argument to TypeFactory#string is deprecated")
|
89
|
+
end
|
90
|
+
deprecated_second_argument.size == 1 ? PStringType.new(deprecated_second_argument[0]) : PEnumType.new(*deprecated_second_argument)
|
91
|
+
end
|
83
92
|
end
|
84
93
|
|
85
94
|
# Produces the Optional type, i.e. a short hand for Variant[T, Undef]
|
@@ -92,7 +101,7 @@ module TypeFactory
|
|
92
101
|
# @api public
|
93
102
|
#
|
94
103
|
def self.optional(optional_type = nil)
|
95
|
-
POptionalType.new(type_of(optional_type.is_a?(String) ? string(
|
104
|
+
POptionalType.new(type_of(optional_type.is_a?(String) ? string(optional_type) : type_of(optional_type)))
|
96
105
|
end
|
97
106
|
|
98
107
|
# Produces the Enum type, optionally with specific string values
|
@@ -129,7 +138,7 @@ module TypeFactory
|
|
129
138
|
# TODO: Should have stricter name rule
|
130
139
|
if key_type.is_a?(String)
|
131
140
|
raise ArgumentError, 'Struct element key cannot be an empty String' if key_type.empty?
|
132
|
-
key_type = string(
|
141
|
+
key_type = string(key_type)
|
133
142
|
# Must make key optional if the value can be Undef
|
134
143
|
key_type = optional(key_type) if tc.assignable?(value_type, PUndefType::DEFAULT)
|
135
144
|
else
|
@@ -141,12 +150,14 @@ module TypeFactory
|
|
141
150
|
s = key_type
|
142
151
|
when POptionalType
|
143
152
|
s = key_type.optional_type
|
144
|
-
when PStringType
|
153
|
+
when PStringType
|
145
154
|
s = key_type
|
155
|
+
when PEnumType
|
156
|
+
s = key_type.values.size == 1 ? PStringType.new(key_type.values[0]) : nil
|
146
157
|
else
|
147
158
|
raise ArgumentError, "Illegal Struct member key type. Expected NotUndef, Optional, String, or Enum. Got: #{key_type.class.name}"
|
148
159
|
end
|
149
|
-
unless
|
160
|
+
unless s.is_a?(PStringType) && !s.value.nil?
|
150
161
|
raise ArgumentError, "Unable to extract a non-empty literal string from Struct member key type #{tc.string(key_type)}"
|
151
162
|
end
|
152
163
|
end
|
@@ -307,7 +318,7 @@ module TypeFactory
|
|
307
318
|
# @api public
|
308
319
|
#
|
309
320
|
def self.collection(size_type = nil)
|
310
|
-
size_type.nil? ? PCollectionType::DEFAULT : PCollectionType.new(
|
321
|
+
size_type.nil? ? PCollectionType::DEFAULT : PCollectionType.new(size_type)
|
311
322
|
end
|
312
323
|
|
313
324
|
# Produces the Data type
|
@@ -435,7 +446,7 @@ module TypeFactory
|
|
435
446
|
# @api public
|
436
447
|
#
|
437
448
|
def self.not_undef(inst_type = nil)
|
438
|
-
inst_type = string(
|
449
|
+
inst_type = string(inst_type) if inst_type.is_a?(String)
|
439
450
|
PNotUndefType.new(inst_type)
|
440
451
|
end
|
441
452
|
|
@@ -42,17 +42,24 @@ class TypeFormatter
|
|
42
42
|
#
|
43
43
|
# @api public
|
44
44
|
def indented_string(t, indent = 0, indent_width = 2)
|
45
|
+
@bld = ''
|
46
|
+
append_indented_string(t, indent, indent_width)
|
47
|
+
@bld
|
48
|
+
end
|
49
|
+
|
50
|
+
# @api private
|
51
|
+
def append_indented_string(t, indent = 0, indent_width = 2, skip_initial_indent = false)
|
52
|
+
save_indent = @indent
|
53
|
+
save_indent_width = @indent_width
|
45
54
|
@indent = indent
|
46
55
|
@indent_width = indent_width
|
47
56
|
begin
|
48
|
-
@bld
|
49
|
-
(@indent * @indent_width).times { @bld << ' ' }
|
57
|
+
(@indent * @indent_width).times { @bld << ' ' } unless skip_initial_indent
|
50
58
|
append_string(t)
|
51
59
|
@bld << "\n"
|
52
|
-
@bld
|
53
60
|
ensure
|
54
|
-
@indent =
|
55
|
-
@indent_width =
|
61
|
+
@indent = save_indent
|
62
|
+
@indent_width = save_indent_width
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
@@ -169,11 +176,10 @@ class TypeFormatter
|
|
169
176
|
# @api private
|
170
177
|
def string_PStringType(t)
|
171
178
|
range = range_array_part(t.size_type)
|
172
|
-
append_array('String', range.empty?) do
|
179
|
+
append_array('String', range.empty? && !(@debug && !t.value.nil?)) do
|
173
180
|
if @debug
|
174
|
-
append_elements(range,
|
175
|
-
|
176
|
-
chomp_list
|
181
|
+
append_elements(range, !t.value.nil?)
|
182
|
+
append_string(t.value) unless t.value.nil?
|
177
183
|
else
|
178
184
|
append_elements(range)
|
179
185
|
end
|
@@ -297,6 +303,14 @@ class TypeFormatter
|
|
297
303
|
append_array('Collection', range.empty? ) { append_elements(range) }
|
298
304
|
end
|
299
305
|
|
306
|
+
def string_PuppetObject(t)
|
307
|
+
@bld << t._ptype.name << '('
|
308
|
+
append_indented_string(t.i12n_hash, @indent || 0, @indent_width || 2, true)
|
309
|
+
@bld.chomp!
|
310
|
+
@bld << ')'
|
311
|
+
newline if @indent
|
312
|
+
end
|
313
|
+
|
300
314
|
# @api private
|
301
315
|
def string_PUnitType(_)
|
302
316
|
@bld << 'Unit'
|
@@ -326,7 +340,7 @@ class TypeFormatter
|
|
326
340
|
append_array('Hash') { append_strings([0, 0]) }
|
327
341
|
else
|
328
342
|
append_array('Hash', t == PHashType::DATA) do
|
329
|
-
append_strings([t.key_type, t.
|
343
|
+
append_strings([t.key_type, t.value_type], true)
|
330
344
|
append_elements(range_array_part(t.size_type), true)
|
331
345
|
chomp_list
|
332
346
|
end
|
@@ -356,8 +370,8 @@ class TypeFormatter
|
|
356
370
|
def string_PNotUndefType(t)
|
357
371
|
contained_type = t.type
|
358
372
|
append_array('NotUndef', contained_type.nil? || contained_type.class == PAnyType) do
|
359
|
-
if contained_type.is_a?(PStringType) && contained_type.
|
360
|
-
append_string(contained_type.
|
373
|
+
if contained_type.is_a?(PStringType) && !contained_type.value.nil?
|
374
|
+
append_string(contained_type.value)
|
361
375
|
else
|
362
376
|
append_string(contained_type)
|
363
377
|
end
|
@@ -414,7 +428,7 @@ class TypeFormatter
|
|
414
428
|
if @expanded
|
415
429
|
append_object_hash(t.i12n_hash(@type_set.nil? || !@type_set.defines_type?(t)))
|
416
430
|
else
|
417
|
-
@bld << (@type_set ? @type_set.name_for(t) : t.label)
|
431
|
+
@bld << (@type_set ? @type_set.name_for(t, t.label) : t.label)
|
418
432
|
end
|
419
433
|
end
|
420
434
|
|
@@ -427,8 +441,8 @@ class TypeFormatter
|
|
427
441
|
def string_POptionalType(t)
|
428
442
|
optional_type = t.optional_type
|
429
443
|
append_array('Optional', optional_type.nil?) do
|
430
|
-
if optional_type.is_a?(PStringType) && optional_type.
|
431
|
-
append_string(optional_type.
|
444
|
+
if optional_type.is_a?(PStringType) && !optional_type.value.nil?
|
445
|
+
append_string(optional_type.value)
|
432
446
|
else
|
433
447
|
append_string(optional_type)
|
434
448
|
end
|
@@ -440,8 +454,14 @@ class TypeFormatter
|
|
440
454
|
expand = @expanded
|
441
455
|
if expand && t.self_recursion?
|
442
456
|
@guard ||= RecursionGuard.new
|
443
|
-
|
457
|
+
@guard.with_this(t) { |state| format_type_alias_type(t, (state & RecursionGuard::SELF_RECURSION_IN_THIS) == 0) }
|
458
|
+
else
|
459
|
+
format_type_alias_type(t, expand)
|
444
460
|
end
|
461
|
+
end
|
462
|
+
|
463
|
+
# @api private
|
464
|
+
def format_type_alias_type(t, expand)
|
445
465
|
if @type_set.nil?
|
446
466
|
@bld << t.name
|
447
467
|
if expand
|
@@ -452,7 +472,7 @@ class TypeFormatter
|
|
452
472
|
if expand && @type_set.defines_type?(t)
|
453
473
|
append_string(t.resolved_type)
|
454
474
|
else
|
455
|
-
@bld << @type_set.name_for(t)
|
475
|
+
@bld << @type_set.name_for(t, t.name)
|
456
476
|
end
|
457
477
|
end
|
458
478
|
end
|
@@ -329,8 +329,7 @@ module Types
|
|
329
329
|
a = detailed_actual_to_s(e, a)
|
330
330
|
e = e.map { |t| t.to_alias_expanded_s }
|
331
331
|
else
|
332
|
-
|
333
|
-
e = e.map { |t| s = t.simple_name; sns.count {|x| x == s } == 1 ? s : t.to_s }.uniq
|
332
|
+
e = e.map { |t| t.simple_name }.uniq
|
334
333
|
a = a.simple_name
|
335
334
|
end
|
336
335
|
case e.size
|
@@ -464,7 +463,7 @@ module Types
|
|
464
463
|
|
465
464
|
def actual_string
|
466
465
|
a = actual
|
467
|
-
a.is_a?(PStringType) && a.
|
466
|
+
a.is_a?(PStringType) && !a.value.nil? ? "'#{a.value}'" : a.simple_name
|
468
467
|
end
|
469
468
|
end
|
470
469
|
|
@@ -722,8 +721,10 @@ module Types
|
|
722
721
|
arg_count.times do |index|
|
723
722
|
adx = index >= etypes.size ? etypes.size - 1 : index
|
724
723
|
etype = etypes[adx]
|
725
|
-
|
726
|
-
|
724
|
+
unless etype.assignable?(atypes[index])
|
725
|
+
descriptions = describe(etype, atypes[index], path + [ParameterPathElement.new(enames[adx])])
|
726
|
+
return descriptions unless descriptions.empty?
|
727
|
+
end
|
727
728
|
end
|
728
729
|
EMPTY_ARRAY
|
729
730
|
else
|
@@ -816,7 +817,7 @@ module Types
|
|
816
817
|
def describe_PHashType(expected, actual, path)
|
817
818
|
descriptions = []
|
818
819
|
key_type = expected.key_type || PAnyType::DEFAULT
|
819
|
-
value_type = expected.
|
820
|
+
value_type = expected.value_type || PAnyType::DEFAULT
|
820
821
|
if actual.is_a?(PStructType)
|
821
822
|
elements = actual.elements
|
822
823
|
expected_size = expected.size_type || PCollectionType::DEFAULT_SIZE
|
@@ -37,6 +37,12 @@ class TypeParser
|
|
37
37
|
interpret(model.current.body, context)
|
38
38
|
end
|
39
39
|
|
40
|
+
# @api private
|
41
|
+
def parse_literal(string, context = nil)
|
42
|
+
model = @parser.parse_string(string)
|
43
|
+
interpret_any(model.current.body, context)
|
44
|
+
end
|
45
|
+
|
40
46
|
# @param ast [Puppet::Pops::Model::PopsObject] the ast to interpret
|
41
47
|
# @param context [Puppet::Parser::Scope,Loader::Loader, nil] scope or loader to use when loading type aliases
|
42
48
|
# @return [PAnyType] a specialization of the PAnyType representing the type.
|
@@ -292,6 +292,10 @@ class PAnyType < TypedModelObject
|
|
292
292
|
simple_name
|
293
293
|
end
|
294
294
|
|
295
|
+
def create(*args)
|
296
|
+
Loaders.find_loader(nil).load(:function, 'new').call({}, self, *args)
|
297
|
+
end
|
298
|
+
|
295
299
|
def new_function(loader)
|
296
300
|
self.class.new_function(self, loader)
|
297
301
|
end
|
@@ -550,7 +554,7 @@ class PUndefType < PAnyType
|
|
550
554
|
end
|
551
555
|
|
552
556
|
def instance?(o, guard = nil)
|
553
|
-
o.nil? ||
|
557
|
+
o.nil? || :undef == o
|
554
558
|
end
|
555
559
|
|
556
560
|
# @api private
|
@@ -701,6 +705,16 @@ class PEnumType < PScalarType
|
|
701
705
|
block_given? ? r.each(&block) : r
|
702
706
|
end
|
703
707
|
|
708
|
+
def generalize
|
709
|
+
# General form of an Enum is a String
|
710
|
+
if @values.empty?
|
711
|
+
PStringType::DEFAULT
|
712
|
+
else
|
713
|
+
range = @values.map(&:size).minmax
|
714
|
+
PStringType.new(PIntegerType.new(range.min, range.max))
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
704
718
|
def iterable?(guard = nil)
|
705
719
|
true
|
706
720
|
end
|
@@ -731,8 +745,9 @@ class PEnumType < PScalarType
|
|
731
745
|
end
|
732
746
|
case o
|
733
747
|
when PStringType
|
734
|
-
# if the
|
735
|
-
|
748
|
+
# if the contained string is found in the set of enums
|
749
|
+
v = o.value
|
750
|
+
!v.nil? && svalues.any? { |e| e == v }
|
736
751
|
when PEnumType
|
737
752
|
!o.values.empty? && o.values.all? { |s| svalues.any? {|e| e == s }}
|
738
753
|
else
|
@@ -807,8 +822,8 @@ end
|
|
807
822
|
class PNumericType < PAbstractRangeType
|
808
823
|
def self.register_ptype(loader, ir)
|
809
824
|
create_ptype(loader, ir, 'ScalarType',
|
810
|
-
'from' => { KEY_TYPE => PNumericType::DEFAULT, KEY_VALUE =>
|
811
|
-
'to' => { KEY_TYPE => PNumericType::DEFAULT, KEY_VALUE =>
|
825
|
+
'from' => { KEY_TYPE => POptionalType.new(PNumericType::DEFAULT), KEY_VALUE => nil },
|
826
|
+
'to' => { KEY_TYPE => POptionalType.new(PNumericType::DEFAULT), KEY_VALUE => nil }
|
812
827
|
)
|
813
828
|
end
|
814
829
|
|
@@ -1153,58 +1168,36 @@ end
|
|
1153
1168
|
class PCollectionType < PAnyType
|
1154
1169
|
def self.register_ptype(loader, ir)
|
1155
1170
|
create_ptype(loader, ir, 'AnyType',
|
1156
|
-
'
|
1157
|
-
KEY_TYPE => POptionalType.new(PType::DEFAULT),
|
1171
|
+
'size_type' => {
|
1172
|
+
KEY_TYPE => POptionalType.new(PType.new(PIntegerType::DEFAULT)),
|
1158
1173
|
KEY_VALUE => nil
|
1159
1174
|
}
|
1160
1175
|
)
|
1161
1176
|
end
|
1162
1177
|
|
1163
|
-
attr_reader :
|
1178
|
+
attr_reader :size_type
|
1164
1179
|
|
1165
|
-
def initialize(
|
1180
|
+
def initialize(size_type)
|
1166
1181
|
@size_type = size_type
|
1167
|
-
if !size_type.nil? && size_type.from == 0 && size_type.to == 0
|
1168
|
-
@element_type = PUnitType::DEFAULT
|
1169
|
-
else
|
1170
|
-
@element_type = element_type
|
1171
|
-
end
|
1172
1182
|
end
|
1173
1183
|
|
1174
1184
|
def accept(visitor, guard)
|
1175
1185
|
super
|
1176
1186
|
@size_type.accept(visitor, guard) unless @size_type.nil?
|
1177
|
-
@element_type.accept(visitor, guard) unless @element_type.nil?
|
1178
1187
|
end
|
1179
1188
|
|
1180
1189
|
def generalize
|
1181
|
-
|
1182
|
-
DEFAULT
|
1183
|
-
else
|
1184
|
-
ge_type = @element_type.generalize
|
1185
|
-
@size_type.nil? && @element_type.equal?(ge_type) ? self : self.class.new(ge_type, nil)
|
1186
|
-
end
|
1190
|
+
DEFAULT
|
1187
1191
|
end
|
1188
1192
|
|
1189
1193
|
def normalize(guard = nil)
|
1190
|
-
|
1191
|
-
DEFAULT
|
1192
|
-
else
|
1193
|
-
ne_type = @element_type.normalize(guard)
|
1194
|
-
@element_type.equal?(ne_type) ? self : self.class.new(ne_type, @size_type)
|
1195
|
-
end
|
1194
|
+
DEFAULT
|
1196
1195
|
end
|
1197
1196
|
|
1198
1197
|
def instance?(o, guard = nil)
|
1199
1198
|
assignable?(TypeCalculator.infer(o), guard)
|
1200
1199
|
end
|
1201
1200
|
|
1202
|
-
def resolve(type_parser, loader)
|
1203
|
-
relement_type = @element_type
|
1204
|
-
relement_type = relement_type.resolve(type_parser, loader) unless relement_type.nil?
|
1205
|
-
relement_type.equal?(@element_type) ? self : self.class.new(relement_type, @size_type)
|
1206
|
-
end
|
1207
|
-
|
1208
1201
|
# Returns an array with from (min) size to (max) size
|
1209
1202
|
def size_range
|
1210
1203
|
(@size_type || DEFAULT_SIZE).range
|
@@ -1216,19 +1209,15 @@ class PCollectionType < PAnyType
|
|
1216
1209
|
end
|
1217
1210
|
|
1218
1211
|
def hash
|
1219
|
-
@
|
1212
|
+
@size_type.hash
|
1220
1213
|
end
|
1221
1214
|
|
1222
1215
|
def iterable?(guard = nil)
|
1223
1216
|
true
|
1224
1217
|
end
|
1225
1218
|
|
1226
|
-
def iterable_type(guard = nil)
|
1227
|
-
@element_type.nil? ? PIterableType::DEFAULT : PIterableType.new(@element_type)
|
1228
|
-
end
|
1229
|
-
|
1230
1219
|
def eql?(o)
|
1231
|
-
self.class == o.class && @
|
1220
|
+
self.class == o.class && @size_type == o.size_type
|
1232
1221
|
end
|
1233
1222
|
|
1234
1223
|
|
@@ -1266,7 +1255,7 @@ end
|
|
1266
1255
|
class PIterableType < PTypeWithContainedType
|
1267
1256
|
def self.register_ptype(loader, ir)
|
1268
1257
|
create_ptype(loader, ir, 'AnyType',
|
1269
|
-
'
|
1258
|
+
'type' => {
|
1270
1259
|
KEY_TYPE => POptionalType.new(PType::DEFAULT),
|
1271
1260
|
KEY_VALUE => nil
|
1272
1261
|
}
|
@@ -1324,7 +1313,7 @@ end
|
|
1324
1313
|
class PIteratorType < PTypeWithContainedType
|
1325
1314
|
def self.register_ptype(loader, ir)
|
1326
1315
|
create_ptype(loader, ir, 'AnyType',
|
1327
|
-
'
|
1316
|
+
'type' => {
|
1328
1317
|
KEY_TYPE => POptionalType.new(PType::DEFAULT),
|
1329
1318
|
KEY_VALUE => nil
|
1330
1319
|
}
|
@@ -1362,27 +1351,27 @@ end
|
|
1362
1351
|
class PStringType < PScalarType
|
1363
1352
|
def self.register_ptype(loader, ir)
|
1364
1353
|
create_ptype(loader, ir, 'ScalarType',
|
1365
|
-
'
|
1366
|
-
KEY_TYPE => POptionalType.new(PType.new(PIntegerType::DEFAULT)),
|
1367
|
-
|
1368
|
-
|
1369
|
-
'values' => {
|
1370
|
-
KEY_TYPE => PArrayType.new(PStringType::DEFAULT),
|
1371
|
-
KEY_VALUE => EMPTY_ARRAY
|
1372
|
-
}
|
1373
|
-
)
|
1354
|
+
'size_type_or_value' => {
|
1355
|
+
KEY_TYPE => POptionalType.new(PVariantType.new([PStringType::DEFAULT, PType.new(PIntegerType::DEFAULT)])),
|
1356
|
+
KEY_VALUE => nil
|
1357
|
+
})
|
1374
1358
|
end
|
1375
1359
|
|
1376
|
-
attr_reader :
|
1360
|
+
attr_reader :size_type_or_value
|
1377
1361
|
|
1378
|
-
def initialize(
|
1379
|
-
|
1380
|
-
|
1362
|
+
def initialize(size_type_or_value, deprecated_multi_args = EMPTY_ARRAY)
|
1363
|
+
unless deprecated_multi_args.empty?
|
1364
|
+
if Puppet[:strict] != :off
|
1365
|
+
Puppet.warn_once(:deprecatation, "PStringType#initialize_multi_args", "Passing more than one argument to PStringType#initialize is deprecated")
|
1366
|
+
end
|
1367
|
+
size_type_or_value = deprecated_multi_args[0]
|
1368
|
+
end
|
1369
|
+
@size_type_or_value = size_type_or_value
|
1381
1370
|
end
|
1382
1371
|
|
1383
1372
|
def accept(visitor, guard)
|
1384
1373
|
super
|
1385
|
-
@
|
1374
|
+
@size_type_or_value.accept(visitor, guard) if @size_type_or_value.is_a?(PIntegerType)
|
1386
1375
|
end
|
1387
1376
|
|
1388
1377
|
def generalize
|
@@ -1390,7 +1379,7 @@ class PStringType < PScalarType
|
|
1390
1379
|
end
|
1391
1380
|
|
1392
1381
|
def hash
|
1393
|
-
@
|
1382
|
+
@size_type_or_value.hash
|
1394
1383
|
end
|
1395
1384
|
|
1396
1385
|
def iterable?(guard = nil)
|
@@ -1402,18 +1391,54 @@ class PStringType < PScalarType
|
|
1402
1391
|
end
|
1403
1392
|
|
1404
1393
|
def eql?(o)
|
1405
|
-
self.class == o.class && @
|
1394
|
+
self.class == o.class && @size_type_or_value == o.size_type_or_value
|
1406
1395
|
end
|
1407
1396
|
|
1408
1397
|
def instance?(o, guard = nil)
|
1409
1398
|
# true if size compliant
|
1410
|
-
if o.is_a?(String)
|
1411
|
-
|
1399
|
+
if o.is_a?(String)
|
1400
|
+
if @size_type_or_value.is_a?(PIntegerType)
|
1401
|
+
@size_type_or_value.instance?(o.size, guard)
|
1402
|
+
else
|
1403
|
+
@size_type_or_value.nil? ? true : o == value
|
1404
|
+
end
|
1412
1405
|
else
|
1413
1406
|
false
|
1414
1407
|
end
|
1415
1408
|
end
|
1416
1409
|
|
1410
|
+
def value
|
1411
|
+
@size_type_or_value.is_a?(PIntegerType) ? nil : @size_type_or_value
|
1412
|
+
end
|
1413
|
+
|
1414
|
+
# @deprecated
|
1415
|
+
# @api private
|
1416
|
+
def values
|
1417
|
+
if Puppet[:strict] != :off
|
1418
|
+
Puppet.warn_once(:deprecatation, "PStringType#values", "Method PStringType#values is deprecated. Use #value instead")
|
1419
|
+
end
|
1420
|
+
@value.is_a?(String) ? [@value] : EMPTY_ARRAY
|
1421
|
+
end
|
1422
|
+
|
1423
|
+
def size_type
|
1424
|
+
@size_type_or_value.is_a?(PIntegerType) ? @size_type_or_value : nil
|
1425
|
+
end
|
1426
|
+
|
1427
|
+
def size_type
|
1428
|
+
@size_type_or_value.is_a?(PIntegerType) ? @size_type_or_value : nil
|
1429
|
+
end
|
1430
|
+
|
1431
|
+
def derived_size_type
|
1432
|
+
if @size_type_or_value.is_a?(PIntegerType)
|
1433
|
+
@size_type_or_value
|
1434
|
+
elsif @size_type_or_value.is_a?(String)
|
1435
|
+
sz = @size_type_or_value.size
|
1436
|
+
PIntegerType.new(sz, sz)
|
1437
|
+
else
|
1438
|
+
PCollectionType::DEFAULT_SIZE
|
1439
|
+
end
|
1440
|
+
end
|
1441
|
+
|
1417
1442
|
def self.new_function(_, loader)
|
1418
1443
|
@new_function ||= Puppet::Functions.create_loaded_function(:new_string, loader) do
|
1419
1444
|
local_types do
|
@@ -1450,44 +1475,48 @@ class PStringType < PScalarType
|
|
1450
1475
|
|
1451
1476
|
# @api private
|
1452
1477
|
def _assignable?(o, guard)
|
1453
|
-
if
|
1478
|
+
if @size_type_or_value.is_a?(PIntegerType)
|
1454
1479
|
# A general string is assignable by any other string or pattern restricted string
|
1455
1480
|
# if the string has a size constraint it does not match since there is no reasonable way
|
1456
1481
|
# to compute the min/max length a pattern will match. For enum, it is possible to test that
|
1457
1482
|
# each enumerator value is within range
|
1458
1483
|
case o
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
#
|
1466
|
-
@
|
1467
|
-
|
1468
|
-
when PEnumType
|
1469
|
-
if o.values.empty?
|
1470
|
-
# enum represents all enums, and thus all strings, a sized constrained string can thus not
|
1471
|
-
# be assigned any enum (unless it is max size).
|
1472
|
-
@size_type.nil? || @size_type.assignable?(PCollectionType::DEFAULT_SIZE, guard)
|
1473
|
-
else
|
1474
|
-
# true if all enum values are within range
|
1475
|
-
orange = o.values.map(&:size).minmax
|
1476
|
-
srange = (@size_type || PCollectionType::DEFAULT_SIZE).range
|
1477
|
-
# If o min and max are within the range of t
|
1478
|
-
srange[0] <= orange[0] && srange[1] >= orange[1]
|
1479
|
-
end
|
1484
|
+
when PStringType
|
1485
|
+
@size_type_or_value.assignable?(o.derived_size_type, guard)
|
1486
|
+
|
1487
|
+
when PEnumType
|
1488
|
+
if o.values.empty?
|
1489
|
+
# enum represents all enums, and thus all strings, a sized constrained string can thus not
|
1490
|
+
# be assigned any enum (unless it is max size).
|
1491
|
+
@size_type_or_value.assignable?(PCollectionType::DEFAULT_SIZE, guard)
|
1480
1492
|
else
|
1481
|
-
#
|
1482
|
-
|
1493
|
+
# true if all enum values are within range
|
1494
|
+
orange = o.values.map(&:size).minmax
|
1495
|
+
srange = @size_type_or_value.range
|
1496
|
+
# If o min and max are within the range of t
|
1497
|
+
srange[0] <= orange[0] && srange[1] >= orange[1]
|
1498
|
+
end
|
1499
|
+
|
1500
|
+
when PPatternType
|
1501
|
+
# true if size constraint is at least 0 to +Infinity (which is the same as the default)
|
1502
|
+
@size_type_or_value.assignable?(PCollectionType::DEFAULT_SIZE, guard)
|
1503
|
+
else
|
1504
|
+
# no other type matches string
|
1505
|
+
false
|
1483
1506
|
end
|
1484
|
-
elsif o.is_a?(PStringType)
|
1485
|
-
# A specific string acts as a set of strings - must have exactly the same strings
|
1486
|
-
# In this case, size does not matter since the definition is very precise anyway
|
1487
|
-
values == o.values
|
1488
1507
|
else
|
1489
|
-
|
1490
|
-
|
1508
|
+
case o
|
1509
|
+
when PStringType
|
1510
|
+
# Must match exactly when value is a string
|
1511
|
+
@size_type_or_value.nil? || @size_type_or_value == o.size_type_or_value
|
1512
|
+
when PEnumType
|
1513
|
+
@size_type_or_value.nil? ? true : o.values.size == 1 && @size_type_or_value == o.values[0]
|
1514
|
+
when PPatternType
|
1515
|
+
@size_type_or_value.nil?
|
1516
|
+
else
|
1517
|
+
# All others are false, since no other type describes the same set of specific strings
|
1518
|
+
false
|
1519
|
+
end
|
1491
1520
|
end
|
1492
1521
|
end
|
1493
1522
|
end
|
@@ -1574,16 +1603,28 @@ class PPatternType < PScalarType
|
|
1574
1603
|
def _assignable?(o, guard)
|
1575
1604
|
return true if self == o
|
1576
1605
|
case o
|
1577
|
-
when PStringType
|
1606
|
+
when PStringType
|
1607
|
+
v = o.value
|
1608
|
+
if v.nil?
|
1609
|
+
# Strings cannot all match a pattern, but if there is no pattern it is ok
|
1610
|
+
# (There should really always be a pattern, but better safe than sorry).
|
1611
|
+
@patterns.empty?
|
1612
|
+
else
|
1613
|
+
# the string in String type must match one of the patterns in Pattern type,
|
1614
|
+
# or Pattern represents all Patterns == all Strings
|
1615
|
+
regexps = @patterns.map { |p| p.regexp }
|
1616
|
+
regexps.empty? || regexps.any? { |re| re.match(v) }
|
1617
|
+
end
|
1618
|
+
when PEnumType
|
1578
1619
|
if o.values.empty?
|
1579
|
-
#
|
1620
|
+
# Enums (unknown which ones) cannot all match a pattern, but if there is no pattern it is ok
|
1580
1621
|
# (There should really always be a pattern, but better safe than sorry).
|
1581
1622
|
@patterns.empty?
|
1582
1623
|
else
|
1583
1624
|
# all strings in String/Enum type must match one of the patterns in Pattern type,
|
1584
1625
|
# or Pattern represents all Patterns == all Strings
|
1585
1626
|
regexps = @patterns.map { |p| p.regexp }
|
1586
|
-
regexps.empty? || o.values.all? { |
|
1627
|
+
regexps.empty? || o.values.all? { |s| regexps.any? {|re| re.match(s) } }
|
1587
1628
|
end
|
1588
1629
|
when PPatternType
|
1589
1630
|
@patterns.empty?
|
@@ -1668,7 +1709,7 @@ class PStructElement < TypedModelObject
|
|
1668
1709
|
def name
|
1669
1710
|
k = key_type
|
1670
1711
|
k = k.optional_type if k.is_a?(POptionalType)
|
1671
|
-
k.
|
1712
|
+
k.value
|
1672
1713
|
end
|
1673
1714
|
|
1674
1715
|
def initialize(key_type, value_type)
|
@@ -1841,7 +1882,7 @@ class PStructType < PAnyType
|
|
1841
1882
|
true
|
1842
1883
|
else
|
1843
1884
|
required += 1
|
1844
|
-
if e.value_type.assignable?(o.
|
1885
|
+
if e.value_type.assignable?(o.value_type, guard)
|
1845
1886
|
# Hash must have something that is assignable. We don't care about the name or size of the key though
|
1846
1887
|
# because we have no instance of a hash to compare against.
|
1847
1888
|
key_type.generalize.assignable?(o.key_type)
|
@@ -2040,7 +2081,7 @@ class PTupleType < PAnyType
|
|
2040
2081
|
return false unless size_s.assignable?(size_o, guard)
|
2041
2082
|
unless s_types.empty?
|
2042
2083
|
o_types = o.types
|
2043
|
-
return
|
2084
|
+
return size_s.numeric_from == 0 if o_types.empty?
|
2044
2085
|
o_types.size.times do |index|
|
2045
2086
|
return false unless (s_types[index] || s_types[-1]).assignable?(o_types[index], guard)
|
2046
2087
|
end
|
@@ -2073,6 +2114,10 @@ class PCallableType < PAnyType
|
|
2073
2114
|
'block_type' => {
|
2074
2115
|
KEY_TYPE => POptionalType.new(PCallableType::DEFAULT),
|
2075
2116
|
KEY_VALUE => nil
|
2117
|
+
},
|
2118
|
+
'return_type' => {
|
2119
|
+
KEY_TYPE => POptionalType.new(PType::DEFAULT),
|
2120
|
+
KEY_VALUE => PAnyType::DEFAULT
|
2076
2121
|
}
|
2077
2122
|
)
|
2078
2123
|
end
|
@@ -2212,13 +2257,29 @@ class PArrayType < PCollectionType
|
|
2212
2257
|
|
2213
2258
|
def self.register_ptype(loader, ir)
|
2214
2259
|
create_ptype(loader, ir, 'CollectionType',
|
2215
|
-
'
|
2216
|
-
KEY_TYPE => POptionalType.new(PType
|
2260
|
+
'element_type' => {
|
2261
|
+
KEY_TYPE => POptionalType.new(PType::DEFAULT),
|
2217
2262
|
KEY_VALUE => nil
|
2218
2263
|
}
|
2219
2264
|
)
|
2220
2265
|
end
|
2221
2266
|
|
2267
|
+
attr_reader :element_type
|
2268
|
+
|
2269
|
+
def initialize(element_type, size_type = nil)
|
2270
|
+
super(size_type)
|
2271
|
+
if !size_type.nil? && size_type.from == 0 && size_type.to == 0
|
2272
|
+
@element_type = PUnitType::DEFAULT
|
2273
|
+
else
|
2274
|
+
@element_type = element_type
|
2275
|
+
end
|
2276
|
+
end
|
2277
|
+
|
2278
|
+
def accept(visitor, guard)
|
2279
|
+
super
|
2280
|
+
@element_type.accept(visitor, guard) unless @element_type.nil?
|
2281
|
+
end
|
2282
|
+
|
2222
2283
|
# @api private
|
2223
2284
|
def callable_args?(callable, guard = nil)
|
2224
2285
|
param_t = callable.param_types
|
@@ -2230,19 +2291,39 @@ class PArrayType < PCollectionType
|
|
2230
2291
|
def generalize
|
2231
2292
|
if self == DATA
|
2232
2293
|
self
|
2294
|
+
elsif @element_type.nil?
|
2295
|
+
DEFAULT
|
2233
2296
|
else
|
2234
|
-
|
2297
|
+
ge_type = @element_type.generalize
|
2298
|
+
@size_type.nil? && @element_type.equal?(ge_type) ? self : self.class.new(ge_type, nil)
|
2235
2299
|
end
|
2236
2300
|
end
|
2237
2301
|
|
2302
|
+
def eql?(o)
|
2303
|
+
super && @element_type == o.element_type
|
2304
|
+
end
|
2305
|
+
|
2306
|
+
def hash
|
2307
|
+
super ^ @element_type.hash
|
2308
|
+
end
|
2309
|
+
|
2238
2310
|
def normalize(guard = nil)
|
2239
2311
|
if self == DATA
|
2240
2312
|
self
|
2313
|
+
elsif @element_type.nil?
|
2314
|
+
DEFAULT
|
2241
2315
|
else
|
2242
|
-
|
2316
|
+
ne_type = @element_type.normalize(guard)
|
2317
|
+
@element_type.equal?(ne_type) ? self : self.class.new(ne_type, @size_type)
|
2243
2318
|
end
|
2244
2319
|
end
|
2245
2320
|
|
2321
|
+
def resolve(type_parser, loader)
|
2322
|
+
relement_type = @element_type
|
2323
|
+
relement_type = relement_type.resolve(type_parser, loader) unless relement_type.nil?
|
2324
|
+
relement_type.equal?(@element_type) ? self : self.class.new(relement_type, @size_type)
|
2325
|
+
end
|
2326
|
+
|
2246
2327
|
def instance?(o, guard = nil)
|
2247
2328
|
return false unless o.is_a?(Array)
|
2248
2329
|
element_t = element_type
|
@@ -2251,6 +2332,10 @@ class PArrayType < PCollectionType
|
|
2251
2332
|
size_t.nil? || size_t.instance?(o.size, guard)
|
2252
2333
|
end
|
2253
2334
|
|
2335
|
+
def iterable_type(guard = nil)
|
2336
|
+
@element_type.nil? ? PIterableType::DEFAULT : PIterableType.new(@element_type)
|
2337
|
+
end
|
2338
|
+
|
2254
2339
|
# Returns a new function that produces an Array
|
2255
2340
|
#
|
2256
2341
|
def self.new_function(_, loader)
|
@@ -2335,33 +2420,38 @@ class PHashType < PCollectionType
|
|
2335
2420
|
KEY_TYPE => POptionalType.new(PType::DEFAULT),
|
2336
2421
|
KEY_VALUE => nil
|
2337
2422
|
},
|
2338
|
-
'
|
2423
|
+
'value_type' => {
|
2339
2424
|
KEY_TYPE => POptionalType.new(PType::DEFAULT),
|
2340
2425
|
KEY_VALUE => nil,
|
2341
|
-
KEY_OVERRIDE => true
|
2342
|
-
},
|
2343
|
-
'size_type' => {
|
2344
|
-
KEY_TYPE => POptionalType.new(PType.new(PIntegerType::DEFAULT)),
|
2345
|
-
KEY_VALUE => nil
|
2346
2426
|
}
|
2347
2427
|
)
|
2348
2428
|
end
|
2349
2429
|
|
2350
|
-
attr_accessor :key_type
|
2351
|
-
alias value_type element_type
|
2430
|
+
attr_accessor :key_type, :value_type
|
2352
2431
|
|
2353
2432
|
def initialize(key_type, value_type, size_type = nil)
|
2354
|
-
super(
|
2433
|
+
super(size_type)
|
2355
2434
|
if !size_type.nil? && size_type.from == 0 && size_type.to == 0
|
2356
2435
|
@key_type = PUnitType::DEFAULT
|
2436
|
+
@value_type = PUnitType::DEFAULT
|
2357
2437
|
else
|
2358
2438
|
@key_type = key_type
|
2439
|
+
@value_type = value_type
|
2359
2440
|
end
|
2360
2441
|
end
|
2361
2442
|
|
2362
2443
|
def accept(visitor, guard)
|
2363
2444
|
super
|
2364
2445
|
@key_type.accept(visitor, guard) unless @key_type.nil?
|
2446
|
+
@value_type.accept(visitor, guard) unless @value_type.nil?
|
2447
|
+
end
|
2448
|
+
|
2449
|
+
def element_type
|
2450
|
+
if Puppet[:strict] != :off
|
2451
|
+
Puppet.warn_once(:deprecation, 'Puppet::Pops::Types::PHashType#element_type',
|
2452
|
+
'Puppet::Pops::Types::PHashType#element_type is deprecated, use #value_type instead')
|
2453
|
+
end
|
2454
|
+
@value_type
|
2365
2455
|
end
|
2366
2456
|
|
2367
2457
|
def generalize
|
@@ -2370,9 +2460,9 @@ class PHashType < PCollectionType
|
|
2370
2460
|
else
|
2371
2461
|
key_t = @key_type
|
2372
2462
|
key_t = key_t.generalize unless key_t.nil?
|
2373
|
-
value_t = @
|
2463
|
+
value_t = @value_type
|
2374
2464
|
value_t = value_t.generalize unless value_t.nil?
|
2375
|
-
@size_type.nil? && @key_type.equal?(key_t) && @
|
2465
|
+
@size_type.nil? && @key_type.equal?(key_t) && @value_type.equal?(value_t) ? self : PHashType.new(key_t, value_t, nil)
|
2376
2466
|
end
|
2377
2467
|
end
|
2378
2468
|
|
@@ -2382,22 +2472,22 @@ class PHashType < PCollectionType
|
|
2382
2472
|
else
|
2383
2473
|
key_t = @key_type
|
2384
2474
|
key_t = key_t.normalize(guard) unless key_t.nil?
|
2385
|
-
value_t = @
|
2475
|
+
value_t = @value_type
|
2386
2476
|
value_t = value_t.normalize(guard) unless value_t.nil?
|
2387
|
-
@size_type.nil? && @key_type.equal?(key_t) && @
|
2477
|
+
@size_type.nil? && @key_type.equal?(key_t) && @value_type.equal?(value_t) ? self : PHashType.new(key_t, value_t, nil)
|
2388
2478
|
end
|
2389
2479
|
end
|
2390
2480
|
|
2391
2481
|
def hash
|
2392
|
-
super ^ @key_type.hash
|
2482
|
+
super ^ @key_type.hash ^ @value_type.hash
|
2393
2483
|
end
|
2394
2484
|
|
2395
2485
|
def instance?(o, guard = nil)
|
2396
2486
|
return false unless o.is_a?(Hash)
|
2397
2487
|
key_t = key_type
|
2398
|
-
|
2488
|
+
value_t = value_type
|
2399
2489
|
if (key_t.nil? || o.keys.all? {|key| key_t.instance?(key, guard) }) &&
|
2400
|
-
(
|
2490
|
+
(value_t.nil? || o.values.all? {|value| value_t.instance?(value, guard) })
|
2401
2491
|
size_t = size_type
|
2402
2492
|
size_t.nil? || size_t.instance?(o.size, guard)
|
2403
2493
|
else
|
@@ -2413,12 +2503,12 @@ class PHashType < PCollectionType
|
|
2413
2503
|
if self == DEFAULT || self == EMPTY
|
2414
2504
|
PIterableType.new(DEFAULT_KEY_PAIR_TUPLE)
|
2415
2505
|
else
|
2416
|
-
PIterableType.new(PTupleType.new([@key_type, @
|
2506
|
+
PIterableType.new(PTupleType.new([@key_type, @value_type], KEY_PAIR_TUPLE_SIZE))
|
2417
2507
|
end
|
2418
2508
|
end
|
2419
2509
|
|
2420
2510
|
def eql?(o)
|
2421
|
-
super && @key_type == o.key_type
|
2511
|
+
super && @key_type == o.key_type && @value_type == o.value_type
|
2422
2512
|
end
|
2423
2513
|
|
2424
2514
|
def is_the_empty_hash?
|
@@ -2428,9 +2518,9 @@ class PHashType < PCollectionType
|
|
2428
2518
|
def resolve(type_parser, loader)
|
2429
2519
|
rkey_type = @key_type
|
2430
2520
|
rkey_type = rkey_type.resolve(type_parser, loader) unless rkey_type.nil?
|
2431
|
-
rvalue_type = @
|
2521
|
+
rvalue_type = @value_type
|
2432
2522
|
rvalue_type = rvalue_type.resolve(type_parser, loader) unless rvalue_type.nil?
|
2433
|
-
rkey_type.equal?(@key_type) && rvalue_type.equal?(@
|
2523
|
+
rkey_type.equal?(@key_type) && rvalue_type.equal?(@value_type) ? self : self.class.new(rkey_type, rvalue_type, @size_type)
|
2434
2524
|
end
|
2435
2525
|
|
2436
2526
|
# Returns a new function that produces a Hash
|
@@ -2495,7 +2585,7 @@ class PHashType < PCollectionType
|
|
2495
2585
|
when PHashType
|
2496
2586
|
size_s = size_type
|
2497
2587
|
return true if (size_s.nil? || size_s.from == 0) && o.is_the_empty_hash?
|
2498
|
-
return false unless (key_type.nil? || key_type.assignable?(o.key_type, guard)) && (
|
2588
|
+
return false unless (key_type.nil? || key_type.assignable?(o.key_type, guard)) && (value_type.nil? || value_type.assignable?(o.value_type, guard))
|
2499
2589
|
super
|
2500
2590
|
when PStructType
|
2501
2591
|
# hash must accept String as key type
|
@@ -2503,7 +2593,7 @@ class PHashType < PCollectionType
|
|
2503
2593
|
# hash must accept the size of the struct
|
2504
2594
|
o_elements = o.elements
|
2505
2595
|
(size_type || DEFAULT_SIZE).instance?(o_elements.size, guard) &&
|
2506
|
-
o_elements.all? {|e| (key_type.nil? || key_type.instance?(e.name, guard)) && (
|
2596
|
+
o_elements.all? {|e| (key_type.nil? || key_type.instance?(e.name, guard)) && (value_type.nil? || value_type.assignable?(e.value_type, guard)) }
|
2507
2597
|
else
|
2508
2598
|
false
|
2509
2599
|
end
|
@@ -2700,11 +2790,11 @@ class PVariantType < PAnyType
|
|
2700
2790
|
# @api private
|
2701
2791
|
def merge_enums(array)
|
2702
2792
|
if array.size > 1
|
2703
|
-
parts = array.partition {|t| t.is_a?(PEnumType) || t.is_a?(PStringType) && !t.
|
2793
|
+
parts = array.partition {|t| t.is_a?(PEnumType) && !t.values.empty? || t.is_a?(PStringType) && !t.value.nil? }
|
2704
2794
|
enums = parts[0]
|
2705
2795
|
if enums.size > 1
|
2706
2796
|
others = parts[1]
|
2707
|
-
others << PEnumType.new(enums.map { |enum| enum.values }.flatten.uniq)
|
2797
|
+
others << PEnumType.new(enums.map { |enum| enum.is_a?(PStringType) ? enum.value : enum.values }.flatten.uniq)
|
2708
2798
|
array = others
|
2709
2799
|
end
|
2710
2800
|
end
|
@@ -2883,7 +2973,7 @@ end
|
|
2883
2973
|
class POptionalType < PTypeWithContainedType
|
2884
2974
|
|
2885
2975
|
def self.register_ptype(loader, ir)
|
2886
|
-
create_ptype(loader, ir, '
|
2976
|
+
create_ptype(loader, ir, 'AnyType',
|
2887
2977
|
'type' => {
|
2888
2978
|
KEY_TYPE => POptionalType.new(PType::DEFAULT),
|
2889
2979
|
KEY_VALUE => nil
|
@@ -3017,9 +3107,10 @@ class PTypeAliasType < PAnyType
|
|
3017
3107
|
def assignable?(o, guard = nil)
|
3018
3108
|
if @self_recursion
|
3019
3109
|
guard ||= RecursionGuard.new
|
3020
|
-
|
3110
|
+
guard.with_this(self) { |state| state == RecursionGuard::SELF_RECURSION_IN_BOTH ? true : super(o, guard) }
|
3111
|
+
else
|
3112
|
+
super(o, guard)
|
3021
3113
|
end
|
3022
|
-
super(o, guard)
|
3023
3114
|
end
|
3024
3115
|
|
3025
3116
|
# Returns the resolved type. The type must have been resolved by a call prior to calls to this
|
@@ -3070,7 +3161,7 @@ class PTypeAliasType < PAnyType
|
|
3070
3161
|
end
|
3071
3162
|
|
3072
3163
|
def visit(type, _)
|
3073
|
-
unless type.is_a?(PTypeAliasType) || type.is_a?(PVariantType)
|
3164
|
+
unless type.is_a?(PTypeAliasType) || type.is_a?(PVariantType)
|
3074
3165
|
@other_type_detected = true
|
3075
3166
|
end
|
3076
3167
|
end
|
@@ -3183,10 +3274,12 @@ class PTypeAliasType < PAnyType
|
|
3183
3274
|
def really_instance?(o, guard = nil)
|
3184
3275
|
if @self_recursion
|
3185
3276
|
guard ||= RecursionGuard.new
|
3186
|
-
guard.
|
3187
|
-
|
3277
|
+
guard.with_that(o) do
|
3278
|
+
guard.with_this(self) { |state| state == RecursionGuard::SELF_RECURSION_IN_BOTH ? 0 : resolved_type.really_instance?(o, guard) }
|
3279
|
+
end
|
3280
|
+
else
|
3281
|
+
resolved_type.really_instance?(o, guard)
|
3188
3282
|
end
|
3189
|
-
resolved_type.really_instance?(o, guard)
|
3190
3283
|
end
|
3191
3284
|
|
3192
3285
|
# @return `nil` to prevent serialization of the type_expr used when first initializing this instance
|
@@ -3210,7 +3303,7 @@ class PTypeAliasType < PAnyType
|
|
3210
3303
|
def guarded_recursion(guard, dflt)
|
3211
3304
|
if @self_recursion
|
3212
3305
|
guard ||= RecursionGuard.new
|
3213
|
-
|
3306
|
+
guard.with_this(self) { |state| (state & RecursionGuard::SELF_RECURSION_IN_THIS) == 0 ? yield(guard) : dflt }
|
3214
3307
|
else
|
3215
3308
|
yield(guard)
|
3216
3309
|
end
|
@@ -3223,7 +3316,7 @@ class PTypeAliasType < PAnyType
|
|
3223
3316
|
real_types = resolved_types.select do |type|
|
3224
3317
|
next false if type == self
|
3225
3318
|
real_type_asserter = AssertOtherTypeAcceptor.new
|
3226
|
-
accept(real_type_asserter, RecursionGuard.new)
|
3319
|
+
type.accept(real_type_asserter, RecursionGuard.new)
|
3227
3320
|
real_type_asserter.other_type_detected?
|
3228
3321
|
end
|
3229
3322
|
if real_types.size != resolved_types.size
|