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

enh(swift) add parameter pack keywords #3803

Merged

Conversation

bradleymackey
Copy link
Contributor

Parameter packs are supported in Swift 5.9

Their usage can be seen in SE-0393. This essentially just requires a promotion of each to a keyword and matching repeat and each as keywords in generic parameters.

Changes

  • Support repeat and each parameter pack keywords.

Checklist

  • Added markup tests, or they don't apply here because...
  • Updated the changelog at CHANGES.md

src/languages/swift.js Outdated Show resolved Hide resolved
@joshgoebel
Copy link
Member

So what is repeat when used outside a generic?

@bradleymackey
Copy link
Contributor Author

bradleymackey commented Jun 12, 2023

It's a general mechanism for destructuring and composing type/value packs, so it's supported in more contexts than just generic parameter lists. This is a good example from the proposal, the keyword can be used in the context of a parameter pack directly:

struct Pair<First, Second> {
  init(_ first: First, _ second: Second)
}

func makePairs<each First, each Second>(
  firsts first: repeat each First,
  seconds second: repeat each Second
) -> (repeat Pair<each First, each Second>) {
  return (repeat Pair(each first, each second))
}

let pairs = makePairs(firsts: 1, "hello", seconds: true, 1.0)
// 'pairs' is '(Pair(1, true), Pair("hello", 2.0))'

@joshgoebel
Copy link
Member

Is it not a keyword in those other contexts?

@bradleymackey
Copy link
Contributor Author

It is a keyword in those contexts as well, it's already in the "keywords" list though because it's already used for loops.

repeat {
    print(number)
    number += 1
} while number <= 20

@joshgoebel
Copy link
Member

Ah that's what I was missing. 😀

src/languages/swift.js Outdated Show resolved Hide resolved
@joshgoebel joshgoebel merged commit 4efc51c into highlightjs:main Jun 14, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants