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-2326] bad type inference error with ternary operator and enums #44933

Closed
swift-ci opened this issue Aug 11, 2016 · 1 comment
Closed

[SR-2326] bad type inference error with ternary operator and enums #44933

swift-ci opened this issue Aug 11, 2016 · 1 comment

Comments

@swift-ci
Copy link
Collaborator

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

Previous ID SR-2326
Radar None
Original Reporter comex (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 3.0-dev (LLVM 17c4c6cf7a, Clang 4ca9e01a7c, Swift 13a9908)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee comex (JIRA)
Priority Medium

md5: 11e7790490ed6492b7bd5998006e8501

Issue Description:

The following program:

let a = UInt(1) == UInt(2) ? .foo : .bar

is problematic because it doesn't identify which enum foo and bar belong to. But the resulting error spew makes no sense, blaming the == operator:

huh.swift:1:17: error: ambiguous reference to member '=='
let a = UInt(1) == UInt(2) ? .foo : .bar
                ^~
Swift.==:3:13: note: found this candidate
public func ==(t0: Any.Type?, t1: Any.Type?) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: UInt8, rhs: UInt8) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: Int8, rhs: Int8) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: UInt16, rhs: UInt16) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: Int16, rhs: Int16) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: UInt32, rhs: UInt32) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: Int32, rhs: Int32) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: UInt64, rhs: UInt64) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: Int64, rhs: Int64) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: UInt, rhs: UInt) -> Bool
            ^
Swift.==:5:13: note: found this candidate
public func ==(lhs: Int, rhs: Int) -> Bool
            ^
Swift.==:3:13: note: found this candidate
public func ==(lhs: UnsafeMutableRawPointer, rhs: UnsafeMutableRawPointer) -> Bool
            ^
Swift.==:3:13: note: found this candidate
public func ==(lhs: UnsafeRawPointer, rhs: UnsafeRawPointer) -> Bool
            ^
Swift.Bool:11:24: note: found this candidate
    public static func ==(lhs: Bool, rhs: Bool) -> Bool
                       ^
Swift.Character:2:24: note: found this candidate
    public static func ==(lhs: Character, rhs: Character) -> Bool
                       ^
Swift.OpaquePointer:2:24: note: found this candidate
    public static func ==(lhs: OpaquePointer, rhs: OpaquePointer) -> Bool
                       ^
Swift.FloatingPointClassification:36:30: note: found this candidate
    infix public static func ==(a: FloatingPointClassification, b: FloatingPointClassification) -> Bool
                             ^
Swift.FloatingPointRoundingRule:121:30: note: found this candidate
    infix public static func ==(a: FloatingPointRoundingRule, b: FloatingPointRoundingRule) -> Bool
                             ^
Swift.AnyHashable:27:24: note: found this candidate
    public static func ==(lhs: AnyHashable, rhs: AnyHashable) -> Bool
                       ^
Swift.ArithmeticOverflow:5:30: note: found this candidate
    infix public static func ==(a: ArithmeticOverflow, b: ArithmeticOverflow) -> Bool
                             ^
Swift.ObjectIdentifier:3:24: note: found this candidate
    public static func ==(x: ObjectIdentifier, y: ObjectIdentifier) -> Bool
                       ^
Swift._MirrorDisposition:25:30: note: found this candidate
    infix public static func ==(a: _MirrorDisposition, b: _MirrorDisposition) -> Bool
                             ^
Swift.String:2:24: note: found this candidate
    public static func ==(lhs: String, rhs: String) -> Bool
                       ^
Swift.Index:2:24: note: found this candidate
    public static func ==(lhs: Index, rhs: Index) -> Bool
                       ^
Swift.String.UnicodeScalarView.Index:2:24: note: found this candidate
    public static func ==(lhs: String.UnicodeScalarView.Index, rhs: String.UnicodeScalarView.Index) -> Bool
                       ^
Swift.String.UTF16View.Index:2:24: note: found this candidate
    public static func ==(lhs: String.UTF16View.Index, rhs: String.UTF16View.Index) -> Bool
                       ^
Swift.String.UTF8View.Index:2:24: note: found this candidate
    public static func ==(lhs: String.UTF8View.Index, rhs: String.UTF8View.Index) -> Bool
                       ^
Swift.UnicodeDecodingResult:15:24: note: found this candidate
    public static func ==(lhs: UnicodeDecodingResult, rhs: UnicodeDecodingResult) -> Bool
                       ^
Swift.UnicodeScalar:2:24: note: found this candidate
    public static func ==(lhs: UnicodeScalar, rhs: UnicodeScalar) -> Bool
                       ^
Swift._SwiftNSOperatingSystemVersion:2:24: note: found this candidate
    public static func ==(lhs: _SwiftNSOperatingSystemVersion, rhs: _SwiftNSOperatingSystemVersion) -> Bool
                       ^
Swift.AnyIndex:10:24: note: found this candidate
    public static func ==(lhs: AnyIndex, rhs: AnyIndex) -> Bool
                       ^
Swift.Mirror:95:34: note: found this candidate
        infix public static func ==(a: Mirror.DisplayStyle, b: Mirror.DisplayStyle) -> Bool
                                 ^
Swift.==:2:13: note: found this candidate
public func ==<Element : Equatable>(lhs: ContiguousArray<Element>, rhs: ContiguousArray<Element>) -> Bool
            ^
Swift.==:2:13: note: found this candidate
public func ==<Element : Equatable>(lhs: ArraySlice<Element>, rhs: ArraySlice<Element>) -> Bool
            ^
Swift.==:2:13: note: found this candidate
public func ==<Element : Equatable>(lhs: [Element], rhs: [Element]) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<Pointee>(lhs: AutoreleasingUnsafeMutablePointer<Pointee>, rhs: AutoreleasingUnsafeMutablePointer<Pointee>) -> Bool
            ^
Swift.==:6:13: note: found this candidate
public func ==<T : RawRepresentable where T.RawValue : Equatable>(lhs: T, rhs: T) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<T : FloatingPoint>(lhs: T, rhs: T) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<Value, Element>(lhs: _HeapBuffer<Value, Element>, rhs: _HeapBuffer<Value, Element>) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<T : BinaryInteger>(lhs: T, rhs: T) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<T : BinaryInteger, U : BinaryInteger>(lhs: T, rhs: U) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<Header, Element>(lhs: ManagedBufferPointer<Header, Element>, rhs: ManagedBufferPointer<Header, Element>) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<T : Equatable>(lhs: T?, rhs: T?) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<T>(lhs: T?, rhs: _OptionalNilComparisonType) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<T>(lhs: _OptionalNilComparisonType, rhs: T?) -> Bool
            ^
Swift.==:1:13: note: found this candidate
public func ==<T : Strideable>(x: T, y: T) -> Bool
            ^
Swift.==:3:13: note: found this candidate
public func ==<Pointee>(lhs: UnsafeMutablePointer<Pointee>, rhs: UnsafeMutablePointer<Pointee>) -> Bool
            ^
Swift.==:3:13: note: found this candidate
public func ==<Pointee>(lhs: UnsafePointer<Pointee>, rhs: UnsafePointer<Pointee>) -> Bool
            ^
Swift.==:20:13: note: found this candidate
public func ==<A : Equatable, B : Equatable>(lhs: (A, B), rhs: (A, B)) -> Bool
            ^
Swift.==:20:13: note: found this candidate
public func ==<A : Equatable, B : Equatable, C : Equatable>(lhs: (A, B, C), rhs: (A, B, C)) -> Bool
            ^
Swift.==:20:13: note: found this candidate
public func ==<A : Equatable, B : Equatable, C : Equatable, D : Equatable>(lhs: (A, B, C, D), rhs: (A, B, C, D)) -> Bool
            ^
Swift.==:20:13: note: found this candidate
public func ==<A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable>(lhs: (A, B, C, D, E), rhs: (A, B, C, D, E)) -> Bool
            ^
Swift.==:20:13: note: found this candidate
public func ==<A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable, F : Equatable>(lhs: (A, B, C, D, E, F), rhs: (A, B, C, D, E, F)) -> Bool
            ^
Swift.ClosedRangeIndex<Bound>:2:24: note: found this candidate
    public static func ==(lhs: ClosedRangeIndex<Bound>, rhs: ClosedRangeIndex<Bound>) -> Bool
                       ^
Swift.EmptyCollection<Element>:2:24: note: found this candidate
    public static func ==(lhs: EmptyCollection<Element>, rhs: EmptyCollection<Element>) -> Bool
                       ^
Swift.Equatable:149:24: note: found this candidate
    public static func ==(lhs: Self, rhs: Self) -> Bool
                       ^
Swift.LazyFilterIndex<Base>:2:24: note: found this candidate
    public static func ==(lhs: LazyFilterIndex<Base>, rhs: LazyFilterIndex<Base>) -> Bool
                       ^
Swift.FlattenCollectionIndex<BaseElements>:2:24: note: found this candidate
    public static func ==(lhs: FlattenCollectionIndex<BaseElements>, rhs: FlattenCollectionIndex<BaseElements>) -> Bool
                       ^
Swift.FlattenBidirectionalCollectionIndex<BaseElements>:2:24: note: found this candidate
    public static func ==(lhs: FlattenBidirectionalCollectionIndex<BaseElements>, rhs: FlattenBidirectionalCollectionIndex<BaseElements>) -> Bool
                       ^
Swift.Set<Element>:9:24: note: found this candidate
    public static func ==(lhs: Set<Element>, rhs: Set<Element>) -> Bool
                       ^
Swift.Dictionary<Key, Value>:2:24: note: found this candidate
    public static func ==(lhs: [Key : Value], rhs: [Key : Value]) -> Bool
                       ^
Swift.SetIndex<Element>:2:24: note: found this candidate
    public static func ==(lhs: SetIndex<Element>, rhs: SetIndex<Element>) -> Bool
                       ^
Swift.DictionaryIndex<Key, Value>:2:24: note: found this candidate
    public static func ==(lhs: DictionaryIndex<Key, Value>, rhs: DictionaryIndex<Key, Value>) -> Bool
                       ^
Swift.Range<Bound>:2:24: note: found this candidate
    public static func ==(lhs: Range<Bound>, rhs: Range<Bound>) -> Bool
                       ^
Swift.CountableRange<Bound>:2:24: note: found this candidate
    public static func ==(lhs: CountableRange<Bound>, rhs: CountableRange<Bound>) -> Bool
                       ^
Swift.ClosedRange<Bound>:2:24: note: found this candidate
    public static func ==(lhs: ClosedRange<Bound>, rhs: ClosedRange<Bound>) -> Bool
                       ^
Swift.CountableClosedRange<Bound>:2:24: note: found this candidate
    public static func ==(lhs: CountableClosedRange<Bound>, rhs: CountableClosedRange<Bound>) -> Bool
                       ^
Swift.ReversedIndex:7:24: note: found this candidate
    public static func ==(lhs: ReversedIndex<Base>, rhs: ReversedIndex<Base>) -> Bool
                       ^
Swift.ReversedRandomAccessIndex:7:24: note: found this candidate
    public static func ==(lhs: ReversedRandomAccessIndex<Base>, rhs: ReversedRandomAccessIndex<Base>) -> Bool
@xedin
Copy link
Member

@xedin xedin commented Aug 22, 2017

The latest master produces following diagnostic:

error: reference to member 'foo' cannot be resolved without a contextual type
let a = UInt(1) == UInt(2) ? .foo : .bar
                             ~^~~

Which is what is expected because neither ".foo" nor ".bar" has a contextual type to be looked up at.

comex (JIRA User) Could you please verify and resolve this issue using the latest nightly build of swift compiler?

@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
Projects
None yet
Development

No branches or pull requests

2 participants