Files
swift-mirror/test/SILGen/member_chains.swift
Kavon Farvardin d2bd562799 Test: send shadow RUN lines to /dev/null
The opaque values test coverage I initially added will emit to
stdout, which is noisy for people's logs if the test is failing for
some other reason.
2026-06-30 17:40:48 -07:00

38 lines
1.1 KiB
Swift

// RUN: %target-swift-emit-silgen-ossa -o /dev/null -enable-sil-opaque-values %s
// RUN: %target-swift-emit-silgen -verify %s
struct ImplicitMembers: Equatable {
static var implicit = ImplicitMembers()
static var optional: ImplicitMembers? = ImplicitMembers()
static func createOptional() -> ImplicitMembers? {
ImplicitMembers()
}
var another: ImplicitMembers { ImplicitMembers() }
var anotherOptional: ImplicitMembers? { ImplicitMembers() }
}
// Make sure we can SILGen these without issue.
postfix operator ^
postfix func ^ (_ lhs: ImplicitMembers) -> Int { 0 }
extension Int {
func foo() {}
var optionalMember: Int? { 0 }
}
// https://github.com/swiftlang/swift/issues/80265
// Make sure optional chaining looks through postfix operators.
var x: ImplicitMembers?
let _ = x?^.foo()
let _ = x?^.optionalMember?.foo()
let _ = x?.another^.optionalMember?.foo()
// Make sure the unresolved member chain extends up to the postfix operator,
// but the optional chain covers the entire expr.
let _ = .optional?^.foo()
let _ = .createOptional()?^.foo()
let _ = .implicit.anotherOptional?^.foo()