From e82c86f6c14cc798760a62979ef6d88d1f8f6c7b Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 10 Dec 2016 22:41:49 +0200 Subject: [PATCH] fix class def tests and code --- lib/typed/compiler/class_field.rb | 3 +- test/typed/statements/test_class.rb | 69 +++++++++++++++-------------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/lib/typed/compiler/class_field.rb b/lib/typed/compiler/class_field.rb index c2926325..0cdbf4e2 100644 --- a/lib/typed/compiler/class_field.rb +++ b/lib/typed/compiler/class_field.rb @@ -9,7 +9,8 @@ module Typed index = for_class.instance_type.variable_index(statement.name) raise "class field already defined:#{name} for class #{for_class.name}" if index - for_class.instance_type.add_instance_variable( statement.name , statement.type ) + #FIXME should not hack into current type, but create a new + for_class.instance_type.send(:private_add_instance_variable, statement.name , statement.type) return nil # statements don't reurn values, only expressions end diff --git a/test/typed/statements/test_class.rb b/test/typed/statements/test_class.rb index 0bbd6eb4..d53d30ad 100644 --- a/test/typed/statements/test_class.rb +++ b/test/typed/statements/test_class.rb @@ -1,39 +1,40 @@ require_relative 'helper' module Register -class TestClassStatements #< MiniTest::Test +class TestClassStatements < MiniTest::Test include Statements + def class_def + clean_compile s(:statements, + s(:class, :Bar, + s(:derives, nil), + s(:statements, + s(:function, :Integer, + s(:name, :buh), + s(:parameters), + s(:statements, + s(:return, + s(:int, 1))), + s(:receiver, :self))))) + end + def test_class_defs - @input = <