mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 12:14:43 +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
|
@ -2395,7 +2395,7 @@ pub struct TypeAscription {
|
||||||
|
|
||||||
impl NestedDisplay for TypeAscription {
|
impl NestedDisplay for TypeAscription {
|
||||||
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
|
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
|
||||||
writeln!(f, "{}{}", self.expr, self.spec)
|
writeln!(f, "{} {}", self.expr, self.spec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3991,7 +3991,7 @@ pub struct TypeAscription {
|
||||||
|
|
||||||
impl NestedDisplay for TypeAscription {
|
impl NestedDisplay for TypeAscription {
|
||||||
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
|
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);
|
debug_exit_info!(self);
|
||||||
Ok(sig)
|
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 => {
|
other => {
|
||||||
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
|
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
|
||||||
self.errs.push(err);
|
self.errs.push(err);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue