fix: type alias bug

This commit is contained in:
Shunsuke Shibayama 2023-10-16 18:34:19 +09:00
parent 0c6c5e363f
commit e6cf329f97
8 changed files with 42 additions and 28 deletions

View file

@ -1389,6 +1389,11 @@ impl Context {
Visibility::BUILTIN_PUBLIC,
);
generic_array.register_trait(mono(GENERIC_ARRAY), array_hash);
let unsized_array_t = poly(UNSIZED_ARRAY, vec![ty_tp(T.clone())]);
let mut unsized_array =
Self::builtin_poly_class(UNSIZED_ARRAY, vec![ParamSpec::t_nd(TY_T)], 1);
unsized_array.register_superclass(Obj, &obj);
unsized_array.register_builtin_decl(KW_ELEM, T.clone(), vis.clone(), Some(KW_ELEM));
/* Array */
let mut array_ =
Self::builtin_poly_class(ARRAY, vec![PS::t_nd(TY_T), PS::default(TY_N, Nat)], 10);
@ -2994,6 +2999,13 @@ impl Context {
Const,
Some(ARRAY),
);
self.register_builtin_type(
unsized_array_t,
unsized_array,
vis.clone(),
Const,
Some(UNSIZED_ARRAY),
);
self.register_builtin_type(arr_t, array_, vis.clone(), Const, Some(ARRAY));
self.register_builtin_type(mono(SLICE), slice, vis.clone(), Const, Some(FUNC_SLICE));
self.register_builtin_type(

View file

@ -227,6 +227,7 @@ const PATH: &str = "Path";
const MODULE: &str = "Module";
const PY_MODULE: &str = "PyModule";
const GENERIC_ARRAY: &str = "GenericArray";
const UNSIZED_ARRAY: &str = "UnsizedArray";
const ARRAY: &str = "Array";
const MUT_ARRAY: &str = "Array!";
const FUNC_UPDATE_NTH: &str = "update_nth";

View file

@ -570,12 +570,7 @@ impl Context {
return Ok(t);
}
}
if let Some((typ, _)) = self.get_type_and_ctx(ident.inspect()) {
if let Some((_, vi)) = self.get_var_info(ident.inspect()) {
self.inc_ref(ident.inspect(), vi, ident, self);
}
Ok(typ.clone())
} else if let Some(typ) = self
if let Some(typ) = self
.consts
.get(ident.inspect())
.and_then(|v| self.convert_value_into_type(v.clone()).ok())
@ -584,6 +579,11 @@ impl Context {
self.inc_ref(ident.inspect(), vi, ident, self);
}
Ok(typ)
} else if let Some((typ, _)) = self.get_type_and_ctx(ident.inspect()) {
if let Some((_, vi)) = self.get_var_info(ident.inspect()) {
self.inc_ref(ident.inspect(), vi, ident, self);
}
Ok(typ.clone())
} else if not_found_is_qvar {
let tyvar = named_free_var(Str::rc(other), self.level, Constraint::Uninited);
tmp_tv_cache.push_or_init_tyvar(&ident.name, &tyvar, self);

View file

@ -1735,21 +1735,18 @@ impl ASTLowerer {
Ok(block) => {
let found_body_t = block.ref_t();
let outer = self.module.context.outer.as_ref().unwrap();
let opt_expect_body_t = sig
.ident()
.and_then(|ident| outer.get_current_scope_var(&ident.name))
.map(|vi| vi.t.clone())
let opt_expect_body_t = self
.module
.context
.instantiate_var_sig_t(
sig.t_spec.as_ref().map(|ts| &ts.t_spec),
RegistrationMode::PreRegister,
)
.ok()
.or_else(|| {
// discard pattern
let sig_t = self
.module
.context
.instantiate_var_sig_t(
sig.t_spec.as_ref().map(|ts| &ts.t_spec),
RegistrationMode::PreRegister,
)
.ok();
sig_t
sig.ident()
.and_then(|ident| outer.get_current_scope_var(&ident.name))
.map(|vi| vi.t.clone())
});
let ident = match &sig.pat {
ast::VarPattern::Ident(ident) => ident.clone(),

View file

@ -3135,8 +3135,7 @@ impl VarName {
.content
.chars()
.next()
.map(|c| c.is_uppercase())
.unwrap_or(false)
.map_or(false, |c| c.is_uppercase())
}
#[inline]
@ -3146,12 +3145,7 @@ impl VarName {
#[inline]
pub fn is_procedural(&self) -> bool {
self.0
.content
.chars()
.last()
.map(|c| c == '!')
.unwrap_or(false)
self.0.content.chars().last().map_or(false, |c| c == '!')
}
pub fn is_raw(&self) -> bool {

View file

@ -0,0 +1,2 @@
Packages = [{ .name = Str; .version = Str }; _]
_: Packages = [{ .name = "a"; }]

View file

@ -12,3 +12,6 @@ _: Iterable(Dict({Str: Int})) = [{"a": 1}]
f2|T|(_: Structural { .a = (self: T) -> Obj }): NoneType = None
g2: (|T|(_: Structural { .a = (self: T) -> Obj }) -> NoneType) = f2
_, _ = f2, g2
Packages = [{ .name = Str; .version = Str }; _]
_: Packages = [{ .name = "a"; .version = "b" }]

View file

@ -396,6 +396,11 @@ fn exec_addition_err() -> Result<(), ()> {
expect_failure("tests/should_err/addition.er", 3, 9)
}
#[test]
fn exec_advanced_type_spec_err() -> Result<(), ()> {
expect_failure("tests/should_err/advanced_type_spec.er", 0, 1)
}
#[test]
fn exec_args() -> Result<(), ()> {
expect_failure("tests/should_err/args.er", 0, 19)