diff --git a/src/typing.ml b/src/typing.ml index be56ac84178..9f82a3cda97 100644 --- a/src/typing.ml +++ b/src/typing.ml @@ -363,7 +363,8 @@ and infer_exp'' env exp : T.typ = | Some T.Pre -> error env id.at "cannot infer type of forward variable %s" id.it; | Some t -> t - | None -> error env id.at "unbound variable %s" id.it + | None -> + error env id.at "unbound variable %s" id.it ) | LitE lit -> T.Prim (infer_lit env lit exp.at) @@ -1120,7 +1121,12 @@ and gather_dec_typdecs env scope dec : scope = let c = Con.fresh id.it pre_k in let te' = T.Env.add id.it c scope.typ_env in let ce' = T.ConSet.disjoint_add c scope.con_env in - {scope with typ_env = te'; con_env = ce'} + let ve' = match dec.it with + | ClassD _ -> + T.Env.add id.it T.Pre scope.val_env + | _ -> scope.val_env + in + { typ_env = te'; con_env = ce'; val_env = ve' } (* Pass 2 and 3: infer type definitions *) diff --git a/test/bugs/freeclass1.as b/test/bugs/freeclass1.as new file mode 100644 index 00000000000..c69527dac15 --- /dev/null +++ b/test/bugs/freeclass1.as @@ -0,0 +1,11 @@ + +class Foo(f1:Int -> Int, f2:Int -> Int) { }; + +class Bar () { + + private g(n:Int) : Int = n + 1; + + let Bar = Foo(g, g) ; + +}; + diff --git a/test/fail/nested-class-rec-fail.as b/test/fail/nested-class-rec-fail.as new file mode 100644 index 00000000000..5dbcfb85677 --- /dev/null +++ b/test/fail/nested-class-rec-fail.as @@ -0,0 +1,10 @@ + +class Foo(f1:Int -> Int, f2:Int -> Int) { }; + +class Bar () { + + private g(n:Int) : Int = n + 1; + + let Bar = Foo(g, g) /*: Foo */; // annotation needed to typecheck constructor call + +}; diff --git a/test/fail/ok/nested-class-rec-fail.tc.ok b/test/fail/ok/nested-class-rec-fail.tc.ok new file mode 100644 index 00000000000..6e4d5470dd3 --- /dev/null +++ b/test/fail/ok/nested-class-rec-fail.tc.ok @@ -0,0 +1 @@ +nested-class-rec-fail.as:8.13-8.16: type error, cannot infer type of forward variable Foo diff --git a/test/run/nested-class-rec.as b/test/run/nested-class-rec.as new file mode 100644 index 00000000000..4ab62442d0c --- /dev/null +++ b/test/run/nested-class-rec.as @@ -0,0 +1,10 @@ + +class Foo(f1:Int -> Int, f2:Int -> Int) { }; + +class Bar () { + + private g(n:Int) : Int = n + 1; + + let Bar = Foo(g, g) : Foo; // annotation needed to typecheck constructor call + +};