Files
swift-mirror/test/IRGen/Inputs/weak_import_native_helper.swift
Allan Shortlidge a6eb7e494b AST: Fix weak linking for potentially unavailable accessors in extensions.
In https://github.com/swiftlang/swift/pull/78454 queries for the platform
availability of decl were consolidated into
`Decl::getAvailableAttrForPlatformIntroduction()`. In addition to checking the
attributes directly attached to the decl, this method also checks whether the
decl is a member directly contained inside of an extension and checks for
attributes attached to the extension as well. Previously, this logic was only
used for availability checking diagnostics, where special casing extension
members was a requirement. As a result of the consolidation, though, the logic
is now also shared by the query that determines whether to weakly link symbols
associated with a decl. That determination already had its own way of handling
members of extensions but it seemed like consolidating the logic would stil be
a net improvement that would reduce overall complexity.

Unfortunately, the existing approach to getting the availability of the
enclosing extension had a subtle bug for both AccessorDecl and OpaqueTypeDecl.
If an AvailableAttr was not directly attached to the immediate decl, then
`Decl::getAvailableAttrForPlatformIntroduction()` would check if the enclosing
decl context was an extension and look at its attributes as well. For
AccessorDecl and OpaqueTypeDecl, checking the enclosing decl context would
accidentally skip over the VarDecl and AbstractFunctionDecl that are formally
the parents of those decls for the purposes of attribute inheritance. As a
result, the availability of the enclosing property or function could be ignored
if the enclosing extension had explicit availability attributes.

The fix is to use `AvailabilityInference::parentDeclForInferredAvailability()`
instead of `getDeclContext()` when looking for the immediately enclosing
extension.

Resolves rdar://143139472.
2025-01-24 17:43:42 -08:00

139 lines
1.9 KiB
Swift

@_weakLinked
public func fn() {}
@_weakLinked
public var globalStored = 0
@_weakLinked
public var globalComputed: Int {
get { return 1 }
set {}
}
public struct S {
@_weakLinked
public func fn() {}
@_weakLinked
public var storedProp = 0
@_weakLinked
public var computedProp: Int {
get { return 1 }
set {}
}
@_weakLinked
public init() {}
@_weakLinked
public subscript(_: Int) -> Int {
get { return 1 }
set {}
}
}
extension S {
@_weakLinked
public func extensionFn() {}
@_weakLinked
public var extensionProp: Int {
get { return 1 }
set {}
}
}
public enum E {
case strong
@_weakLinked
case weak
case strongAssoc(Int)
@_weakLinked
case weakAssoc(Int)
}
open class C {
@_weakLinked
open func fn() {}
@_weakLinked
open var storedProp = 0
@_weakLinked
open var computedProp: Int {
get { return 1 }
set {}
}
@_weakLinked
public init() {}
@_weakLinked
open subscript(_: Int) -> Int {
get { return 1 }
set {}
}
}
public protocol P {
@_weakLinked
func fn()
@_weakLinked
var prop: Int { get set }
@_weakLinked
init()
@_weakLinked
subscript(_: Int) -> Int { get set }
}
@_weakLinked
public struct WeakS {
public init() {}
public func weakMember() {}
}
@_weakLinked
public enum WeakE {}
@_weakLinked
open class WeakC {
public init() {}
}
@_weakLinked
public protocol WeakP {}
@_weakLinked
public struct GenericS<T> {}
@_weakLinked
public enum GenericE<T> {}
@_weakLinked
open class GenericC<T> {
public init() {}
}
public protocol OtherProtocol {}
public struct ConcreteType : OtherProtocol {}
public protocol ProtocolWithWeakMembers {
@_weakLinked associatedtype T : OtherProtocol = ConcreteType
@_weakLinked func f()
}
extension ProtocolWithWeakMembers {
@_weakLinked public func f() {}
}
public protocol BaseP {}
@_weakLinked extension S : BaseP {}