swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.5k stars 10.35k forks source link

[SR-4994] Should type check, doesn't #1 #47571

Closed dabrahams closed 6 years ago

dabrahams commented 7 years ago
Previous ID SR-4994
Radar rdar://problem/32381620
Original Reporter @dabrahams
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, TypeChecker | |Assignee | None | |Priority | Medium | md5: 36371a7bd73751fcd8ec14128add5cc6

is duplicated by:

Issue Description:

On GitHub/master, for a long time, we've had:

let x: Int = 0, y: UInt8 = 0
x &<< (1 - y) // error: '-' is unavailable: Please use explicit type conversions or Strideable methods for mixed-type arithmetics.
dabrahams commented 7 years ago

@swift-ci create

dabrahams commented 7 years ago

/cc @moiseev

ee21ea02-9d7a-4385-8c3c-ad21e8e490a8 commented 7 years ago

A little more details:

This is happening in Swift 4 mode (Swift 3 only warns about the deprecation of this overload). Also there is a note that the compiler generates:

Swift.Strideable:9:24: note: '-' was obsoleted in Swift 4
    public static func -(lhs: Self, rhs: Self) -> Self.Stride
                       ^
ee21ea02-9d7a-4385-8c3c-ad21e8e490a8 commented 7 years ago

This is all happening because of the - overload on Strideable of type (Self, Self) -> Self.Stride.

I guess what's happening is as follows:

For some reason, compiler does not seem to try another possible solution, a homogeneous - defined on Int.

Same expression compiles just fine, should you change the type of x to something other than {{Int}.

CodaFi commented 6 years ago

This typechecks in Xcode 9.3, 10, and ToT Swift.