@@ -334,8 +334,15 @@ impl <'a> TypeEnvironment<'a> {
334
334
}
335
335
let data_definitions = module. dataDefinitions . clone ( ) ;
336
336
for instance in module. instances . mut_iter ( ) {
337
- let class = module. classes . iter ( ) . find ( |class| class. name == instance. classname )
338
- . expect ( format ! ( "Could not find class {}" , instance. classname) ) ;
337
+ let ( class_constraints, class_var, class_decls) = module. classes . iter ( )
338
+ . find ( |class| class. name == instance. classname )
339
+ . map ( |class| ( class. constraints . as_slice ( ) , & class. variable , class. declarations . as_slice ( ) ) )
340
+ . or_else ( || {
341
+ self . assemblies . iter ( )
342
+ . filter_map ( |a| a. find_class ( instance. classname ) )
343
+ . next ( )
344
+ } )
345
+ . unwrap_or_else ( || fail ! ( "Could not find class {}" , instance. classname) ) ;
339
346
//Update the kind of the type for the instance to be the same as the class kind (since we have no proper kind inference
340
347
match instance. typ {
341
348
TypeConstructor ( ref mut op) => {
@@ -349,10 +356,10 @@ impl <'a> TypeEnvironment<'a> {
349
356
_ => ( )
350
357
}
351
358
for binding in instance. bindings . mut_iter ( ) {
352
- let decl = class . declarations . iter ( ) . find ( |decl| binding. name . as_slice ( ) . ends_with ( decl. name . as_slice ( ) ) )
353
- . expect ( format ! ( "Could not find {} in class {}" , binding. name, class . name ) ) ;
359
+ let decl = class_decls . iter ( ) . find ( |decl| binding. name . as_slice ( ) . ends_with ( decl. name . as_slice ( ) ) )
360
+ . expect ( format ! ( "Could not find {} in class {}" , binding. name, instance . classname ) ) ;
354
361
binding. typ = decl. typ . clone ( ) ;
355
- replace_var ( & mut binding. typ . value , & class . variable , & instance. typ ) ;
362
+ replace_var ( & mut binding. typ . value , class_var , & instance. typ ) ;
356
363
self . freshen_qualified_type ( & mut binding. typ , HashMap :: new ( ) ) ;
357
364
{
358
365
let mut context = ~[ ] ;
@@ -365,8 +372,8 @@ impl <'a> TypeEnvironment<'a> {
365
372
}
366
373
}
367
374
{
368
- let mut missing_super_classes = self . find_class_constraints ( class . name )
369
- . unwrap_or_else ( || fail ! ( "Error: Missing class {}" , class . name ) )
375
+ let mut missing_super_classes = self . find_class_constraints ( instance . classname )
376
+ . unwrap_or_else ( || fail ! ( "Error: Missing class {}" , instance . classname ) )
370
377
. iter ( ) //Make sure we have an instance for all of the constraints
371
378
. filter ( |constraint| self . has_instance ( constraint. class , & instance. typ , & mut Vec :: new ( ) ) . is_err ( ) )
372
379
. peekable ( ) ;
@@ -1595,9 +1602,12 @@ fn typecheck_modules_common(modules: Vec<Module>) -> Vec<Module<Name>> {
1595
1602
for module in modules. mut_iter ( ) {
1596
1603
prec_visitor. visit_module ( module) ;
1597
1604
}
1598
- let mut env = TypeEnvironment :: new ( ) ;
1599
- for module in modules. mut_iter ( ) {
1600
- env. typecheck_module ( module) ;
1605
+ {
1606
+ let mut env = TypeEnvironment :: new ( ) ;
1607
+ for module in modules. mut_iter ( ) {
1608
+ env. typecheck_module ( module) ;
1609
+ env. assemblies . push ( module) ;
1610
+ }
1601
1611
}
1602
1612
modules
1603
1613
}
0 commit comments