Closed rlinoz closed 4 years ago
This one might be a bit more complicated to solve... here's what I'd try to do:
Create a new transpilation pass in TranspilationPass.swift
. Call it something like OptionalFunctionsTranspilationPass
or whatever.
Override the processCallExpression
method.
Inside the method, check if the callExpression's function
is an OptionalExpression
. If it is, return the expression you want in its place. It'll probably be something like this:
CallExpression(
function: DotExpression(
left: callExpression.function,
right: DeclarationReferenceExpression(identifier: "invoke"))
parameters: callExpression.parameters)
only more complicated since I omitted some arguments. If the function isn't an OptionalExpression
, return something like super.processCallExpression(callExpression)
.
Make sure to add the necessary // gryphon insert:
and // gryphon annotation:
comments to the transpilation pass (just look at the other transpilation passes to see where they go). You'll know you did it right if the BootstrappingTests are passing (run them with ./runTests.sh -b
).
Make the code run your new transpilation pass, probably somewhere around here.
That's it :)
I'd try to solve #49 before this, it might make things easier.
Describe the bug Invoking an optional function type is not being properly translated.
How to reproduce it When invoking a optional function type in Swift
foo?()
The result in Kotlin is
foo?()
When it should be
foo?.invoke()
Your environment (please complete the following information):