Skip to content

Commit

Permalink
Allow closures to use method type parameters
Browse files Browse the repository at this point in the history
This commit fixes a bug where closures did not properly capture
type parameters of methods. A test has been added.

Fixes parapluu#809.
  • Loading branch information
EliasC committed Jun 1, 2017
1 parent 25ecb27 commit e9e23e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/back/CodeGen/MethodDecl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ translateGeneral mdecl@(A.Method {A.mbody, A.mlocals})
(Deref $ Cast (Ptr . AsType $ classTypeName cname) thisVar)
`Dot`
name
closures = map (\clos -> translateClosure clos typeVars newTable)
closures = map (\clos -> translateClosure clos (typeVars ++ mTypeVars) newTable)
(reverse (Util.filter A.isClosure mbody))

localize cls prefix fun =
Expand Down
18 changes: 18 additions & 0 deletions src/tests/encore/parametric/methodPolyClosure.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
read class Bar[t]
def bar() : unit
println("In Bar")
end
end

read class Foo
def foo[ty]() : () -> unit
fun() => (new Bar[ty]()).bar()
end
end

active class Main
def main() : unit
val f = (new Foo()).foo[int]()
f()
end
end
1 change: 1 addition & 0 deletions src/tests/encore/parametric/methodPolyClosure.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In Bar

0 comments on commit e9e23e2

Please sign in to comment.