swiftlang/swift

Passing class-constrained type as AnyObject instance behavior is not matched on Darwin and non-Darwin platform

Open

#70,645 创建于 2023年12月28日

在 GitHub 查看
 (16 评论) (0 反应) (0 负责人)Swift (10,719 fork)batch import
buggood first issueswift 5.9type checker

仓库指标

Star
 (69,989 star)
PR 合并指标
 (平均合并 8天 17小时) (30 天内合并 510 个 PR)

描述

Description

Passing class-constrained type as AnyObject instance behavior is not matched on Darwin and non-Darwin platform

On Darwin platform, we can pass it directly.

On non-Darwin platform, a fatalError will be emitted - "error: argument type 'Self.Type' expected to be an instance of a class or class-constrained type". And we can workaround it by manually adding "as AnyObject"

test1(Self.self as AnyObject)

Reproduction

class X {
    func test1(_ o: AnyObject) {}
    func test12() { test1(Self.self) }
}

Expected behavior

The behavior is matched. (The current Darwin platform behavior is preferred.)

Environment

Linux: swift --version Swift version 5.9.2 (swift-5.9.2-RELEASE) Target: aarch64-unknown-linux-gnu

macOS: swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1) Target: arm64-apple-macosx14.0

Additional information

Forum Post about the issue: https://forums.swift.org/t/69190

贡献者指南