skiptools / skiptools/skip

ExpressibleByStringInterpolation constructor is not inferred for non-interpolated string parameters

Open
#68 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement transpilation
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.