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

Support holes as function arguments #45

Open
wants to merge 2 commits into
base: main
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
11 changes: 7 additions & 4 deletions src/main/scala/holes/TypedHolesComponent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ class TypedHolesComponent(plugin: Plugin, val global: Global, getLogLevel: () =>
case _ =>
}
super.traverse(tree)
case a @ Apply(_, args) =>
args foreach {
case Function(vparams, Hole(body)) =>
case a @ Apply(fn, args) =>
val paramTypes = fn.symbol.paramss.flatten.map(_.tpe)
paramTypes.zip(args).foreach {
case (paramTpe, Hole(body)) =>
log(body, paramTpe)
case (paramTpe, Function(vparams, Hole(body))) =>
bindings.push(vparams.map(param => (param.name, Binding(param.tpt.tpe, param.pos))).toMap)
log(body, a.tpe)
log(body, paramTpe)
bindings.pop()
case _ =>
}
Expand Down
24 changes: 19 additions & 5 deletions src/test/resources/val-var-def-one-liners/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,25 @@ Relevant bindings include
val hole13: (Int, String) => (String, Int) = { (a, b) => ??? }
^
src/test/resources/val-var-def-one-liners/input.scala:31:
Found hole with type: Int
Found hole with type: B
Copy link
Owner Author

Choose a reason for hiding this comment

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

I feel like if I can find the right incantation I can persuade the compiler to fill in this type param with the concrete type. More experimentation needed...

Relevant bindings include
a: Int (bound at input.scala:31:55)
c: Char (bound at input.scala:31:58)
a: Double (bound at input.scala:31:65)
c: Char (bound at input.scala:31:68)
s: String (bound at input.scala:31:33)

val hole14: String => Int = { s => s.foldLeft(0) { (a, c) => ??? } }
^
val hole14: String => Int = { s => s.foldLeft[Double](0.0) { (a, c) => ??? }.toInt }
^
src/test/resources/val-var-def-one-liners/input.scala:33:
Found hole with type: CharSequence
Relevant bindings include
x: String (bound at input.scala:33:14)

def hole15(x: String) = x.contains(???)
^
src/test/resources/val-var-def-one-liners/input.scala:35:
Found hole with type: A => Boolean
Copy link
Owner Author

Choose a reason for hiding this comment

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

Similarly here

Relevant bindings include
xs: List[Int] (bound at input.scala:35:14)

def hole16(xs: List[Int]) = xs.exists(???)
^
8 changes: 6 additions & 2 deletions src/test/resources/val-var-def-one-liners/input.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ object Foo {

val hole13: (Int, String) => (String, Int) = { (a, b) => ??? }

val hole14: String => Int = { s => s.foldLeft(0) { (a, c) => ??? } }
val hole14: String => Int = { s => s.foldLeft[Double](0.0) { (a, c) => ??? }.toInt }

}
def hole15(x: String) = x.contains(???)

def hole16(xs: List[Int]) = xs.exists(???)

}