@@ -1245,7 +1245,7 @@ impl Record {
1245
1245
let has_variable_label = |r : & Record | {
1246
1246
r. fields ( ) . any ( |prop| match prop. k {
1247
1247
RecordLabel :: Variable ( v) => unifier. sub . try_apply ( v) . is_none ( ) ,
1248
- RecordLabel :: Concrete ( _) => false ,
1248
+ RecordLabel :: BoundVariable ( _ ) | RecordLabel :: Concrete ( _) => false ,
1249
1249
} )
1250
1250
} ;
1251
1251
if has_variable_label ( self ) || has_variable_label ( actual) {
@@ -1339,7 +1339,9 @@ impl Record {
1339
1339
} ,
1340
1340
tail : MonoType :: Var ( var) ,
1341
1341
} ) ;
1342
+ log:: error!( "{} = {}" , l, act) ;
1342
1343
l. unify ( & act, unifier) ;
1344
+ log:: error!( "{} = {}" , exp, r) ;
1343
1345
exp. unify ( r, unifier) ;
1344
1346
}
1345
1347
// If we are expecting {a: u | r} but find {}, label `a` is missing.
@@ -1450,22 +1452,39 @@ fn unify_in_context<T>(
1450
1452
}
1451
1453
1452
1454
/// Labels in records that are allowed be variables
1453
- #[ derive( Debug , Eq , PartialEq , Ord , PartialOrd , Hash , Clone , Serialize , derive_more :: From ) ]
1455
+ #[ derive( Debug , Eq , PartialEq , Ord , PartialOrd , Hash , Clone , Serialize ) ]
1454
1456
pub enum RecordLabel {
1455
1457
/// A variable label
1456
1458
Variable ( Tvar ) ,
1459
+ /// A variable label
1460
+ BoundVariable ( Tvar ) ,
1457
1461
/// A concrete label
1458
1462
Concrete ( Label ) ,
1459
1463
}
1460
1464
1465
+ impl From < Label > for RecordLabel {
1466
+ fn from ( label : Label ) -> Self {
1467
+ Self :: Concrete ( label)
1468
+ }
1469
+ }
1470
+
1461
1471
impl Substitutable for RecordLabel {
1462
1472
fn walk ( & self , sub : & dyn Substituter ) -> Option < Self > {
1463
1473
match self {
1464
1474
Self :: Variable ( tvr) => sub. try_apply ( * tvr) . and_then ( |new| match new {
1465
1475
MonoType :: Label ( l) => Some ( Self :: Concrete ( l) ) ,
1476
+ MonoType :: BoundVar ( l) => Some ( Self :: BoundVariable ( l) ) ,
1466
1477
MonoType :: Var ( l) => Some ( Self :: Variable ( l) ) ,
1467
1478
_ => None ,
1468
1479
} ) ,
1480
+
1481
+ Self :: BoundVariable ( tvr) => sub. try_apply_bound ( * tvr) . and_then ( |new| match new {
1482
+ MonoType :: Label ( l) => Some ( Self :: Concrete ( l) ) ,
1483
+ MonoType :: BoundVar ( l) => Some ( Self :: BoundVariable ( l) ) ,
1484
+ MonoType :: Var ( l) => Some ( Self :: Variable ( l) ) ,
1485
+ _ => None ,
1486
+ } ) ,
1487
+
1469
1488
Self :: Concrete ( _) => None ,
1470
1489
}
1471
1490
}
@@ -1474,7 +1493,8 @@ impl Substitutable for RecordLabel {
1474
1493
impl fmt:: Display for RecordLabel {
1475
1494
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1476
1495
match self {
1477
- Self :: Variable ( v) => v. fmt ( f) ,
1496
+ Self :: BoundVariable ( v) => v. fmt ( f) ,
1497
+ Self :: Variable ( v) => write ! ( f, "#{}" , v) ,
1478
1498
Self :: Concrete ( v) => v. fmt ( f) ,
1479
1499
}
1480
1500
}
@@ -1483,7 +1503,7 @@ impl fmt::Display for RecordLabel {
1483
1503
impl PartialEq < str > for RecordLabel {
1484
1504
fn eq ( & self , other : & str ) -> bool {
1485
1505
match self {
1486
- Self :: Variable ( _) => false ,
1506
+ Self :: BoundVariable ( _ ) | Self :: Variable ( _) => false ,
1487
1507
Self :: Concrete ( l) => l == other,
1488
1508
}
1489
1509
}
@@ -1630,10 +1650,8 @@ where
1630
1650
V : Substitutable + Clone ,
1631
1651
{
1632
1652
fn walk ( & self , sub : & dyn Substituter ) -> Option < Self > {
1633
- self . v . visit ( sub) . map ( |v| Property {
1634
- k : self . k . clone ( ) ,
1635
- v,
1636
- } )
1653
+ let Self { k, v } = self ;
1654
+ apply2 ( k, v, sub) . map ( |( k, v) | Property { k, v } )
1637
1655
}
1638
1656
}
1639
1657
0 commit comments