# Opaque return type fails when using variadic generics

**URL:** <https://forums.swift.org/t/opaque-return-type-fails-when-using-variadic-generics/81120>\
**Category:** Using Swift\
**Tags:** opaque-types, variadic-generics\
**Created:** [July 15, 2025, 3:58am UTC](https://forums.swift.org/t/opaque-return-type-fails-when-using-variadic-generics/81120 "2025-07-15T03:58:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![George](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/george/32/37757_2.png) [@George](https://forums.swift.org/u/George)\
**Post date:** [July 15, 2025, 3:58am UTC](https://forums.swift.org/t/opaque-return-type-fails-when-using-variadic-generics/81120/1 "2025-07-15T03:58:03Z")

</div>

I'm running into another issue that I'd love any advice on how to work around. I've filed a bug here: [Type with parameter pack argument fails to be erased to an opaque type. · Issue #83055 · swiftlang/swift · GitHub](https://github.com/swiftlang/swift/issues/83055)

Basically, returning a type from a method specifying an opaque return type fails when using variadic generics. Below is a minimal reproduction. Interestingly, the error is `Pack expansion requires that 'each PropertyValue' and 'repeat each PropertyValue' have the same shape`, which is something I've seen when failing to convert a variadic argument into a tuple, but there is no such situation here I recognize.

```swift
public protocol Schema<Value>: Sendable {
  associatedtype Value
}

public protocol SchemaCodable {
  associatedtype Schema: VariadicTest.Schema where Schema.Value == Self
  static func schema() -> Schema
}

public protocol StructSchemaCodable: SchemaCodable {
  associatedtype SchemaDefinition
  static var schemaDefinition: SchemaDefinition { get }
}

// MARK: - This does not work

public struct StructSchemaDefinition<
  each PropertyValue: SchemaCodable
>: Sendable {
}

public struct StructSchema<
  Value: StructSchemaCodable,
  each PropertyValue: SchemaCodable
>: Schema
where
  Value.SchemaDefinition == StructSchemaDefinition<
    repeat each PropertyValue
  >
{
  var opaque: some Schema<Value> {
    // Pack expansion requires that 'each PropertyValue' and 'repeat each PropertyValue' have the same shape
    self
  }
}

// MARK: - The Following works

public struct StructSchemaDefinitionNoVariadic<
  PropertyValues
>: Sendable {
}

public struct StructSchemaNoVariadic<
  Value: StructSchemaCodable,
  PropertyValues
>: Schema
where
  Value.SchemaDefinition == StructSchemaDefinitionNoVariadic<PropertyValues>
{
  var opaque: some Schema<Value> {
    self
  }
}

```
