From 1d0657c5449e29e118f4857a63712d0886bbbc54 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Thu, 1 Jun 2023 19:36:25 +0900 Subject: [PATCH] fix: overload subtyping --- crates/erg_compiler/context/compare.rs | 2 ++ crates/erg_compiler/declare.rs | 13 ++++++++++++- crates/erg_compiler/ty/mod.rs | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/erg_compiler/context/compare.rs b/crates/erg_compiler/context/compare.rs index dd66667b..05d925be 100644 --- a/crates/erg_compiler/context/compare.rs +++ b/crates/erg_compiler/context/compare.rs @@ -1255,6 +1255,8 @@ impl Context { }, (_, Not(r)) => self.diff(lhs, r), (Not(l), _) => self.diff(rhs, l), + // overloading + (l, r) if l.is_subr() && r.is_subr() => and(lhs.clone(), rhs.clone()), _ => self.simple_intersection(lhs, rhs), } } diff --git a/crates/erg_compiler/declare.rs b/crates/erg_compiler/declare.rs index 34f6a7a1..8908352e 100644 --- a/crates/erg_compiler/declare.rs +++ b/crates/erg_compiler/declare.rs @@ -49,7 +49,18 @@ impl ASTLowerer { _ => sig.inspect().cloned(), }; let found_body_t = chunk.ref_t(); - let ast::VarPattern::Ident(ident) = &sig.pat else { unreachable!() }; + let ident = match &sig.pat { + ast::VarPattern::Ident(ident) => ident, + ast::VarPattern::Discard(token) => { + return Err(LowerErrors::from(LowerError::declare_error( + self.cfg().input.clone(), + line!() as usize, + token.loc(), + self.module.context.caused_by(), + ))); + } + _ => unreachable!(), + }; let id = body.id; if let Some(spec_t) = opt_spec_t { self.module diff --git a/crates/erg_compiler/ty/mod.rs b/crates/erg_compiler/ty/mod.rs index fc12f88c..0900abe5 100644 --- a/crates/erg_compiler/ty/mod.rs +++ b/crates/erg_compiler/ty/mod.rs @@ -1814,6 +1814,7 @@ impl Type { Self::Subr(_) => true, Self::Quantified(quant) => quant.is_subr(), Self::Refinement(refine) => refine.t.is_subr(), + Self::And(l, r) => l.is_subr() && r.is_subr(), _ => false, } } @@ -1823,6 +1824,7 @@ impl Type { Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_quantified_subr(), Self::Quantified(_) => true, Self::Refinement(refine) => refine.t.is_quantified_subr(), + Self::And(l, r) => l.is_quantified_subr() && r.is_quantified_subr(), _ => false, } }