skiptools / skiptools/skip

Compile Error: using a function in @AppStorage() fails to compile if the enum type is inferred or if a parameter label is used

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

Nobody has claimed this yet.

transpilation
Dominant language
Swift
Stars
3.2k
Forks
106
Avg merge
6d 13h
Merged PRs (30d)
1

Description

I found that when using a function as the @AppStorage key the function fails to infer the enum type causing an error (case 1, when typing 'Tab.tag(.welcome)').
By typing 'Tag.welcome' it fixes the error, although this is not needed outside the @AppStorage() wrapper.
But if you use a function parameter label it also fails to compile (case 3, when typing 'Tab.tag(key: Tab.welcome').

Here's a simplified test:

struct ContentView: View {
    ....

    // 1. Desired option. Doesn't work
    @AppStorage(Tab.tag(.welcome)) var selectedTab1: Int = 0
    
    // 2. Verbose option. It works
    @AppStorage(Tab.tag(Tab.welcome)) var selectedTab2: Int = 0
    
    // 3. Parameter labels don't work
    @AppStorage(Tab.tag(key: Tab.welcome)) var selectedTab3: Int = 0
}

enum Tab : String, Hashable {
    case welcome, home, settings
    
    static func tag(_ key: Tab) -> String { key.rawValue }
    static func tag(key: Tab) -> String { key.rawValue }
}

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

No repository file or test is named. Start by reproducing the simplified ContentView example and compare compilation of the three @AppStorage forms, focusing on enum inference and the labeled parameter. Done means the inferred and labeled forms compile without requiring the explicit Tab type.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.