Support static protocol generic access from reified types
Nobody has claimed this yet.
- 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
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
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