fix redefining typed methods

as happens for predefined Space.main
This commit is contained in:
Torsten Ruger 2018-03-22 21:06:22 +05:30
parent 02c12996b3
commit 769fd71a3d
2 changed files with 15 additions and 10 deletions

View File

@ -77,16 +77,17 @@ module Parfait
def create_method( method_name , arguments , frame)
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
#puts "Self: #{self.class} clazz: #{clazz.name}"
found = get_method( method_name )
#TODO check types and then what ?
return found if found
if arguments.is_a?(Hash)
raise "May want to get rid of this way"
arguments = NamedList.type_for( arguments )
end
raise "frame must be a type, not:#{frame}" unless frame.is_a?(Type)
found = get_method( method_name )
if found
puts "redefining method #{method_name}" #TODO, this surely must get more complicated
raise "attempt to redifine method for different type " unless self == found.for_type
found.init(arguments , frame)
return found
else
add_method TypedMethod.new( self , method_name , arguments , frame )
end
end
def add_method( method )
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? TypedMethod

View File

@ -30,10 +30,14 @@ module Parfait
super()
raise "No class #{name}" unless type
raise "For type, not class #{type}" unless type.is_a?(Type)
raise "Wrong argument type, expect Type not #{arguments.class}" unless arguments.is_a? Type
raise "Wrong frame type, expect Type not #{frame.class}" unless frame.is_a? Type
@for_type = type
@name = name
init(arguments, frame)
end
def init(arguments, frame)
raise "Wrong argument type, expect Type not #{arguments.class}" unless arguments.is_a? Type
raise "Wrong frame type, expect Type not #{frame.class}" unless frame.is_a? Type
@binary = BinaryCode.new 0
@arguments = arguments
@frame = frame