mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
C++ foreign reference types have custom reference counting mechanisms, so they cannot conform to `AnyObject`. Currently Swift's type system treats C++ FRTs as `AnyObject`s on non-Darwin platforms, which is incorrect. This change makes sure the behavior is consistent with Darwin platform, i.e. a cast of C++ FRT to `AnyObject` is rejected by the typechecker. rdar://136664617
27 lines
847 B
Swift
27 lines
847 B
Swift
// RUN: rm -rf %t
|
|
// RUN: split-file %s %t
|
|
// RUN: %target-swift-frontend -typecheck -verify -verify-ignore-unknown -I %t/Inputs %t/test.swift -enable-experimental-cxx-interop
|
|
|
|
//--- Inputs/module.modulemap
|
|
module Test {
|
|
header "test.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
//--- Inputs/test.h
|
|
struct __attribute__((swift_attr("import_reference")))
|
|
__attribute__((swift_attr("retain:immortal")))
|
|
__attribute__((swift_attr("release:immortal"))) Empty {
|
|
static Empty *create() { return new Empty(); }
|
|
};
|
|
|
|
//--- test.swift
|
|
|
|
import Test;
|
|
|
|
public func test(_ _: AnyObject) {}
|
|
|
|
// TODO: make this a better error.
|
|
test(Empty.create()) // expected-error {{type of expression is ambiguous without a type annotation}}
|
|
test([Empty.create()][0]) // expected-error {{argument type 'Any' expected to be an instance of a class or class-constrained type}}
|