Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-4378] Swift 3.1 regression inferring type of tuple with generics #46957

Closed
NachoSoto opened this issue Mar 27, 2017 · 5 comments
Closed

[SR-4378] Swift 3.1 regression inferring type of tuple with generics #46957

NachoSoto opened this issue Mar 27, 2017 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-4378
Radar rdar://problem/31283568
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Won't Do
Environment

Apple Swift version 3.1 (swiftlang-802.0.48 clang-802.0.38)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.1Regression, TypeChecker
Assignee @slavapestov
Priority Medium

md5: 7304cd4263852c034a45e9816087b6ee

Issue Description:

The code (that used to compile):

self.pages = MutableProperty((
    data: [0: .notLoaded(expectedCount: 1)],
    totalCount: 0
))

More info on the types:

public final class InfiniteScrollingCollectionView <
    DataSource: InfiniteScrollingCollectionViewDataSource,
    Delegate: InfiniteScrollingCollectionViewDelegate,
    CellConfiguration: InfiniteScrollingCollectionCellConfigurator
> : UIView
    where
    DataSource.Element == CellConfiguration.Element,
    Delegate.Element == CellConfiguration.Element
{
    typealias Element = DataSource.Element
    typealias Error = DataSource.Error
    typealias Cell = CellConfiguration.Cell
    
    fileprivate typealias Page = DataSourcePage<Element, Error>
    fileprivate typealias Pages = (data: [Int : Page], totalCount: Int)
  
    private let pages: MutableProperty<Pages>

    ....
}

fileprivate enum DataSourcePage<T: Equatable, E: Swift.Error> {
    case loaded([T])
    case notLoaded(expectedCount: Int)
    case error(E, expectedCount: Int)
}
final public class MutableProperty<Value> {
    public init(_ initialValue: Value)
    ....
}

Expected result: code still compiles
Actual result: "Type of expression is ambiguous without more context"


Explicitly defining the tuple type works around the ambiguity:

let initialPages: Pages = (
    data: [0: .notLoaded(expectedCount: 1)],
    totalCount: 0
)
self.pages = MutableProperty(initialPages)
@jckarter
Copy link
Member

@swift-ci create

@slavapestov
Copy link
Member

Here is a reduced test case:

final public class MutableProperty<Value> {
    public init(_ initialValue: Value) {}
}

enum DataSourcePage<T> {
    case notLoaded
}

let pages1: MutableProperty<(data: DataSourcePage<Int>, totalCount: Int)> = MutableProperty((
    data: .notLoaded,
    totalCount: 0
))


let pages2: MutableProperty<(data: DataSourcePage<Int>, totalCount: Int)> = MutableProperty((
    data: DataSourcePage.notLoaded,
    totalCount: 0
))


let pages3: MutableProperty<(data: DataSourcePage<Int>, totalCount: Int)> = MutableProperty((
    data: DataSourcePage<Int>.notLoaded,
    totalCount: 0
))

All three examples type check correctly in -swift-version 4 mode, so this is something we fixed already as part of SE-0110. I'll add some tests.

@slavapestov
Copy link
Member

I added a test case: #8877

@NachoSoto
Copy link
Contributor Author

I imagine this is still not fixed?

@slavapestov
Copy link
Member

Swift 3 mode is going away. The code works in Swift 4 mode.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants