mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 21:21:10 +00:00
fix: occur check bug
This commit is contained in:
parent
359329e593
commit
2e8810f10d
4 changed files with 18 additions and 3 deletions
|
@ -113,7 +113,7 @@ impl<'c, 'l, L: Locational> Unifier<'c, 'l, L> {
|
||||||
self.occur(&lhs.return_t, &rhs.return_t)?;
|
self.occur(&lhs.return_t, &rhs.return_t)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
(Poly { params, .. }, FreeVar(fv)) if fv.is_unbound() => {
|
/*(Poly { params, .. }, FreeVar(fv)) if fv.is_unbound() => {
|
||||||
for param in params.iter().filter_map(|tp| {
|
for param in params.iter().filter_map(|tp| {
|
||||||
if let TyParam::Type(t) = tp {
|
if let TyParam::Type(t) = tp {
|
||||||
Some(t)
|
Some(t)
|
||||||
|
@ -124,7 +124,7 @@ impl<'c, 'l, L: Locational> Unifier<'c, 'l, L> {
|
||||||
self.occur_inner(param, maybe_sup)?;
|
self.occur_inner(param, maybe_sup)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}*/
|
||||||
(FreeVar(fv), Poly { params, .. }) if fv.is_unbound() => {
|
(FreeVar(fv), Poly { params, .. }) if fv.is_unbound() => {
|
||||||
for param in params.iter().filter_map(|tp| {
|
for param in params.iter().filter_map(|tp| {
|
||||||
if let TyParam::Type(t) = tp {
|
if let TyParam::Type(t) = tp {
|
||||||
|
|
|
@ -15,3 +15,11 @@ norm x = x.norm()
|
||||||
a = [1, 2] + [3, 4]
|
a = [1, 2] + [3, 4]
|
||||||
|
|
||||||
abc = ["c"] + ["a", "b"][1..1000]
|
abc = ["c"] + ["a", "b"][1..1000]
|
||||||
|
|
||||||
|
f! t =
|
||||||
|
arr = ![]
|
||||||
|
result = ![]
|
||||||
|
result.push! t
|
||||||
|
for! arr, t =>
|
||||||
|
result.extend! f! t
|
||||||
|
result
|
||||||
|
|
|
@ -11,7 +11,7 @@ use erg_compiler::lower::ASTLowerer;
|
||||||
|
|
||||||
use erg_compiler::ty::constructors::{
|
use erg_compiler::ty::constructors::{
|
||||||
array_t, func0, func1, func2, kw, mono, nd_func, nd_proc, or, poly, proc1, subtype_q, ty_tp,
|
array_t, func0, func1, func2, kw, mono, nd_func, nd_proc, or, poly, proc1, subtype_q, ty_tp,
|
||||||
type_q, unknown_len_array_t, v_enum,
|
type_q, unknown_len_array_mut, unknown_len_array_t, v_enum,
|
||||||
};
|
};
|
||||||
use erg_compiler::ty::Type::*;
|
use erg_compiler::ty::Type::*;
|
||||||
|
|
||||||
|
@ -73,6 +73,9 @@ fn _test_infer_types() -> Result<(), ()> {
|
||||||
module.context.assert_var_type("a", &a_t)?;
|
module.context.assert_var_type("a", &a_t)?;
|
||||||
let abc_t = unknown_len_array_t(v_enum(set! {"a".into(), "b".into(), "c".into()}));
|
let abc_t = unknown_len_array_t(v_enum(set! {"a".into(), "b".into(), "c".into()}));
|
||||||
module.context.assert_var_type("abc", &abc_t)?;
|
module.context.assert_var_type("abc", &abc_t)?;
|
||||||
|
let t = type_q("T");
|
||||||
|
let f_t = proc1(t.clone(), unknown_len_array_mut(t)).quantify();
|
||||||
|
module.context.assert_var_type("f!", &f_t)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ pub fn unknown_len_array_t(elem_t: Type) -> Type {
|
||||||
array_t(elem_t, TyParam::erased(Type::Nat))
|
array_t(elem_t, TyParam::erased(Type::Nat))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unknown_len_array_mut(elem_t: Type) -> Type {
|
||||||
|
array_mut(elem_t, TyParam::erased(Type::Nat))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn tuple_t(args: Vec<Type>) -> Type {
|
pub fn tuple_t(args: Vec<Type>) -> Type {
|
||||||
poly(
|
poly(
|
||||||
"Tuple",
|
"Tuple",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue