skiptools / skiptools/skip-lib

Functions as initializer arguments...

Open
#4 3 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.