Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Match templates for trailing closures in functions with multiple parameters #22

Open
vinivendra opened this issue Mar 30, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@vinivendra
Copy link
Owner

vinivendra commented Mar 30, 2020

Currently, templates for trailing closures only match if the closure is the only parameter of the function call. If there are more, the template won't match. For instance:

// Define a function with multiple parameters
func f(int: Int, a: (Int) -> ()) {
	a(int)
}

// Define the template
func gryphonTemplates() {
	let _closure: (Int) -> () = { _ in }
	let _int: Int = 0

	f(int: _int, a: _closure)
	"g(_int) _closure"
}

// Call the function
f(int: 0) { print($0) }

translates to

internal fun f(int: Int, a: (Int) -> Unit) {
	a(int)
}

fun main(args: Array<String>) {
	f(int = 0, a = { println(it) })
}

If the template had matched, the translation (in the second-to-last line of Kotlin code) would be g(0) { println(it) } as the template said.

This template works if the f function only has one parameter (i.e. if we removed the int parameter), but not if it has more than one.

@vinivendra vinivendra added the bug Something isn't working label Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant