You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnfoo(v:Value){let ty = Ty::of_value(v);let ident = ty.to_string();
...}
And the motivation is that I am building a configuration system where I allow users to define new record types. But the issue comes when user in one file makes Foo = record() and another file makes Foo = record(). These are distinct types because they were defined in two separate files.
But the ty.to_string() in the above collides.
is there currently a way I can disambiguate these two?
if not, would you be open to a PR that allows inspecting the module id where the user type was defined, which should allow disambiguation.
The text was updated successfully, but these errors were encountered:
The Ty you get back has both a name (which isn't sufficient to disambiguate them), but also a type matcher which can be applied to a Value to figure out if it matches. I think you need to use that type matcher. Unfortunately, I can't find anywhere it is exposed. Maybe @stepancheg knows where?
I ran into this as well. I would have preferred an approach based on a hash table, but was able to get something to work using a linear search by adapting the code used to implement the starlark isinstance function. Some demo code:
fn at(&self, index: Value<'v>, heap: &'v Heap) -> starlark::Result<Value<'v>> {
let matcher = TypeCompiled::new(index, heap)?;
for item in &self.items {
if matcher.matches(item.to_value()) {
return Ok(item.to_value());
}
}
Err(starlark::Error::new_value(anyhow::Error::msg(
"No matching type found",
)))
}
I have some code like:
And the motivation is that I am building a configuration system where I allow users to define new
record
types. But the issue comes when user in one file makesFoo = record()
and another file makesFoo = record()
. These are distinct types because they were defined in two separate files.But the
ty.to_string()
in the above collides.The text was updated successfully, but these errors were encountered: