skiptools / skiptools/skip-lib
Functions as initializer arguments...
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 13
- Forks
- 4
- Avg merge
- 1h 49m
- Merged PRs (30d)
- 2
Description
I have created a struct that takes a function as an initializer argument. This is then run periodically (using a timer) in order to repeatedly perform some logic on a periodic basis. The timer portion works fine (thanks for that!), but Skip seems to have trouble with the function argument.
A contrived and simplified example, omitting the timer aspect:
struct DoThing {
var handler: (Int, Int) -> Int
func run() {
let result = self.handler(2, 5)
print("result = \(result)")
}
}
func addHandler(number1:Int, number2:Int) -> Int {
return number1 + number2
}
func multiplyHandler(number1:Int, number2:Int) -> Int {
return number1 * number2
}
let doThing1 = DoThing(handler: addHandler)
doThing1.run()
let doThing2 = DoThing(handler: multiplyHandler)
doThing2.run()
For this, Skip errors out with the following during compilation:
Function invocation 'addHandler(...)' expected
Function invocation 'addHandler(...)' expected
No value passed for parameter 'number1'
No value passed for parameter 'number1'
No value passed for parameter 'number2'
No value passed for parameter 'number2'
Type mismatch: inferred type is Int but (Int, Int) -> Int was expected
Type mismatch: inferred type is Int but (Int, Int) -> Int was expected
Function invocation 'multiplyHandler(...)' expected
Function invocation 'multiplyHandler(...)' expected
No value passed for parameter 'number1'
No value passed for parameter 'number1'
No value passed for parameter 'number2'
No value passed for parameter 'number2'
On iOS, this code results in the following (correct) output:
result = 7
result = 10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied DoThing reproduction, including the handler property, initializer calls, and compiler diagnostics. Investigate how Skip compiles Swift function arguments; done when both addHandler and multiplyHandler can be passed and invoked successfully, producing 7 and 10.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100