fix: type-spec parsing bugs

This commit is contained in:
Shunsuke Shibayama 2023-05-02 22:46:37 +09:00
parent c84294fc11
commit 456201fb49
3 changed files with 20 additions and 2 deletions

View file

@ -3991,7 +3991,7 @@ pub struct TypeAscription {
impl NestedDisplay for TypeAscription {
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
writeln!(f, "{}{}", self.expr, self.t_spec)
writeln!(f, "{} {}", self.expr, self.t_spec)
}
}

View file

@ -693,6 +693,24 @@ impl Parser {
debug_exit_info!(self);
Ok(sig)
}
Expr::BinOp(bin) => match bin.op.kind {
TokenKind::OrOp | TokenKind::AndOp => {
let pat = ParamPattern::Discard(bin.op.clone());
let expr = Expr::BinOp(bin);
let t_spec = Self::expr_to_type_spec(expr.clone())
.map_err(|_| self.stack_dec(fn_name!()))?;
let t_spec = TypeSpecWithOp::new(Token::DUMMY, t_spec, expr);
let param = NonDefaultParamSignature::new(pat, Some(t_spec));
let params = Params::single(param);
Ok(LambdaSignature::new(params, None, TypeBoundSpecs::empty()))
}
_ => {
let err = ParseError::simple_syntax_error(line!() as usize, bin.loc());
self.errs.push(err);
debug_exit_info!(self);
Err(())
}
},
other => {
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
self.errs.push(err);