From a7935db10746a5216f04be5672f8d823fd7bcde4 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 30 Dec 2016 19:17:59 +0200 Subject: [PATCH] cleaner way to generate argument types possibly more correct --- lib/typed/parfait/named_list.rb | 6 +++++- lib/typed/parfait/type.rb | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/typed/parfait/named_list.rb b/lib/typed/parfait/named_list.rb index e11a430f..431b331e 100644 --- a/lib/typed/parfait/named_list.rb +++ b/lib/typed/parfait/named_list.rb @@ -11,7 +11,7 @@ # PS: it turns out that both messages and named_lists are created at compile, not run-time, and # just constantly reused. Each message has two named_list object ready and is also linked # to the next message. -# The better way to say above is that a message is *used* by the caller, and a named_list +# The better way to say above is that a message is *used* by the caller, and a named_list # by the callee. # Also at runtime Messages and NamedLists remain completely "normal" objects. @@ -23,5 +23,9 @@ module Parfait class NamedList < Object + def self.type_for( arguments ) + my_class = Parfait.object_space.classes[:NamedList] + Parfait::Type.for_hash( my_class , arguments.merge(type: my_class.instance_type)) + end end end diff --git a/lib/typed/parfait/type.rb b/lib/typed/parfait/type.rb index a269f443..2f8e5d09 100644 --- a/lib/typed/parfait/type.rb +++ b/lib/typed/parfait/type.rb @@ -40,7 +40,7 @@ module Parfait attr_reader :object_class , :names , :types , :methods def self.for_hash( object_class , hash) - hash[:type] = :Type unless hash[:type] + hash = {type: object_class.name }.merge(hash) unless hash[:type] new_type = Type.new( object_class , hash) code = hash_code_for_hash( hash ) Parfait.object_space.types[code] = new_type @@ -105,9 +105,9 @@ module Parfait def create_method( method_name , arguments ) raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol) #puts "Self: #{self.class} clazz: #{clazz.name}" - type = arguments - type = Parfait::Type.for_hash( @object_class , arguments) if arguments.is_a?(Hash) - add_method TypedMethod.new( self , method_name , type ) + arg_type = arguments + arg_type = NamedList.type_for( arguments ) if arguments.is_a?(Hash) + add_method TypedMethod.new( self , method_name , arg_type ) end def add_method( method )