Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow closures to use method type parameters #815

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/back/CodeGen/MethodDecl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ translateGeneral mdecl@(A.Method {A.mbody, A.mlocals})
argNames = map (AsLval . argName) encArgNames
argTypes = map translate encArgTypes
subst = [(ID.thisName, thisVar)] ++
varSubFromTypeVars typeVars ++
varSubFromTypeVars (typeVars ++ mTypeVars) ++
zip encArgNames argNames
ctx = Ctx.setMtdCtx (Ctx.new subst newTable) mdecl
forwardingCtx = Ctx.setMtdCtx(Ctx.newWithForwarding subst newTable) mdecl
Expand All @@ -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()
Copy link
Contributor

@kikofernandez kikofernandez Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for this case but doesn't work for the following one (copy-paste of this function plus a local function declaration):

read class Bar[t]
  def bar() : unit
    println("In Bar")
  end
end

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

active class Main
  def main() : unit
    val f = (new Foo()).foo[int]()
    f()
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Looking into it now...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EliasC What is the status of this PR? Does it still fail for @kikofernandez's example?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug this example hits has been reported as #809 — it seems to be not caused by this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have not had time to fix it. The discussion below is all there is so far.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this problem too, now.

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