You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-2620 Conditional Downcast from AnyHashable to [file]private Protocol Fails Unless Going Through Intermediate Internal/Public Protocol
Issue Description:
I'm noticing that if I call a protocol defined static member on a generic (which conforms to the protocol), runtime doesn't call the overridden implementation (see extension CarouselView where Component == Label ).
/** Type-erased View */protocolAnyView:AnyObject{}protocolViewBuilder{func makeView()->AnyView}/** Configurable View. It requires that the type has an associated Configuration type which is used to build the AnyView instances (due to ViewBuilder requirement) */protocolConfigurableView:AnyView,PreviewProvider{associatedtypeConfiguration:ViewConfigurationvarconfiguration:Configuration{get}init(_ configuration:Configuration)}protocolViewConfiguration:ViewBuilder{associatedtypeView:ConfigurableViewwhere View.Configuration ==Self}protocolPreviewProvider{staticvarpreviewConfigurations:[ViewBuilder]{get}}extensionViewConfiguration{// Implementing the ViewBuilder protocol.func makeView()->AnyView{View(self)}}/** An example of a simple `ConfigurableView` implementation. Think of it as a simple Label view that can render a line of text with configurable font size. */classLabel:ConfigurableView{varconfiguration:Configurationrequiredinit(_ configuration:Configuration){self.configuration = configuration
}structConfiguration:ViewConfiguration{typealiasView=Labellettext:StringletfontSize:Int}}extensionLabel{staticvarpreviewConfigurations:[ViewBuilder]{[Label.Configuration(text:"Regular size label", fontSize:1),Label.Configuration(text:"Bigger label", fontSize:2),Label.Configuration(text:"Even bigger label", fontSize:3),]}}/** An example of a `ConfigurableView` implementation using generics. Think of it as a scrollable collection of configurable views. */classCarouselView<Component:ConfigurableView>:ConfigurableView{varconfiguration:Configurationrequiredinit(_ configuration:Configuration){self.configuration = configuration
}structConfiguration:ViewConfiguration{typealiasView=CarouselView<Component>letitems:[Component.Configuration]}}extensionCarouselView{staticvarpreviewConfigurations:[ViewBuilder]{[]}}extensionCarouselViewwhere Component ==Label{staticvarpreviewConfigurations:[ViewBuilder]{[CarouselView.Configuration(
items:[Label.Configuration(text:"Hello", fontSize:1),Label.Configuration(text:"World", fontSize:1),])]}}
And here's the test:
import XCTest
@testable import DynamicDispatchIssue
finalclassDynamicDispatchIssueTests:XCTestCase{func testCallingStaticMemberDirectly(){XCTAssertEqual(Label.previewConfigurations.count,3)XCTAssertEqual(CarouselView<Label>.previewConfigurations.count,1)XCTAssertEqual(CarouselView<Label>.self.previewConfigurations.count,1)}func testCallingStaticMemberOnDowncastType(){XCTAssertEqual((CarouselView<Label>.self asPreviewProvider.Type).previewConfigurations.count,1)// This assert fails because of (CarouselView<Label>.self as PreviewProvider.Type)}staticvarallTests=[("testCallingStaticMemberDirectly", testCallingStaticMemberDirectly),("testCallingStaticMemberOnDowncastType", testCallingStaticMemberOnDowncastType),]}
Is this expected?
Find the package with the code attached. Run it with:
swift test
The text was updated successfully, but these errors were encountered:
Attachment: Download
Additional Detail from JIRA
md5: ad172b3baa93495175a765a9ffb6a869
relates to:
Issue Description:
I'm noticing that if I call a protocol defined static member on a generic (which conforms to the protocol), runtime doesn't call the overridden implementation (see
extension CarouselView where Component == Label
).edit: follow the conversation in the Swift Forums: SR-14064: Accessing Static Member on Downcast Type not Calling Overridden Implementation
Here's a real-life example:
And here's the test:
Is this expected?
Find the package with the code attached. Run it with:
swift test
The text was updated successfully, but these errors were encountered: