better cast errors
This commit is contained in:
parent
d5bcd53335
commit
f0106d7f0b
@ -5,17 +5,34 @@ struct CastResolver<'a, Ctx: 'a + Context> {
|
||||
points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>,
|
||||
}
|
||||
|
||||
pub enum CastError<'a> {
|
||||
Typeless(TypelessError<'a>),
|
||||
AddressIndexOutOfBounds(usize),
|
||||
AddressPointMismatch {
|
||||
expected: Hash,
|
||||
received: Hash,
|
||||
index: usize,
|
||||
},
|
||||
}
|
||||
|
||||
impl<'a, Ctx: 'a + Context> Resolver<'a, Ctx> for CastResolver<'a, Ctx>
|
||||
where
|
||||
Ctx::LookupError: From<TypelessError<'a>>,
|
||||
Ctx::LookupError: From<CastError<'a>>,
|
||||
{
|
||||
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx> {
|
||||
let point = &self
|
||||
.points
|
||||
.get(address.index)
|
||||
.expect("CastResolved received an invalid address.");
|
||||
let point = match self.points.get(address.index) {
|
||||
Some(point) => point,
|
||||
None => {
|
||||
return Ctx::T::pure(Err(CastError::AddressIndexOutOfBounds(address.index).into()));
|
||||
}
|
||||
};
|
||||
if point.point != address.point {
|
||||
panic!("CastResolved received an invalid address.")
|
||||
return Ctx::T::pure(Err(CastError::AddressPointMismatch {
|
||||
expected: point.point,
|
||||
received: address.point,
|
||||
index: address.index,
|
||||
}
|
||||
.into()));
|
||||
}
|
||||
Ctx::T::fmap(
|
||||
|resolved| match resolved {
|
||||
@ -29,7 +46,7 @@ where
|
||||
}
|
||||
Err(error) => Err(match error {
|
||||
ResolutionError::Lookup(lookup_error) => lookup_error,
|
||||
ResolutionError::Parse(parse_error) => parse_error.into(),
|
||||
ResolutionError::Parse(parse_error) => CastError::Typeless(parse_error).into(),
|
||||
}),
|
||||
},
|
||||
point.resolve(),
|
||||
@ -41,7 +58,7 @@ pub type CastResult<'a, Ctx, A> =
|
||||
Result<A, <<A as Mentionable<'a, Ctx>>::Fctr as Factory<'a, Ctx>>::ParseError>;
|
||||
impl<'a, Ctx: Context> TypelessMentionable<'a, Ctx>
|
||||
where
|
||||
Ctx::LookupError: From<TypelessError<'a>>,
|
||||
Ctx::LookupError: From<CastError<'a>>,
|
||||
{
|
||||
/// .
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user