Skip to content

[SR-2318] Swift 3 Regression - "type of expression is ambiguous without more context" #44925

Open
@swift-ci

Description

@swift-ci
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: +)) }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationregressionswift 3.0type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions