mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
fix: type-spec parsing bugs
This commit is contained in:
parent
c84294fc11
commit
456201fb49
3 changed files with 20 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue