[meta] Make Typevar::type_set private, and add a second getter to read it directly;
There might be a silent bug in the Python module which directly reads from this type_set field; in particular, it does so when reading all controlling type variables, which all seem to be free variables (i.e. no parent typevar). So imitate this behavior here, until we're sure there are no other meta generators that rely on this.
This commit is contained in:
@@ -25,7 +25,9 @@ pub struct TypeVarContent {
|
||||
pub doc: String,
|
||||
|
||||
/// Type set associated to the type variable.
|
||||
pub type_set: Rc<TypeSet>,
|
||||
/// This field must remain private; use `get_typeset()` or `get_raw_typeset()` to get the
|
||||
/// information you want.
|
||||
type_set: Rc<TypeSet>,
|
||||
|
||||
pub base: Option<TypeVarParent>,
|
||||
}
|
||||
@@ -84,13 +86,22 @@ impl TypeVar {
|
||||
TypeVar::new(name, doc, builder.finish())
|
||||
}
|
||||
|
||||
/// Returns this typevar's type set, maybe computing it from the parent.
|
||||
fn get_typeset(&self) -> Rc<TypeSet> {
|
||||
// TODO Can this be done in a non-lazy way in derived() and we can remove this function and
|
||||
// the one below?
|
||||
match &self.content.base {
|
||||
Some(base) => Rc::new(base.type_var.get_typeset().image(base.derived_func)),
|
||||
None => self.content.type_set.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns this typevar's type set, assuming this type var has no parent.
|
||||
pub fn get_raw_typeset(&self) -> &TypeSet {
|
||||
assert_eq!(self.content.type_set, self.get_typeset());
|
||||
&*self.content.type_set
|
||||
}
|
||||
|
||||
/// If the associated typeset has a single type return it. Otherwise return None.
|
||||
pub fn singleton_type(&self) -> Option<ValueType> {
|
||||
let type_set = self.get_typeset();
|
||||
|
||||
Reference in New Issue
Block a user