swiftlang / swift

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

[SR-434] Confounding non-conformance diagnostic #43051

Open dabrahams opened 8 years ago

dabrahams commented 8 years ago
Previous ID SR-434
Radar None
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, DiagnosticsQoI, TypeChecker | |Assignee | None | |Priority | Medium | md5: d1d92894b07a001718c1bd56c575351e

Issue Description:

This tiny patch (applies to to 249c86e) attempts to move the `absoluteValue` property requirement and `AbsoluteValue` associated type up the refinement hierarchy from SignedIntegerType to IntegerType.
The problem is on line 26 of the patch (should be : Self, not : AbsoluteValue).

If you run the Prototypes/Integers.swift.gyb test, you’ll get this:

/Users/dave/src/s/swift/test/Prototypes/Integers.swift.gyb:787:15: error: type 'Int8' does not conform to protocol 'IntegerType'
public struct Int8
              ^
/Users/dave/src/s/swift/test/Prototypes/Integers.swift.gyb:198:7: note: protocol requires property 'mostSignificantBit' with type 'Word' (aka 'Int64')
  var mostSignificantBit: Word { get }
      ^
/Users/dave/src/s/swift/test/Prototypes/Integers.swift.gyb:760:14: note: candidate has non-matching type 'Word' (aka 'Int64') [with AbsoluteValue = UInt8]
  public var mostSignificantBit: Word {
             ^
…

The diagnostics make no sense, “requires Word; candidate has non-matching type Word” and mentions the changed associated type incidentally in a way I don’t understand.

Dante-Broggi commented 6 years ago

I believe this can be closed as "Cannot Reproduce", unless someone wants to extract a test case.

dabrahams commented 6 years ago

`AbsoluteValue` is now called `Magnitude`. You could probably recreate this scenario in the standard library pretty easily before you decide to pitch it.