Commits

Michael Tindal committed f86dc9f

Fix bug in valueForUndefinedKey, update module handling and fix bug in submodule resolution.

  • Participants
  • Parent commits 3713300

Comments (0)

Files changed (5)

Classes/Types/SVCategory.m

 #import "SVVariable.h"
 #import "NSMutableDictionary+SVExtensions.h"
 #import "SVIncludeStatement.h"
+#import "SVModule.h"
 #import <objc/runtime.h>
 
 @interface SVFunction (SVClassExtension)
     for (id content in self.contents) {
         if([content isKindOfClass:[SVIncludeStatement class]]) {
             id res = [content evaluateWithContext:context];
-            if([res respondsToSelector:@selector(contents)]) {
+            if([res isKindOfClass:[SVModule class]]) {
                 [contents addObjectsFromArray:[res contents]];
             } else {
                 [contents addObject:res];

Classes/Types/SVClass.m

 #import "SVVariable.h"
 #import "SVClassWrapper.h"
 #import "SVIncludeStatement.h"
+#import "SVModule.h"
 #import <objc/runtime.h>
 
 NSMutableDictionary * sv_block_table;
     for (id content in self.contents) {
         if([content isKindOfClass:[SVIncludeStatement class]]) {
             id res = [content evaluateWithContext:context];
-            if([res respondsToSelector:@selector(contents)]) {
+            if([res isKindOfClass:[SVModule class]]) {
                 [contents addObjectsFromArray:[res contents]];
             } else {
                 [contents addObject:res];

Classes/Types/SVModule.m

 }
 
 -(id) evaluateWithContext:(NSMutableDictionary *)context {
-    id res = [self.owner evaluateWithContext:context];
-    if(![res isKindOfClass:[SVModule class]])
+    id o;
+    if([self.owner isKindOfClass:[NSString class]])
+        o = [SVVariable variableWithName:self.owner];
+    else
+        o = self.owner;
+    id res = [o evaluateWithContext:context];
+    if(![res isKindOfClass:[SVModule class]]) {
+        NSLog(@"Not module, res: %@ (type: %@), submodule: %@", res, NSStringFromClass([res class]), self.submodule);
         return nil;
+    }
     return [((SVModule *)res).mappedContents objectForKey:self.submodule];
 }
 

Tests/SVClassSystemTests.m

     
     assertThat(var,is(equalTo(N(20))));
 }
+
+-(void) testSubModule1 {
+    PC(@"module TestModule2 { class ModuleClass2 { def testFunc(x) { return x*5; }; }; class ModuleClass3 { def testFunc2(x) { return x/5; }; }; }; class ModuleTestClass2 { include TestModule2->ModuleClass2; def init { @x = ModuleClass2.alloc.init.testFunc(5); @y = 0; begin { @y = ModuleClass3.alloc.init; } rescue NSException => ex { @y = 10; }; self; }; }; x = ModuleTestClass2.alloc.init; [x.x,x.y];");
+    P(var);
+    assertThat(var,is(equalTo([NSArray arrayWithObjects:N(25),N(10),nil])));
+}
 @end
     };
     
     def valueForUndefinedKey(key) {
-        eval('@#{key}');
+        eval('@#{key};');
     };
 };