Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 *)
Expand Down
11 changes: 11 additions & 0 deletions test/bugs/freeclass1.as
Original file line number Diff line number Diff line change
@@ -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) ;

};

10 changes: 10 additions & 0 deletions test/fail/nested-class-rec-fail.as
Original file line number Diff line number Diff line change
@@ -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

};
1 change: 1 addition & 0 deletions test/fail/ok/nested-class-rec-fail.tc.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nested-class-rec-fail.as:8.13-8.16: type error, cannot infer type of forward variable Foo
10 changes: 10 additions & 0 deletions test/run/nested-class-rec.as
Original file line number Diff line number Diff line change
@@ -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

};