feat: ref/ref! with type specification

This commit is contained in:
Shunsuke Shibayama 2024-12-27 02:46:58 +09:00
parent 6d2c399d67
commit 1fe189e4d3
4 changed files with 65 additions and 15 deletions

View file

@ -466,7 +466,7 @@ impl Context {
free_var(level, Constraint::new_type_of(Type))
};
let spec_t = if let Some(spec_with_op) = &sig.t_spec {
match self.instantiate_typespec_full(
let t = match self.instantiate_typespec_full(
&spec_with_op.t_spec,
opt_decl_t,
tmp_tv_cache,
@ -481,6 +481,11 @@ impl Context {
}
t
}
};
match &sig.pat {
ast::ParamPattern::Ref(_) => ref_(t),
ast::ParamPattern::RefMut(_) => ref_mut(t, None),
_ => t,
}
} else {
match &sig.pat {

View file

@ -540,7 +540,8 @@ impl Context {
kind,
false,
) {
Ok(ty) => (ty, TyCheckErrors::empty()),
Ok(ty @ Type::Ref(_)) => (ty, TyCheckErrors::empty()),
Ok(ty) => (ty.into_ref(), TyCheckErrors::empty()),
Err((ty, errs)) => (ty, errs),
};
if &name.inspect()[..] == "self" {
@ -592,7 +593,8 @@ impl Context {
kind,
false,
) {
Ok(ty) => (ty, TyCheckErrors::empty()),
Ok(ty @ Type::RefMut { .. }) => (ty, TyCheckErrors::empty()),
Ok(ty) => (ty.into_ref_mut(None), TyCheckErrors::empty()),
Err((ty, errs)) => (ty, errs),
};
if &name.inspect()[..] == "self" {