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-2318] Swift 3 Regression - "type of expression is ambiguous without more context" #44925

Open
swift-ci opened this issue Aug 11, 2016 · 3 comments

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Aug 11, 2016

Previous ID SR-2318
Radar rdar://problem/27808030
Original Reporter fabb (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.0Regression, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 1f0ae6b06b963821044de344fd24bc8a

Issue Description:

The code compiled fine in Swift 2, and up to Swift 3 that shipped with Xcode 8 beta 3. In beta 4 and 5, the error "type of expression is ambiguous without more context" is output for the expression $0.residence:

public enum Maybe<T> : ExpressibleByNilLiteral {
    case none, some(T)
    
    public init() { self = .none }
    public init(_ s: T) { self = .some(s) }
    public init(nilLiteral: ()) { self = .none }
    
    func map<U>(_ f: (T) -> U) -> Maybe<U> {
        switch self {
        case .none : return .none
        case .some(let x) : return .some(f(x))
        }
    }
}

func pure<A>(_ x: A) -> Maybe<A> {
    return Maybe(x)
}

infix operator >>= { associativity left }
func >>= <A,B> (m: Maybe<A>, f: (A) -> Maybe<B>) -> Maybe<B> {
    switch m {
    case .none : return .none
    case .some(let m) : return f(m)
    }
}

struct Room { let length: Int, width: Int }
struct Residence { let rooms: [Room] }
struct Person { let name: String, residence: Maybe<Residence> }

func livingSpace(_ person: Maybe<Person>) -> Maybe<Int> {
    return person >>= { $0.residence }
        >>= { pure($0.rooms.map { $0.length * $0.width }.reduce(0, combine: +)) }
}
@belkadan
Copy link
Contributor

@belkadan belkadan commented Aug 11, 2016

@rudkx, the chained map/reduce sounds a little like the ambiguity issue you had earlier? (Which is not yet fixed, for Fabian's benefit.)

@rudkx
Copy link
Member

@rudkx rudkx commented Aug 11, 2016

Poor diagnostic.

The real issue here is that the second argument to reduce apparently no longer has an argument label. If you remove the "combine:" it compiles without error.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Aug 11, 2016

Comment by Fabian Ehrentraud (JIRA)

Thanks for the tip with the combine: label, this fixed the issue for me. sure, better diagnostic would be awesome

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants