puppet 5.0.1-x64-mingw32 → 5.1.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.

Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/lib/puppet/agent.rb +1 -0
  3. data/lib/puppet/defaults.rb +1 -1
  4. data/lib/puppet/functions.rb +6 -7
  5. data/lib/puppet/functions/all.rb +100 -0
  6. data/lib/puppet/functions/any.rb +105 -0
  7. data/lib/puppet/functions/defined.rb +3 -3
  8. data/lib/puppet/functions/new.rb +2 -1
  9. data/lib/puppet/functions/reduce.rb +31 -0
  10. data/lib/puppet/functions/tree_each.rb +200 -0
  11. data/lib/puppet/module.rb +30 -0
  12. data/lib/puppet/parser/functions/new.rb +67 -0
  13. data/lib/puppet/parser/functions/reduce.rb +31 -0
  14. data/lib/puppet/parser/relationship.rb +2 -2
  15. data/lib/puppet/parser/resource.rb +39 -10
  16. data/lib/puppet/parser/scope.rb +1 -1
  17. data/lib/puppet/pops/evaluator/access_operator.rb +11 -4
  18. data/lib/puppet/pops/evaluator/collector_transformer.rb +1 -1
  19. data/lib/puppet/pops/evaluator/evaluator_impl.rb +4 -4
  20. data/lib/puppet/pops/evaluator/relationship_operator.rb +1 -1
  21. data/lib/puppet/pops/evaluator/runtime3_converter.rb +3 -3
  22. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +1 -1
  23. data/lib/puppet/pops/loader/module_loaders.rb +1 -1
  24. data/lib/puppet/pops/loader/static_loader.rb +1 -2
  25. data/lib/puppet/pops/loaders.rb +1 -2
  26. data/lib/puppet/pops/lookup/context.rb +1 -1
  27. data/lib/puppet/pops/lookup/lookup_adapter.rb +2 -1
  28. data/lib/puppet/pops/model/ast.rb +440 -436
  29. data/lib/puppet/pops/model/factory.rb +140 -140
  30. data/lib/puppet/pops/pcore.rb +1 -2
  31. data/lib/puppet/pops/resource/param.rb +1 -1
  32. data/lib/puppet/pops/resource/resource_type_impl.rb +1 -1
  33. data/lib/puppet/pops/serialization/from_data_converter.rb +0 -12
  34. data/lib/puppet/pops/time/timestamp.rb +29 -17
  35. data/lib/puppet/pops/types/annotatable.rb +2 -2
  36. data/lib/puppet/pops/types/annotation.rb +8 -8
  37. data/lib/puppet/pops/types/class_loader.rb +3 -3
  38. data/lib/puppet/pops/types/implementation_registry.rb +1 -1
  39. data/lib/puppet/pops/types/iterable.rb +2 -2
  40. data/lib/puppet/pops/types/p_binary_type.rb +2 -2
  41. data/lib/puppet/pops/types/p_init_type.rb +238 -0
  42. data/lib/puppet/pops/types/p_meta_type.rb +14 -11
  43. data/lib/puppet/pops/types/p_object_type.rb +15 -15
  44. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +2 -2
  45. data/lib/puppet/pops/types/p_sem_ver_type.rb +2 -2
  46. data/lib/puppet/pops/types/p_sensitive_type.rb +2 -2
  47. data/lib/puppet/pops/types/p_timespan_type.rb +6 -6
  48. data/lib/puppet/pops/types/p_timestamp_type.rb +6 -2
  49. data/lib/puppet/pops/types/p_type_set_type.rb +10 -9
  50. data/lib/puppet/pops/types/ruby_generator.rb +6 -5
  51. data/lib/puppet/pops/types/ruby_method.rb +2 -2
  52. data/lib/puppet/pops/types/string_converter.rb +1 -1
  53. data/lib/puppet/pops/types/tree_iterators.rb +250 -0
  54. data/lib/puppet/pops/types/type_calculator.rb +13 -13
  55. data/lib/puppet/pops/types/type_factory.rb +26 -7
  56. data/lib/puppet/pops/types/type_formatter.rb +9 -4
  57. data/lib/puppet/pops/types/type_parser.rb +8 -3
  58. data/lib/puppet/pops/types/type_set_reference.rb +2 -2
  59. data/lib/puppet/pops/types/types.rb +168 -109
  60. data/lib/puppet/provider/package/gem.rb +10 -9
  61. data/lib/puppet/provider/package/pip.rb +12 -3
  62. data/lib/puppet/provider/package/yum.rb +9 -1
  63. data/lib/puppet/resource/capability_finder.rb +30 -11
  64. data/lib/puppet/type/file.rb +21 -13
  65. data/lib/puppet/util/execution.rb +67 -14
  66. data/lib/puppet/util/suidmanager.rb +1 -0
  67. data/lib/puppet/version.rb +1 -1
  68. data/locales/puppet.pot +130 -66
  69. data/man/man5/puppet.conf.5 +1 -1
  70. data/spec/fixtures/unit/provider/package/yum/yum-check-update-simple.txt +1 -0
  71. data/spec/integration/parser/collection_spec.rb +40 -1
  72. data/spec/shared_contexts/types_setup.rb +41 -2
  73. data/spec/unit/agent_spec.rb +11 -0
  74. data/spec/unit/file_bucket/dipper_spec.rb +13 -4
  75. data/spec/unit/functions/all_spec.rb +97 -0
  76. data/spec/unit/functions/any_spec.rb +109 -0
  77. data/spec/unit/functions/hiera_spec.rb +5 -0
  78. data/spec/unit/functions/new_spec.rb +66 -0
  79. data/spec/unit/functions/tree_each_spec.rb +444 -0
  80. data/spec/unit/module_spec.rb +29 -0
  81. data/spec/unit/pops/serialization/serialization_spec.rb +2 -2
  82. data/spec/unit/pops/serialization/to_from_hr_spec.rb +2 -2
  83. data/spec/unit/pops/types/iterable_spec.rb +9 -9
  84. data/spec/unit/pops/types/p_init_type_spec.rb +285 -0
  85. data/spec/unit/pops/types/p_object_type_spec.rb +8 -8
  86. data/spec/unit/pops/types/p_sensitive_type_spec.rb +4 -0
  87. data/spec/unit/pops/types/p_timespan_type_spec.rb +14 -0
  88. data/spec/unit/pops/types/p_timestamp_type_spec.rb +19 -1
  89. data/spec/unit/pops/types/p_type_set_type_spec.rb +2 -2
  90. data/spec/unit/pops/types/ruby_generator_spec.rb +9 -22
  91. data/spec/unit/pops/types/string_converter_spec.rb +2 -2
  92. data/spec/unit/pops/types/type_acceptor_spec.rb +2 -2
  93. data/spec/unit/pops/types/type_calculator_spec.rb +43 -38
  94. data/spec/unit/pops/types/type_factory_spec.rb +6 -6
  95. data/spec/unit/pops/types/type_formatter_spec.rb +6 -6
  96. data/spec/unit/pops/types/types_spec.rb +16 -4
  97. data/spec/unit/provider/package/gem_spec.rb +6 -6
  98. data/spec/unit/provider/package/pip_spec.rb +44 -23
  99. data/spec/unit/provider/package/puppet_gem_spec.rb +1 -1
  100. data/spec/unit/provider/package/yum_spec.rb +8 -0
  101. data/spec/unit/resource/capability_finder_spec.rb +4 -5
  102. data/spec/unit/type/file_spec.rb +19 -14
  103. data/spec/unit/util/execution_spec.rb +216 -82
  104. data/tasks/generate_ast_model.rake +10 -2
  105. metadata +15 -2
@@ -212,7 +212,7 @@ class TypeCalculator
212
212
  when c == FalseClass, c == TrueClass
213
213
  type = PBooleanType::DEFAULT
214
214
  when c == Class
215
- type = PType::DEFAULT
215
+ type = PTypeType::DEFAULT
216
216
  when c == Array
217
217
  # Assume array of any
218
218
  type = PArrayType::DEFAULT
@@ -347,8 +347,8 @@ class TypeCalculator
347
347
  end
348
348
 
349
349
  # when both are host-classes, reduce to PHostClass[] (since one was not assignable to the other)
350
- if t1.is_a?(PHostClassType) && t2.is_a?(PHostClassType)
351
- return PHostClassType::DEFAULT
350
+ if t1.is_a?(PClassType) && t2.is_a?(PClassType)
351
+ return PClassType::DEFAULT
352
352
  end
353
353
 
354
354
  # when both are resources, reduce to Resource[T] or Resource[] (since one was not assignable to the other)
@@ -427,8 +427,8 @@ class TypeCalculator
427
427
  end
428
428
 
429
429
  # Meta types Type[Integer] + Type[String] => Type[Data]
430
- if t1.is_a?(PType) && t2.is_a?(PType)
431
- return PType.new(common_type(t1.type, t2.type))
430
+ if t1.is_a?(PTypeType) && t2.is_a?(PTypeType)
431
+ return PTypeType.new(common_type(t1.type, t2.type))
432
432
  end
433
433
 
434
434
  if common_rich_data?(t1,t2)
@@ -484,11 +484,11 @@ class TypeCalculator
484
484
  reduce_type(enumerable.map {|o| infer(o) })
485
485
  end
486
486
 
487
- # The type of all modules is PType
487
+ # The type of all modules is PTypeType
488
488
  # @api private
489
489
  #
490
490
  def infer_Module(o)
491
- PType::new(PRuntimeType.new(:ruby, o.name))
491
+ PTypeType::new(PRuntimeType.new(:ruby, o.name))
492
492
  end
493
493
 
494
494
  # @api private
@@ -518,19 +518,19 @@ class TypeCalculator
518
518
  end
519
519
  end
520
520
 
521
- # The type of all types is PType
521
+ # The type of all types is PTypeType
522
522
  # @api private
523
523
  #
524
524
  def infer_PAnyType(o)
525
- PType.new(o)
525
+ PTypeType.new(o)
526
526
  end
527
527
 
528
- # The type of all types is PType
528
+ # The type of all types is PTypeType
529
529
  # This is the metatype short circuit.
530
530
  # @api private
531
531
  #
532
- def infer_PType(o)
533
- PType.new(o)
532
+ def infer_PTypeType(o)
533
+ PTypeType.new(o)
534
534
  end
535
535
 
536
536
  # @api private
@@ -629,7 +629,7 @@ class TypeCalculator
629
629
  # A mapping must be made to empty string. A nil value will result in an error later
630
630
  title = o.title
631
631
  title = '' if :undef == title
632
- PType.new(PResourceType.new(o.type.to_s, title))
632
+ PTypeType.new(PResourceType.new(o.type.to_s, title))
633
633
  end
634
634
 
635
635
  # @api private
@@ -54,6 +54,21 @@ module TypeFactory
54
54
  PNumericType::DEFAULT
55
55
  end
56
56
 
57
+ # Produces the Init type
58
+ # @api public
59
+ def self.init(*args)
60
+ case args.size
61
+ when 0
62
+ PInitType::DEFAULT
63
+ when 1
64
+ type = args[0]
65
+ type.nil? ? PInitType::DEFAULT : PInitType.new(type, EMPTY_ARRAY)
66
+ else
67
+ type = args.shift
68
+ PInitType.new(type, args)
69
+ end
70
+ end
71
+
57
72
  # Produces the Iterable type
58
73
  # @api public
59
74
  #
@@ -101,7 +116,11 @@ module TypeFactory
101
116
  # @api public
102
117
  #
103
118
  def self.optional(optional_type = nil)
104
- POptionalType.new(type_of(optional_type.is_a?(String) ? string(optional_type) : type_of(optional_type)))
119
+ if optional_type.nil?
120
+ POptionalType::DEFAULT
121
+ else
122
+ POptionalType.new(type_of(optional_type.is_a?(String) ? string(optional_type) : type_of(optional_type)))
123
+ end
105
124
  end
106
125
 
107
126
  # Produces the Enum type, optionally with specific string values
@@ -396,16 +415,16 @@ module TypeFactory
396
415
  end
397
416
  end
398
417
 
399
- # Produces PHostClassType with a string class_name. A PHostClassType with
400
- # nil or empty name is compatible with any other PHostClassType. A
401
- # PHostClassType with a given name is only compatible with a PHostClassType
418
+ # Produces PClassType with a string class_name. A PClassType with
419
+ # nil or empty name is compatible with any other PClassType. A
420
+ # PClassType with a given name is only compatible with a PClassType
402
421
  # with the same name.
403
422
  #
404
423
  def self.host_class(class_name = nil)
405
424
  if class_name.nil?
406
- PHostClassType::DEFAULT
425
+ PClassType::DEFAULT
407
426
  else
408
- PHostClassType.new(class_name.sub(/^::/, ''))
427
+ PClassType.new(class_name.sub(/^::/, ''))
409
428
  end
410
429
  end
411
430
 
@@ -482,7 +501,7 @@ module TypeFactory
482
501
  # @api public
483
502
  #
484
503
  def self.type_type(inst_type = nil)
485
- inst_type.nil? ? PType::DEFAULT : PType.new(inst_type)
504
+ inst_type.nil? ? PTypeType::DEFAULT : PTypeType.new(inst_type)
486
505
  end
487
506
 
488
507
  # Produce a type corresponding to the class of given unless given is a
@@ -169,10 +169,15 @@ class TypeFormatter
169
169
  end
170
170
 
171
171
  # @api private
172
- def string_PType(t)
172
+ def string_PTypeType(t)
173
173
  append_array('Type', t.type.nil?) { append_string(t.type) }
174
174
  end
175
175
 
176
+ # @api private
177
+ def string_PInitType(t)
178
+ append_array('Init', t.type.nil?) { append_strings([t.type, *t.init_args]) }
179
+ end
180
+
176
181
  # @api private
177
182
  def string_PIterableType(t)
178
183
  append_array('Iterable', t.element_type.nil?) { append_string(t.element_type) }
@@ -341,7 +346,7 @@ class TypeFormatter
341
346
 
342
347
  # @api private
343
348
  def string_PRuntimeType(t)
344
- append_array('Runtime') { append_strings([t.runtime, t.name_or_pattern]) }
349
+ append_array('Runtime', t.runtime.nil? && t.name_or_pattern.nil?) { append_strings([t.runtime, t.name_or_pattern]) }
345
350
  end
346
351
 
347
352
  # @api private
@@ -376,7 +381,7 @@ class TypeFormatter
376
381
  end
377
382
 
378
383
  # @api private
379
- def string_PHostClassType(t)
384
+ def string_PClassType(t)
380
385
  append_array('Class', t.class_name.nil?) { append_elements([t.class_name]) }
381
386
  end
382
387
 
@@ -457,7 +462,7 @@ class TypeFormatter
457
462
 
458
463
  # @api private
459
464
  def string_PSensitiveType(t)
460
- append_array('Sensitive') { append_string(t.type) }
465
+ append_array('Sensitive', PAnyType::DEFAULT == t.type) { append_string(t.type) }
461
466
  end
462
467
 
463
468
  # @api private
@@ -71,7 +71,7 @@ class TypeParser
71
71
 
72
72
  # @api private
73
73
  def interpret_TypeAlias(o, context)
74
- Loader::TypeDefinitionInstantiator.create_type(o.name, o.type_expr, Pcore::RUNTIME_NAME_AUTHORITY).resolve(self, loader_from_context(o, context))
74
+ Loader::TypeDefinitionInstantiator.create_type(o.name, o.type_expr, Pcore::RUNTIME_NAME_AUTHORITY).resolve(loader_from_context(o, context))
75
75
  end
76
76
 
77
77
  # @api private
@@ -159,6 +159,7 @@ class TypeParser
159
159
  'integer' => TypeFactory.integer,
160
160
  'float' => TypeFactory.float,
161
161
  'numeric' => TypeFactory.numeric,
162
+ 'init' => TypeFactory.init,
162
163
  'iterable' => TypeFactory.iterable,
163
164
  'iterator' => TypeFactory.iterator,
164
165
  'string' => TypeFactory.string,
@@ -208,7 +209,7 @@ class TypeParser
208
209
  loader = loader_from_context(name_ast, context)
209
210
  unless loader.nil?
210
211
  type = loader.load(:type, name)
211
- type = type.resolve(self, loader) unless type.nil?
212
+ type = type.resolve(loader) unless type.nil?
212
213
  end
213
214
  type || TypeFactory.type_reference(name_ast.cased_value)
214
215
  end
@@ -408,6 +409,10 @@ class TypeParser
408
409
  raise_invalid_parameters_error('Object', 1, parameters.size) unless parameters.size == 1
409
410
  TypeFactory.type_set(parameters[0])
410
411
 
412
+ when 'init'
413
+ assert_type(ast, parameters[0])
414
+ TypeFactory.init(*parameters)
415
+
411
416
  when 'iterable'
412
417
  if parameters.size != 1
413
418
  raise_invalid_parameters_error('Iterable', 1, parameters.size)
@@ -517,7 +522,7 @@ class TypeParser
517
522
  type = nil
518
523
  unless loader.nil?
519
524
  type = loader.load(:type, type_name)
520
- type = type.resolve(self, loader) unless type.nil?
525
+ type = type.resolve(loader) unless type.nil?
521
526
  end
522
527
 
523
528
  if type.nil?
@@ -36,7 +36,7 @@ class TypeSetReference
36
36
  result
37
37
  end
38
38
 
39
- def resolve(type_parser, loader)
39
+ def resolve(loader)
40
40
  typed_name = Loader::TypedName.new(:type, @name, @name_authority)
41
41
  loaded_entry = loader.load_typed(typed_name)
42
42
  type_set = loaded_entry.nil? ? nil : loaded_entry.value
@@ -44,7 +44,7 @@ class TypeSetReference
44
44
  raise ArgumentError, "#{self} cannot be resolved" if type_set.nil?
45
45
  raise ArgumentError, "#{self} resolves to a #{type_set.name}" unless type_set.is_a?(PTypeSetType)
46
46
 
47
- @type_set = type_set.resolve(type_parser, loader)
47
+ @type_set = type_set.resolve(loader)
48
48
  unless @version_range.include?(@type_set.version)
49
49
  raise ArgumentError, "#{self} resolves to an incompatible version. Expected #{@version_range}, got #{type_set.version}"
50
50
  end
@@ -60,13 +60,13 @@ class TypedModelObject < Object
60
60
  RubyMethod.register_ptype(loader, ir)
61
61
  ]
62
62
  Types.constants.each do |c|
63
+ next if c == :PType || c == :PHostClassType
63
64
  cls = Types.const_get(c)
64
65
  next unless cls.is_a?(Class) && cls < self
65
66
  type = cls.register_ptype(loader, ir)
66
67
  types << type unless type.nil?
67
68
  end
68
- tp = TypeParser.singleton
69
- types.each { |type| type.resolve(tp, loader) }
69
+ types.each { |type| type.resolve(loader) }
70
70
  end
71
71
  end
72
72
 
@@ -187,6 +187,12 @@ class PAnyType < TypedModelObject
187
187
  self
188
188
  end
189
189
 
190
+ # Returns the loader that loaded this type.
191
+ # @return [Loaders::Loader] the loader
192
+ def loader
193
+ Loaders.static_loader
194
+ end
195
+
190
196
  # Normalizes the type. This does not change the characteristics of the type but it will remove duplicates
191
197
  # and constructs like NotUndef[T] where T is not assignable from Undef and change Variant[*T] where all
192
198
  # T are enums into an Enum.
@@ -202,11 +208,10 @@ class PAnyType < TypedModelObject
202
208
  # resolve internal type expressions using a loader. Presently, this method is a no-op for all types
203
209
  # except the {{PTypeAliasType}}.
204
210
  #
205
- # @param type_parser [TypeParser] type parser
206
211
  # @param loader [Loader::Loader] loader to use
207
212
  # @return [PTypeAliasType] the receiver of the call, i.e. `self`
208
213
  # @api private
209
- def resolve(type_parser, loader)
214
+ def resolve(loader)
210
215
  self
211
216
  end
212
217
 
@@ -283,11 +288,10 @@ class PAnyType < TypedModelObject
283
288
  # an instance of PVariantType will return 'Variant'
284
289
  # @return [String] the simple name of this type
285
290
  def self.simple_name
286
- if @simple_name.nil?
291
+ @simple_name ||= (
287
292
  n = name
288
- @simple_name = n[n.rindex('::')+3..n.size-5]
289
- end
290
- @simple_name
293
+ n[n.rindex(DOUBLE_COLON)+3..n.size-5].freeze
294
+ )
291
295
  end
292
296
 
293
297
  def to_alias_expanded_s
@@ -309,8 +313,15 @@ class PAnyType < TypedModelObject
309
313
  Loaders.find_loader(nil).load(:function, 'new').call({}, self, *args)
310
314
  end
311
315
 
312
- def new_function(loader)
313
- self.class.new_function(self, loader)
316
+ # Create an instance of this type.
317
+ # The default implementation will just dispatch the call to the class method with the
318
+ # same name and pass `self` as the first argument.
319
+ #
320
+ # @return [Function] the created function
321
+ # @raises ArgumentError
322
+ #
323
+ def new_function
324
+ self.class.new_function(self)
314
325
  end
315
326
 
316
327
  # This default implementation of of a new_function raises an Argument Error.
@@ -318,10 +329,12 @@ class PAnyType < TypedModelObject
318
329
  # a Puppet Function class by using Puppet:Loaders.create_loaded_function(:new, loader)
319
330
  # and return that result.
320
331
  #
332
+ # @param type [PAnyType] the type to create a new function for
333
+ # @return [Function] the created function
321
334
  # @raises ArgumentError
322
335
  #
323
- def self.new_function(instance, loader)
324
- raise ArgumentError.new("Creation of new instance of type '#{instance.to_s}' is not supported")
336
+ def self.new_function(type)
337
+ raise ArgumentError.new("Creation of new instance of type '#{type.to_s}' is not supported")
325
338
  end
326
339
 
327
340
  # Answers the question if instances of this type can represent themselves as a string that
@@ -434,9 +447,9 @@ class PTypeWithContainedType < PAnyType
434
447
  self.class == o.class && @type == o.type
435
448
  end
436
449
 
437
- def resolve(type_parser, loader)
450
+ def resolve(loader)
438
451
  rtype = @type
439
- rtype = rtype.resolve(type_parser, loader) unless rtype.nil?
452
+ rtype = rtype.resolve(loader) unless rtype.nil?
440
453
  rtype.equal?(@type) ? self : self.class.new(rtype)
441
454
  end
442
455
  end
@@ -444,17 +457,31 @@ end
444
457
  # The type of types.
445
458
  # @api public
446
459
  #
447
- class PType < PTypeWithContainedType
460
+ class PTypeType < PTypeWithContainedType
448
461
 
449
462
  def self.register_ptype(loader, ir)
450
463
  create_ptype(loader, ir, 'AnyType',
451
464
  'type' => {
452
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
465
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
453
466
  KEY_VALUE => nil
454
467
  }
455
468
  )
456
469
  end
457
470
 
471
+ # Returns a new function that produces a Type instance
472
+ #
473
+ def self.new_function(type)
474
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_type, type.loader) do
475
+ dispatch :from_string do
476
+ param 'String', :type_string
477
+ end
478
+
479
+ def from_string(type_string)
480
+ TypeParser.singleton.parse(type_string, loader)
481
+ end
482
+ end
483
+ end
484
+
458
485
  def instance?(o, guard = nil)
459
486
  if o.is_a?(PAnyType)
460
487
  type.nil? || type.assignable?(o, guard)
@@ -496,29 +523,27 @@ class PType < PTypeWithContainedType
496
523
  self.class == o.class && @type == o.type
497
524
  end
498
525
 
499
- def self.simple_name
500
- # since this the class is inconsistently named PType and not PTypeType
501
- 'Type'
502
- end
503
-
504
- DEFAULT = PType.new(nil)
526
+ DEFAULT = PTypeType.new(nil)
505
527
 
506
528
  protected
507
529
 
508
530
  # @api private
509
531
  def _assignable?(o, guard)
510
- return false unless o.is_a?(PType)
532
+ return false unless o.is_a?(PTypeType)
511
533
  return true if @type.nil? # wide enough to handle all types
512
534
  return false if o.type.nil? # wider than t
513
535
  @type.assignable?(o.type, guard)
514
536
  end
515
537
  end
516
538
 
539
+ # For backward compatibility
540
+ PType = PTypeType
541
+
517
542
  class PNotUndefType < PTypeWithContainedType
518
543
  def self.register_ptype(loader, ir)
519
544
  create_ptype(loader, ir, 'AnyType',
520
545
  'type' => {
521
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
546
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
522
547
  KEY_VALUE => nil
523
548
  }
524
549
  )
@@ -549,12 +574,12 @@ class PNotUndefType < PTypeWithContainedType
549
574
  end
550
575
  end
551
576
 
552
- def new_function(loader)
577
+ def new_function
553
578
  # If only NotUndef, then use Unit's null converter
554
579
  if type.nil?
555
- PUnitType.new_function(self.class, loader)
580
+ PUnitType.new_function(self)
556
581
  else
557
- type.new_function(loader)
582
+ type.new_function
558
583
  end
559
584
  end
560
585
 
@@ -607,8 +632,8 @@ class PUnitType < PAnyType
607
632
  end
608
633
 
609
634
  # A "null" implementation - that simply returns the given argument
610
- def self.new_function(_, loader)
611
- @new_function ||= Puppet::Functions.create_loaded_function(:new_unit, loader) do
635
+ def self.new_function(type)
636
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_unit, type.loader) do
612
637
  dispatch :from_args do
613
638
  param 'Any', :from
614
639
  end
@@ -787,8 +812,8 @@ class PNumericType < PScalarDataType
787
812
  )
788
813
  end
789
814
 
790
- def self.new_function(_, loader)
791
- @new_function ||= Puppet::Functions.create_loaded_function(:new_numeric, loader) do
815
+ def self.new_function(type)
816
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_numeric, type.loader) do
792
817
  local_types do
793
818
  type 'Convertible = Variant[Undef, Integer, Float, Boolean, String, Timespan, Timestamp]'
794
819
  type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
@@ -997,7 +1022,7 @@ class PIntegerType < PNumericType
997
1022
  @from >= 0 ? self : PIntegerType.new(0, @to < 0 ? 0 : @to)
998
1023
  end
999
1024
 
1000
- def new_function(loader)
1025
+ def new_function
1001
1026
  @@new_function ||= Puppet::Functions.create_loaded_function(:new, loader) do
1002
1027
  local_types do
1003
1028
  type 'Radix = Variant[Default, Integer[2,2], Integer[8,8], Integer[10,10], Integer[16,16]]'
@@ -1108,8 +1133,8 @@ class PFloatType < PNumericType
1108
1133
 
1109
1134
  # Returns a new function that produces a Float value
1110
1135
  #
1111
- def self.new_function(_, loader)
1112
- @new_function ||= Puppet::Functions.create_loaded_function(:new_float, loader) do
1136
+ def self.new_function(type)
1137
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_float, type.loader) do
1113
1138
  local_types do
1114
1139
  type 'Convertible = Variant[Undef, Numeric, Boolean, String, Timespan, Timestamp]'
1115
1140
  type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
@@ -1186,7 +1211,7 @@ class PCollectionType < PAnyType
1186
1211
  def self.register_ptype(loader, ir)
1187
1212
  create_ptype(loader, ir, 'AnyType',
1188
1213
  'size_type' => {
1189
- KEY_TYPE => POptionalType.new(PType.new(PIntegerType::DEFAULT)),
1214
+ KEY_TYPE => POptionalType.new(PTypeType.new(PIntegerType::DEFAULT)),
1190
1215
  KEY_VALUE => nil
1191
1216
  }
1192
1217
  )
@@ -1278,7 +1303,7 @@ class PIterableType < PTypeWithContainedType
1278
1303
  def self.register_ptype(loader, ir)
1279
1304
  create_ptype(loader, ir, 'AnyType',
1280
1305
  'type' => {
1281
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
1306
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
1282
1307
  KEY_VALUE => nil
1283
1308
  }
1284
1309
  )
@@ -1336,7 +1361,7 @@ class PIteratorType < PTypeWithContainedType
1336
1361
  def self.register_ptype(loader, ir)
1337
1362
  create_ptype(loader, ir, 'AnyType',
1338
1363
  'type' => {
1339
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
1364
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
1340
1365
  KEY_VALUE => nil
1341
1366
  }
1342
1367
  )
@@ -1374,7 +1399,7 @@ class PStringType < PScalarDataType
1374
1399
  def self.register_ptype(loader, ir)
1375
1400
  create_ptype(loader, ir, 'ScalarDataType',
1376
1401
  'size_type_or_value' => {
1377
- KEY_TYPE => POptionalType.new(PVariantType.new([PStringType::DEFAULT, PType.new(PIntegerType::DEFAULT)])),
1402
+ KEY_TYPE => POptionalType.new(PVariantType.new([PStringType::DEFAULT, PTypeType.new(PIntegerType::DEFAULT)])),
1378
1403
  KEY_VALUE => nil
1379
1404
  })
1380
1405
  end
@@ -1446,10 +1471,6 @@ class PStringType < PScalarDataType
1446
1471
  @size_type_or_value.is_a?(PIntegerType) ? @size_type_or_value : nil
1447
1472
  end
1448
1473
 
1449
- def size_type
1450
- @size_type_or_value.is_a?(PIntegerType) ? @size_type_or_value : nil
1451
- end
1452
-
1453
1474
  def derived_size_type
1454
1475
  if @size_type_or_value.is_a?(PIntegerType)
1455
1476
  @size_type_or_value
@@ -1461,8 +1482,8 @@ class PStringType < PScalarDataType
1461
1482
  end
1462
1483
  end
1463
1484
 
1464
- def self.new_function(_, loader)
1465
- @new_function ||= Puppet::Functions.create_loaded_function(:new_string, loader) do
1485
+ def self.new_function(type)
1486
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_string, type.loader) do
1466
1487
  local_types do
1467
1488
  type 'Format = Pattern[/^%([\s\+\-#0\[\{<\(\|]*)([1-9][0-9]*)?(?:\.([0-9]+))?([a-zA-Z])/]'
1468
1489
  type 'ContainerFormat = Struct[{
@@ -1557,8 +1578,8 @@ class PRegexpType < PScalarType
1557
1578
 
1558
1579
  # Returns a new function that produces a Regexp instance
1559
1580
  #
1560
- def self.new_function(_, loader)
1561
- @new_function ||= Puppet::Functions.create_loaded_function(:new_float, loader) do
1581
+ def self.new_function(type)
1582
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_float, type.loader) do
1562
1583
  dispatch :from_string do
1563
1584
  param 'String', :pattern
1564
1585
  end
@@ -1691,8 +1712,8 @@ class PBooleanType < PScalarDataType
1691
1712
  o == true || o == false
1692
1713
  end
1693
1714
 
1694
- def self.new_function(_, loader)
1695
- @new_function ||= Puppet::Functions.create_loaded_function(:new_boolean, loader) do
1715
+ def self.new_function(type)
1716
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_boolean, type.loader) do
1696
1717
  dispatch :from_args do
1697
1718
  param 'Variant[Undef, Integer, Float, Boolean, String]', :from
1698
1719
  end
@@ -1737,8 +1758,8 @@ end
1737
1758
  class PStructElement < TypedModelObject
1738
1759
  def self.register_ptype(loader, ir)
1739
1760
  @type = Pcore::create_object_type(loader, ir, self, 'Pcore::StructElement'.freeze, nil,
1740
- 'key_type' => PType::DEFAULT,
1741
- 'value_type' => PType::DEFAULT)
1761
+ 'key_type' => PTypeType::DEFAULT,
1762
+ 'value_type' => PTypeType::DEFAULT)
1742
1763
  end
1743
1764
 
1744
1765
  attr_accessor :key_type, :value_type
@@ -1773,11 +1794,9 @@ class PStructElement < TypedModelObject
1773
1794
  @value_type.equal?(nv_type) ? self : PStructElement.new(@key_type, nv_type)
1774
1795
  end
1775
1796
 
1776
- def resolve(type_parser, loader)
1777
- rkey_type = @key_type
1778
- rkey_type = rkey_type.resolve(type_parser, loader) unless rkey_type.nil?
1779
- rvalue_type = @value_type
1780
- rvalue_type = rvalue_type.resolve(type_parser, loader) unless rvalue_type.nil?
1797
+ def resolve(loader)
1798
+ rkey_type = @key_type.resolve(loader)
1799
+ rvalue_type = @value_type.resolve(loader)
1781
1800
  rkey_type.equal?(@key_type) && rvalue_type.equal?(@value_type) ? self : self.class.new(rkey_type, rvalue_type)
1782
1801
  end
1783
1802
 
@@ -1869,10 +1888,10 @@ class PStructType < PAnyType
1869
1888
  end
1870
1889
  end
1871
1890
 
1872
- def resolve(type_parser, loader)
1891
+ def resolve(loader)
1873
1892
  changed = false
1874
1893
  relements = @elements.map do |elem|
1875
- relem = elem.resolve(type_parser, loader)
1894
+ relem = elem.resolve(loader)
1876
1895
  changed ||= !relem.equal?(elem)
1877
1896
  relem
1878
1897
  end
@@ -1904,10 +1923,10 @@ class PStructType < PAnyType
1904
1923
  end && matched == o.size
1905
1924
  end
1906
1925
 
1907
- def new_function(loader)
1926
+ def new_function
1908
1927
  # Simply delegate to Hash type and let the higher level assertion deal with
1909
1928
  # compliance with the Struct type regarding the produced result.
1910
- PHashType.new_function(self, loader)
1929
+ PHashType.new_function(self)
1911
1930
  end
1912
1931
 
1913
1932
  DEFAULT = PStructType.new(EMPTY_ARRAY)
@@ -1965,9 +1984,9 @@ class PTupleType < PAnyType
1965
1984
 
1966
1985
  def self.register_ptype(loader, ir)
1967
1986
  create_ptype(loader, ir, 'AnyType',
1968
- 'types' => PArrayType.new(PType::DEFAULT),
1987
+ 'types' => PArrayType.new(PTypeType::DEFAULT),
1969
1988
  'size_type' => {
1970
- KEY_TYPE => POptionalType.new(PType.new(PIntegerType::DEFAULT)),
1989
+ KEY_TYPE => POptionalType.new(PTypeType.new(PIntegerType::DEFAULT)),
1971
1990
  KEY_VALUE => nil
1972
1991
  }
1973
1992
  )
@@ -2050,10 +2069,10 @@ class PTupleType < PAnyType
2050
2069
  end
2051
2070
  end
2052
2071
 
2053
- def resolve(type_parser, loader)
2072
+ def resolve(loader)
2054
2073
  changed = false
2055
2074
  rtypes = @types.map do |type|
2056
- rtype = type.resolve(type_parser, loader)
2075
+ rtype = type.resolve(loader)
2057
2076
  changed ||= !rtype.equal?(type)
2058
2077
  rtype
2059
2078
  end
@@ -2115,10 +2134,10 @@ class PTupleType < PAnyType
2115
2134
  self.class == o.class && @types == o.types && @size_type == o.size_type
2116
2135
  end
2117
2136
 
2118
- def new_function(loader)
2137
+ def new_function
2119
2138
  # Simply delegate to Array type and let the higher level assertion deal with
2120
2139
  # compliance with the Tuple type regarding the produced result.
2121
- PArrayType.new_function(self, loader)
2140
+ PArrayType.new_function(self)
2122
2141
  end
2123
2142
 
2124
2143
  DEFAULT = PTupleType.new(EMPTY_ARRAY)
@@ -2172,7 +2191,7 @@ class PCallableType < PAnyType
2172
2191
  KEY_VALUE => nil
2173
2192
  },
2174
2193
  'return_type' => {
2175
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
2194
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2176
2195
  KEY_VALUE => PAnyType::DEFAULT
2177
2196
  }
2178
2197
  )
@@ -2290,10 +2309,10 @@ class PCallableType < PAnyType
2290
2309
  self.class == o.class && @param_types == o.param_types && @block_type == o.block_type && @return_type == o.return_type
2291
2310
  end
2292
2311
 
2293
- def resolve(type_parser, loader)
2294
- params_t = @param_types.nil? ? nil : @param_types.resolve(type_parser, loader)
2295
- block_t = @block_type.nil? ? nil : @block_type.resolve(type_parser, loader)
2296
- return_t = @return_type.nil? ? nil : @return_type.resolve(type_parser, loader)
2312
+ def resolve(loader)
2313
+ params_t = @param_types.nil? ? nil : @param_types.resolve(loader)
2314
+ block_t = @block_type.nil? ? nil : @block_type.resolve(loader)
2315
+ return_t = @return_type.nil? ? nil : @return_type.resolve(loader)
2297
2316
  @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : self.class.new(params_t, block_t, return_t)
2298
2317
  end
2299
2318
 
@@ -2329,7 +2348,7 @@ class PArrayType < PCollectionType
2329
2348
  def self.register_ptype(loader, ir)
2330
2349
  create_ptype(loader, ir, 'CollectionType',
2331
2350
  'element_type' => {
2332
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
2351
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2333
2352
  KEY_VALUE => PAnyType::DEFAULT
2334
2353
  }
2335
2354
  )
@@ -2385,8 +2404,8 @@ class PArrayType < PCollectionType
2385
2404
  end
2386
2405
  end
2387
2406
 
2388
- def resolve(type_parser, loader)
2389
- relement_type = @element_type.resolve(type_parser, loader)
2407
+ def resolve(loader)
2408
+ relement_type = @element_type.resolve(loader)
2390
2409
  relement_type.equal?(@element_type) ? self : self.class.new(relement_type, @size_type)
2391
2410
  end
2392
2411
 
@@ -2404,8 +2423,8 @@ class PArrayType < PCollectionType
2404
2423
 
2405
2424
  # Returns a new function that produces an Array
2406
2425
  #
2407
- def self.new_function(_, loader)
2408
- @new_function ||= Puppet::Functions.create_loaded_function(:new_array, loader) do
2426
+ def self.new_function(type)
2427
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_array, type.loader) do
2409
2428
 
2410
2429
  dispatch :from_args do
2411
2430
  param 'Any', :from
@@ -2477,11 +2496,11 @@ class PHashType < PCollectionType
2477
2496
  def self.register_ptype(loader, ir)
2478
2497
  create_ptype(loader, ir, 'CollectionType',
2479
2498
  'key_type' => {
2480
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
2499
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2481
2500
  KEY_VALUE => PAnyType::DEFAULT
2482
2501
  },
2483
2502
  'value_type' => {
2484
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
2503
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2485
2504
  KEY_VALUE => PAnyType::DEFAULT
2486
2505
  }
2487
2506
  )
@@ -2571,18 +2590,32 @@ class PHashType < PCollectionType
2571
2590
  self == EMPTY
2572
2591
  end
2573
2592
 
2574
- def resolve(type_parser, loader)
2575
- rkey_type = @key_type.resolve(type_parser, loader)
2576
- rvalue_type = @value_type.resolve(type_parser, loader)
2593
+ def resolve(loader)
2594
+ rkey_type = @key_type.resolve(loader)
2595
+ rvalue_type = @value_type.resolve(loader)
2577
2596
  rkey_type.equal?(@key_type) && rvalue_type.equal?(@value_type) ? self : self.class.new(rkey_type, rvalue_type, @size_type)
2578
2597
  end
2579
2598
 
2599
+ def self.array_as_hash(value)
2600
+ return value unless value.is_a?(Array)
2601
+ result = {}
2602
+ value.each_with_index {|v, idx| result[idx] = array_as_hash(v) }
2603
+ result
2604
+ end
2605
+
2580
2606
  # Returns a new function that produces a Hash
2581
2607
  #
2582
- def self.new_function(_, loader)
2583
- @new_function ||= Puppet::Functions.create_loaded_function(:new_hash, loader) do
2608
+ def self.new_function(type)
2609
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_hash, type.loader) do
2584
2610
  local_types do
2585
2611
  type 'KeyValueArray = Array[Tuple[Any,Any],1]'
2612
+ type 'TreeArray = Array[Tuple[Array,Any],1]'
2613
+ type 'NewHashOption = Enum[tree, hash_tree]'
2614
+ end
2615
+
2616
+ dispatch :from_tree do
2617
+ param 'TreeArray', :from
2618
+ optional_param 'NewHashOption', :build_option
2586
2619
  end
2587
2620
 
2588
2621
  dispatch :from_tuples do
@@ -2597,6 +2630,34 @@ class PHashType < PCollectionType
2597
2630
  Hash[tuple_array]
2598
2631
  end
2599
2632
 
2633
+ def from_tree(tuple_array, build_option = nil)
2634
+ if build_option.nil?
2635
+ return from_tuples(tuple_array)
2636
+ end
2637
+ # only remaining possible options is 'tree' or 'hash_tree'
2638
+
2639
+ all_hashes = build_option == 'hash_tree'
2640
+ result = {}
2641
+ tuple_array.each do |entry|
2642
+ path = entry[0]
2643
+ value = entry[1]
2644
+ if path.empty?
2645
+ # root node (index [] was included - values merge into the result)
2646
+ # An array must be changed to a hash first as this is the root
2647
+ # (Cannot return an array from a Hash.new)
2648
+ if value.is_a?(Array)
2649
+ value.each_with_index {|v, idx| result[idx] = v }
2650
+ else
2651
+ result.merge!(value)
2652
+ end
2653
+ else
2654
+ r = path[0..-2].reduce(result) {|memo, idx| (memo.is_a?(Array) || memo.has_key?(idx)) ? memo[idx] : memo[idx] = {}}
2655
+ r[path[-1]]= (all_hashes ? PHashType.array_as_hash(value) : value)
2656
+ end
2657
+ end
2658
+ result
2659
+ end
2660
+
2600
2661
  def from_array(from)
2601
2662
  case from
2602
2663
  when NilClass
@@ -2660,7 +2721,7 @@ class PVariantType < PAnyType
2660
2721
  include Enumerable
2661
2722
 
2662
2723
  def self.register_ptype(loader, ir)
2663
- create_ptype(loader, ir, 'AnyType', 'types' => PArrayType.new(PType::DEFAULT))
2724
+ create_ptype(loader, ir, 'AnyType', 'types' => PArrayType.new(PTypeType::DEFAULT))
2664
2725
  end
2665
2726
 
2666
2727
  attr_reader :types
@@ -2770,6 +2831,7 @@ class PVariantType < PAnyType
2770
2831
  def really_instance?(o, guard = nil)
2771
2832
  @types.reduce(-1) do |memo, type|
2772
2833
  ri = type.really_instance?(o, guard)
2834
+ break ri if ri > 0
2773
2835
  ri > memo ? ri : memo
2774
2836
  end
2775
2837
  end
@@ -2778,10 +2840,6 @@ class PVariantType < PAnyType
2778
2840
  @types.all? { |type| type.kind_of_callable?(optional, guard) }
2779
2841
  end
2780
2842
 
2781
- def resolved?
2782
- @types.all? { |type| type.resolved? }
2783
- end
2784
-
2785
2843
  def eql?(o)
2786
2844
  self.class == o.class && @types.size == o.types.size && (@types - o.types).empty?
2787
2845
  end
@@ -2915,7 +2973,7 @@ end
2915
2973
  # Represents a (host-) class in the Puppet Language.
2916
2974
  # @api public
2917
2975
  #
2918
- class PHostClassType < PCatalogEntryType
2976
+ class PClassType < PCatalogEntryType
2919
2977
  attr_reader :class_name
2920
2978
 
2921
2979
  def self.register_ptype(loader, ir)
@@ -2927,8 +2985,6 @@ class PHostClassType < PCatalogEntryType
2927
2985
  )
2928
2986
  end
2929
2987
 
2930
- NAME = 'Class'.freeze
2931
-
2932
2988
  def initialize(class_name)
2933
2989
  @class_name = class_name
2934
2990
  end
@@ -2940,17 +2996,13 @@ class PHostClassType < PCatalogEntryType
2940
2996
  self.class == o.class && @class_name == o.class_name
2941
2997
  end
2942
2998
 
2943
- def self.simple_name
2944
- NAME
2945
- end
2946
-
2947
- DEFAULT = PHostClassType.new(nil)
2999
+ DEFAULT = PClassType.new(nil)
2948
3000
 
2949
3001
  protected
2950
3002
 
2951
3003
  # @api private
2952
3004
  def _assignable?(o, guard)
2953
- return false unless o.is_a?(PHostClassType)
3005
+ return false unless o.is_a?(PClassType)
2954
3006
  # Class = Class[name}, Class[name] != Class
2955
3007
  return true if @class_name.nil?
2956
3008
  # Class[name] = Class[name]
@@ -2958,6 +3010,10 @@ class PHostClassType < PCatalogEntryType
2958
3010
  end
2959
3011
  end
2960
3012
 
3013
+ # For backward compatibility
3014
+ PHostClassType = PClassType
3015
+
3016
+
2961
3017
  # Represents a Resource Type in the Puppet Language
2962
3018
  # @api public
2963
3019
  #
@@ -3011,7 +3067,7 @@ class POptionalType < PTypeWithContainedType
3011
3067
  def self.register_ptype(loader, ir)
3012
3068
  create_ptype(loader, ir, 'AnyType',
3013
3069
  'type' => {
3014
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
3070
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
3015
3071
  KEY_VALUE => nil
3016
3072
  }
3017
3073
  )
@@ -3046,8 +3102,8 @@ class POptionalType < PTypeWithContainedType
3046
3102
  end
3047
3103
  end
3048
3104
 
3049
- def new_function(loader)
3050
- optional_type.new_function(loader)
3105
+ def new_function
3106
+ optional_type.new_function
3051
3107
  end
3052
3108
 
3053
3109
  DEFAULT = POptionalType.new(nil)
@@ -3094,8 +3150,8 @@ class PTypeReferenceType < PAnyType
3094
3150
  super && o.type_string == @type_string
3095
3151
  end
3096
3152
 
3097
- def resolve(type_parser, loader)
3098
- type_parser.parse(@type_string, loader)
3153
+ def resolve(loader)
3154
+ TypeParser.singleton.parse(@type_string, loader)
3099
3155
  end
3100
3156
 
3101
3157
  protected
@@ -3122,13 +3178,13 @@ class PTypeAliasType < PAnyType
3122
3178
  'name' => PStringType::NON_EMPTY,
3123
3179
  'type_expr' => PAnyType::DEFAULT,
3124
3180
  'resolved_type' => {
3125
- KEY_TYPE => POptionalType.new(PType::DEFAULT),
3181
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
3126
3182
  KEY_VALUE => nil
3127
3183
  }
3128
3184
  )
3129
3185
  end
3130
3186
 
3131
- attr_reader :name
3187
+ attr_reader :loader, :name
3132
3188
 
3133
3189
  # @param name [String] The name of the type
3134
3190
  # @param type_expr [Model::PopsObject] The expression that describes the aliased type
@@ -3233,16 +3289,17 @@ class PTypeAliasType < PAnyType
3233
3289
  # @param loader [Loader::Loader] loader to use when loading type aliases
3234
3290
  # @return [PTypeAliasType] the receiver of the call, i.e. `self`
3235
3291
  # @api private
3236
- def resolve(type_parser, loader)
3292
+ def resolve(loader)
3293
+ @loader = loader
3237
3294
  if @resolved_type.nil?
3238
3295
  # resolved to PTypeReferenceType::DEFAULT during resolve to avoid endless recursion
3239
3296
  @resolved_type = PTypeReferenceType::DEFAULT
3240
3297
  @self_recursion = true # assumed while it being found out below
3241
3298
  begin
3242
3299
  if @type_expr.is_a?(PTypeReferenceType)
3243
- @resolved_type = @type_expr.resolve(type_parser, loader)
3300
+ @resolved_type = @type_expr.resolve(loader)
3244
3301
  else
3245
- @resolved_type = type_parser.interpret(@type_expr, loader).normalize
3302
+ @resolved_type = TypeParser.singleton.interpret(@type_expr, loader).normalize
3246
3303
  end
3247
3304
 
3248
3305
  # Find out if this type is recursive. A recursive type has performance implications
@@ -3267,7 +3324,7 @@ class PTypeAliasType < PAnyType
3267
3324
  else
3268
3325
  # An alias may appoint an Object type that isn't resolved yet. The default type
3269
3326
  # reference is used to prevent endless recursion and should not be resolved here.
3270
- @resolved_type.resolve(type_parser, loader) unless @resolved_type.equal?(PTypeReferenceType::DEFAULT)
3327
+ @resolved_type.resolve(loader) unless @resolved_type.equal?(PTypeReferenceType::DEFAULT)
3271
3328
  end
3272
3329
  self
3273
3330
  end
@@ -3330,8 +3387,8 @@ class PTypeAliasType < PAnyType
3330
3387
  resolved_type.assignable?(o, guard)
3331
3388
  end
3332
3389
 
3333
- def new_function(loader)
3334
- resolved_type.new_function(loader)
3390
+ def new_function
3391
+ resolved_type.new_function
3335
3392
  end
3336
3393
 
3337
3394
  private
@@ -3390,5 +3447,7 @@ require_relative 'p_type_set_type'
3390
3447
  require_relative 'p_timespan_type'
3391
3448
  require_relative 'p_timestamp_type'
3392
3449
  require_relative 'p_binary_type'
3450
+ require_relative 'p_init_type'
3393
3451
  require_relative 'type_set_reference'
3394
3452
  require_relative 'implementation_registry'
3453
+ require_relative 'tree_iterators'