Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- Sources/MetaCodable/CodedAs/AnyCodableLiteral.swift
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
{
"os": "macos-15",
"language": "swift",
"swift": "latest"
"swift": "6.1.2"
}
]
}
Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
},
{
"os": "macos-15",
"swift": "latest"
"swift": "6.1.2"
}
]
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/MetaCodable/Codable/Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
/// coding key path, with variable name as coding key.
/// * Use ``CodedAt(_:)`` with no path arguments, when type is composition
/// of multiple `Codable` types.
/// * Use ``CodedAs(_:_:)`` to provide additional coding key values where
/// field value can appear.
/// * Use ``CodedAs(_:_:)-8wdaz`` to provide additional coding key values
/// where field value can appear.
/// * Use ``CodedBy(_:)`` to provide custom decoding/encoding behavior for
/// `Codable` types or implement decoding/encoding for non-`Codable` types.
/// * Use ``Default(_:)`` to provide default value when decoding fails.
/// * Use ``CodedAs(_:_:)`` to provide custom values for enum cases.
/// * Use ``CodedAs(_:_:)-8wdaz`` and ``CodedAs(_:_:)-4n3ze``
/// to provide custom values for enum cases.
/// * Use ``CodedAt(_:)`` to provide enum-case/protocol identifier tag path.
/// * Use ``CodedAs()`` to provide enum-case/protocol identifier tag type.
/// * Use ``ContentAt(_:_:)`` to provided enum-case/protocol content path.
Expand Down
5 changes: 4 additions & 1 deletion Sources/MetaCodable/Codable/Decodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
/// of multiple `Decodable` types.
/// * Use ``CodedBy(_:)`` to provide custom decoding behavior for
/// `Decodable` types or implement decoding for non-`Decodable` types.
/// * Use ``CodedAs(_:_:)-8wdaz`` to provide additional coding key values
/// where field value can appear.
/// * Use ``Default(_:)`` to provide default value when decoding fails.
/// * Use ``CodedAs(_:_:)`` to provide custom values for enum cases.
/// * Use ``CodedAs(_:_:)-8wdaz`` and ``CodedAs(_:_:)-4n3ze``
/// to provide custom values for enum cases.
/// * Use ``CodedAt(_:)`` to provide enum-case/protocol identifier tag path.
/// * Use ``CodedAs()`` to provide enum-case/protocol identifier tag type.
/// * Use ``ContentAt(_:_:)`` to provided enum-case/protocol content path.
Expand Down
7 changes: 4 additions & 3 deletions Sources/MetaCodable/Codable/Encodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
/// coding key path, with variable name as coding key.
/// * Use ``CodedAt(_:)`` with no path arguments, when type is composition
/// of multiple `Encodable` types.
/// * Use ``CodedAs(_:_:)`` to provide additional coding key values where
/// field value can appear.
/// * Use ``CodedAs(_:_:)-8wdaz`` to provide additional coding key values
/// where field value can appear.
/// * Use ``CodedBy(_:)`` to provide custom encoding behavior for
/// `Encodable` types or implement encoding for non-`Encodable` types.
/// * Use ``CodedAs(_:_:)`` to provide custom values for enum cases.
/// * Use ``CodedAs(_:_:)-8wdaz`` and ``CodedAs(_:_:)-4n3ze``
/// to provide custom values for enum cases.
/// * Use ``CodedAt(_:)`` to provide enum-case/protocol identifier tag path.
/// * Use ``CodedAs()`` to provide enum-case/protocol identifier tag type.
/// * Use ``ContentAt(_:_:)`` to provided enum-case/protocol content path.
Expand Down
304 changes: 304 additions & 0 deletions Sources/MetaCodable/CodedAs/AnyCodableLiteral.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
/// A type that conforms to all `ExpressibleBy*Literal` protocols for use in macro contexts.
///
/// This type is designed to be used only during macro expansion and compile-time processing.
/// All runtime implementations will `fatalError` to prevent accidental usage at runtime.
///
/// ## Usage
/// This type allows macros to accept literal values of any type while maintaining type safety
/// during compilation. The actual values are processed at compile-time and never instantiated
/// at runtime.
///
/// ## Warning
/// **DO NOT USE AT RUNTIME** - All initializers and methods will crash with `fatalError`.
public struct AnyCodableLiteral {
/// Private initializer to prevent direct instantiation
private init() {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - ExpressibleByBooleanLiteral
extension AnyCodableLiteral: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - ExpressibleByIntegerLiteral
extension AnyCodableLiteral: ExpressibleByIntegerLiteral {
public init(integerLiteral value: Int) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - ExpressibleByFloatLiteral
extension AnyCodableLiteral: ExpressibleByFloatLiteral {
public init(floatLiteral value: Double) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - ExpressibleByStringLiteral
extension AnyCodableLiteral: ExpressibleByStringLiteral {
public init(stringLiteral value: String) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - ExpressibleByExtendedGraphemeClusterLiteral
extension AnyCodableLiteral: ExpressibleByExtendedGraphemeClusterLiteral {
public init(extendedGraphemeClusterLiteral value: String) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - ExpressibleByUnicodeScalarLiteral
extension AnyCodableLiteral: ExpressibleByUnicodeScalarLiteral {
public init(unicodeScalarLiteral value: String) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - ExpressibleByStringInterpolation
extension AnyCodableLiteral: ExpressibleByStringInterpolation {
public struct StringInterpolation: StringInterpolationProtocol {
public init(literalCapacity: Int, interpolationCount: Int) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public mutating func appendLiteral(_ literal: String) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public mutating func appendInterpolation<T>(_ value: T) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

public init(stringInterpolation: StringInterpolation) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - Additional Conformances for Completeness
extension AnyCodableLiteral: Hashable {
public func hash(into hasher: inout Hasher) {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

extension AnyCodableLiteral: Equatable {
public static func == (
lhs: AnyCodableLiteral, rhs: AnyCodableLiteral
) -> Bool {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

extension AnyCodableLiteral: CustomStringConvertible {
public var description: String {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

extension AnyCodableLiteral: CustomDebugStringConvertible {
public var debugDescription: String {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - Comparable and Numeric Support
extension AnyCodableLiteral: Comparable {
public static func < (
lhs: AnyCodableLiteral, rhs: AnyCodableLiteral
) -> Bool {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

extension AnyCodableLiteral: AdditiveArithmetic {
public static var zero: AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public static func + (
lhs: AnyCodableLiteral, rhs: AnyCodableLiteral
) -> AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public static func - (
lhs: AnyCodableLiteral, rhs: AnyCodableLiteral
) -> AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

extension AnyCodableLiteral: Numeric {
public typealias Magnitude = AnyCodableLiteral

public var magnitude: AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public static func * (
lhs: AnyCodableLiteral, rhs: AnyCodableLiteral
) -> AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public static func *= (lhs: inout AnyCodableLiteral, rhs: AnyCodableLiteral)
{
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public init?<T>(exactly source: T) where T: BinaryInteger {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

extension AnyCodableLiteral: SignedNumeric {
public static func += (lhs: inout AnyCodableLiteral, rhs: AnyCodableLiteral)
{
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public static func -= (lhs: inout AnyCodableLiteral, rhs: AnyCodableLiteral)
{
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public static func / (
lhs: AnyCodableLiteral, rhs: AnyCodableLiteral
) -> AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public static func /= (lhs: inout AnyCodableLiteral, rhs: AnyCodableLiteral)
{
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public static prefix func - (
operand: AnyCodableLiteral
) -> AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

extension AnyCodableLiteral: Strideable {
public typealias Stride = AnyCodableLiteral

public func distance(to other: AnyCodableLiteral) -> AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

public func advanced(by n: AnyCodableLiteral) -> AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}

// MARK: - Range Operator Implementations
extension AnyCodableLiteral {
/// Closed range operator (...)
public static func ... (
lhs: AnyCodableLiteral, rhs: AnyCodableLiteral
) -> AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

/// Half-open range operator (..<)
public static func ..< (
lhs: AnyCodableLiteral, rhs: AnyCodableLiteral
) -> AnyCodableLiteral {
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

/// One-sided range operator (...) - postfix
public static postfix func ... (lhs: AnyCodableLiteral) -> AnyCodableLiteral
{
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

/// One-sided range operator (...) - prefix
public static prefix func ... (rhs: AnyCodableLiteral) -> AnyCodableLiteral
{
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}

/// One-sided range operator (..<) - prefix
public static prefix func ..< (rhs: AnyCodableLiteral) -> AnyCodableLiteral
{
fatalError(
"AnyCodableLiteral is not for runtime usage - compile-time only"
)
}
}
Loading
Loading