Skip to content

Generated types can shadow PklSwift API types #155

@HT154

Description

@HT154
// TypeAlias.pkl
module TypeAlias

foo: TypeAlias = UInt

Output (with compiler errors inlined as comments):

// TypeAlias.swift

// Code generated from Pkl module `TypeAlias`. DO NOT EDIT.
import PklSwift

public enum TypeAlias {}

extension TypeAlias {
    public struct Module: PklRegisteredType, Decodable, Hashable, Sendable {
//                ^^^^^^
//                Type 'TypeAlias.Module' does not conform to protocol 'Equatable'

        public static let registeredIdentifier: String = "TypeAlias"

        public var foo: TypeAlias
//                 ^^^
//                 Stored property 'foo' of 'Sendable'-conforming struct
//                 'Module' has non-Sendable type 'TypeAlias'

        public init(foo: TypeAlias) {
            self.foo = foo
        }
    }

    /// Load the Pkl module at the given source and evaluate it into `TypeAlias.Module`.
    ///
    /// - Parameter source: The source of the Pkl module.
    public static func loadFrom(source: ModuleSource) async throws -> TypeAlias.Module {
        try await PklSwift.withEvaluator { evaluator in
            try await loadFrom(evaluator: evaluator, source: source)
        }
    }

    /// Load the Pkl module at the given source and evaluate it with the given evaluator into
    /// `TypeAlias.Module`.
    ///
    /// - Parameter evaluator: The evaluator to use for evaluation.
    /// - Parameter source: The module to evaluate.
    public static func loadFrom(
        evaluator: PklSwift.Evaluator,
        source: PklSwift.ModuleSource
    ) async throws -> TypeAlias.Module {
        try await evaluator.evaluateModule(source: source, as: Module.self)
    }
}

Code generation should produce

public var foo: PklSwift.TypeAlias

Either unconditionally, or when an outer type would shadow a type from PklSwift.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions