Correctly instantiate type constructors
@@ -869,7 +869,6 @@ pub fn infer_module(module: UntypedModule) -> Result<TypedModule, Error> {
args: args_types,
retrn: Box::new(retrn.clone()),
};
- dbg!(&typ);
if public {
fields.push((constructor.name.clone(), typ.clone()));
}
@@ -993,21 +992,6 @@ pub fn infer(expr: UntypedExpr, level: usize, env: &mut Env) -> Result<TypedExpr
})
}
- Expr::Var {
- meta,
- scope: _,
- typ: _,
- name,
- } => {
- let (scope, typ) = infer_var(&name, level, &meta, env)?;
- Ok(Expr::Var {
- meta,
- scope,
- typ,
- name,
- })
- }
-
Expr::Fn {
meta,
typ: _,
@@ -1196,6 +1180,21 @@ pub fn infer(expr: UntypedExpr, level: usize, env: &mut Env) -> Result<TypedExpr
})
}
+ Expr::Var {
+ meta,
+ scope: _,
+ typ: _,
+ name,
+ } => {
+ let (scope, typ) = infer_var(&name, level, &meta, env)?;
+ Ok(Expr::Var {
+ meta,
+ scope,
+ typ,
+ name,
+ })
+ }
+
Expr::Constructor { meta, name, typ: _ } => {
let (_scope, typ) = infer_var(&name, level, &meta, env)?;
Ok(Expr::Constructor { meta, typ, name })
@@ -1385,7 +1384,7 @@ fn instantiate(typ: Type, ctx_level: usize, env: &mut Env) -> Type {
module,
args: args
.into_iter()
- .map(|t| instantiate(t, ctx_level, env))
+ .map(|t| go(t, ctx_level, ids, env))
.collect(),
},
@@ -2585,14 +2584,12 @@ fn infer_module_test() {
let cases = [
Case {
- src: "
-fn private() { 1 }
+ src: "fn private() { 1 }
pub fn public() { 1 }",
typ: "module { fn public() -> Int }",
},
Case {
- src: "
-fn empty() { {} }
+ src: "fn empty() { {} }
pub fn run() { { empty() | level = 1 } }",
typ: "module { fn run() -> {level = Int} }",
},
@@ -2647,7 +2644,6 @@ pub fn run() { { empty() | level = 1 } }",
fn int() -> Int
}",
},
- /* TODO: FIXME: generic vars in constructors are not functioning correctly
Case {
src: "
pub enum Box(a) = | Box(a)
@@ -2659,7 +2655,6 @@ pub fn run() { { empty() | level = 1 } }",
fn int() -> Box(Int)
}",
},
- */
// Case {
// src: "
// pub enum I = | I(Int)
