skiptools / skiptools/skip

Support static protocol generic access from reified types

Open
#469 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

Accessing static members of generic parameters could be supported with Skip's reified type support like so:

protocol Foo {
    static var staticValue: Int { get }
}

struct FooInstance : Foo {
    static var staticValue: Int = 123
}

@inline(__always) func getFooValue<T: Foo>(_ type: T.Type) -> Int {
    // Without this we get: Type parameter 'T' cannot have or inherit a companion object, so it cannot be on the left-hand side of a dot.
    // SKIP REPLACE: return (T::class.companionObjectInstance as FooCompanion).staticValue
    return T.staticValue
}

Skip could automatically identify when there is an attempt to access a static value of a generic reified type T that conforms to X and replace T. with (T::class.companionObjectInstance as XCompanion).

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 issue's Swift example and inspect the compiler handling for reified generic types, protocol conformances, and static member access. Determine where the shown T.staticValue access is translated and how the companion-object replacement should apply. Done means the example compiles and retrieves the conforming type's static value.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.