ExpressibleByStringInterpolation constructor is not inferred for non-interpolated string parameters
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 3.2k
- Forks
- 106
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
This is related to https://github.com/skiptools/skip/issues/64 . We want to be able to implement SkipUI.Text like so:
public struct Text {
public init(_ key: LocalizedStringKey, tableName: String? = nil, bundle: Bundle? = nil, comment: StaticString? = nil) {
…
}
public init(verbatim string: String) {
…
}
}
And be able to create the Text with a localized key. When the string contains an interpolation (e.g., Text("Name: \(username)"), then the LocalizedStringKey constructor is inferred correctly. But if just do Text("Name") with no interpolated arguments, the string sent to the String(verbatim:) constructor, which is not what we want.
The workaround is to explicitly use a LocalizedStringKey in the Text initializer, as seen at https://github.com/skiptools/skip-ui/blob/main/Tests/SkipUITests/SkipUITests.swift#L320
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
Review related issue #64 and the workaround in skip-ui Tests/SkipUITests/SkipUITests.swift at line 320. Reproduce both Text("Name") and Text("Name: (username)") and compare which initializer is selected. Done means a non-interpolated string selects the LocalizedStringKey initializer without requiring an explicit LocalizedStringKey.
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