Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Checking of a Generic Type not working using swift 6.0 on Mac (swiftlang-6.0.0.3.300 clang-1600.0.20.10) #74282

Closed
agiokas opened this issue Jun 11, 2024 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself noncopyable struct/enum Feature → declarations: Noncopyable value type declarations

Comments

@agiokas
Copy link

agiokas commented Jun 11, 2024

Description

When trying to check if a Type conforms to a protocol which is extending Optional it delivers wrong result.

Checking does not work when using swiftlang-6.0.0.3.300 clang-1600.0.20.10 with target MacOS

Code works as expected using swiftlang-6.0.0.3.300 clang-1600.0.20.10 with target iOS
Code works as expected using swiftlang-5.10.0.13 clang-1500.3.9.4 with target MacOS
Code works as expected using swiftlang-5.10.0.13 clang-1500.3.9.4 with target iOS

Reproduction

// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "OptionalCheck",
    products: [
        .library(name: "OptionalCheck", targets: ["OptionalCheck"]),
    ],
    targets: [
        .target(name: "OptionalCheck"),
        .testTarget(name: "OptionalCheckTests", dependencies: ["OptionalCheck"] ),
    ]
)
import XCTest

final class OptionalCheckTests: XCTestCase {
    func testExample() throws {
        XCTAssertFalse(isOptional(Int.self), "Int is not an Optional")
        XCTAssertTrue(isOptional(Int?.self), "Int? is an Optional")
    }
    
    func isOptional<R>(_ type: R.Type) -> Bool {
        R.self is OptionalProtocol.Type
    }
}

protocol OptionalProtocol {}
extension Optional: OptionalProtocol {}

Expected behavior

using swiftlang-6.0.0.3.300 clang-1600.0.20.10 and target MacOS it should work like in swift 5.10 or like target iOS

Environment

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0

Additional information

No response

@agiokas agiokas added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jun 11, 2024
@agiokas agiokas changed the title Type Checking to Optional Type not working using swift 6.0 on Mac (swiftlang-6.0.0.3.300 clang-1600.0.20.10) Optional Checking of a Generic Type not working using swift 6.0 on Mac (swiftlang-6.0.0.3.300 clang-1600.0.20.10) Jun 11, 2024
@xedin
Copy link
Contributor

xedin commented Jun 11, 2024

@mikeash This looks like a runtime problem and not type-checker one, output of Sema is identical between 5.10 and 6.0 in this case but runtime behavior is different.

@mikeash
Copy link
Contributor

mikeash commented Jun 11, 2024

This specifically happens when using the new swiftc and running on an older OS. The new swiftc emits the conformance with an invertible protocol requirement. But the old runtime doesn't know how to handle that requirement. checkGenericRequirement bonks into this check:

  if (!req.hasKnownKind())
    return TypeLookupError("unknown kind");

And the check fails. @kavon how is this supposed to work when targeting an older OS version?

@xedin xedin added noncopyable struct/enum Feature → declarations: Noncopyable value type declarations compiler The Swift compiler itself and removed noncopyable struct/enum Feature → declarations: Noncopyable value type declarations triage needed This issue needs more specific labels labels Jun 14, 2024
@kavon
Copy link
Member

kavon commented Jun 24, 2024

This should be fixed by #74604

@kavon
Copy link
Member

kavon commented Jun 24, 2024

For release/6.0: #74605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself noncopyable struct/enum Feature → declarations: Noncopyable value type declarations
Projects
None yet
Development

No branches or pull requests

4 participants