swiftlang / swift

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

[SR-4551] Bogus ambiguity #47128

Open dabrahams opened 7 years ago

dabrahams commented 7 years ago
Previous ID SR-4551
Radar rdar://problem/31527224
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, TypeChecker | |Assignee | @ematejska | |Priority | Medium | md5: aff8ae4aa15d32bbe341d91981f60b6f

Issue Description:

With:

$ git fetch https://github.com/dabrahams/swift refs/bugs/refs/bugs/bogus-ambiguity:BUG && git checkout BUG

Build the standard library for these errors.

cd /Users/Shared/dabrahams/s/build/Ninja-Release/swift-macosx-x86_64/stdlib/public/core && /usr/bin/python /Users/Shared/dabrahams/s/swift/utils/line-directive @/Users/Shared/dabrahams/s/build/Ninja-Release/swift-macosx-x86_64/stdlib/public/core/6oN5j.txt -- /Users/Shared/dabrahams/s/build/Ninja-Release/swift-macosx-x86_64/./bin/swiftc -c -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -target x86_64-apple-macosx10.9 -resource-dir /Users/Shared/dabrahams/s/build/Ninja-Release/swift-macosx-x86_64/./lib/swift -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/../../../Developer/Library/Frameworks -O -I /Users/Shared/dabrahams/s/build/Ninja-Release/swift-macosx-x86_64/./lib/swift/macosx/x86_64 -module-cache-path /Users/Shared/dabrahams/s/build/Ninja-Release/swift-macosx-x86_64/./module-cache -no-link-objc-runtime -Xfrontend -enable-cow-existentials -nostdimport -parse-stdlib -module-name Swift -Xfrontend -group-info-path -Xfrontend /Users/Shared/dabrahams/s/swift/stdlib/public/core/GroupInfo.json -Xfrontend -sil-serialize-all -warn-swift3-objc-inference -module-link-name swiftCore -force-single-frontend-invocation -Xcc -D__SWIFT_CURRENT_DYLIB=swiftCore -parse-as-library -o /Users/Shared/dabrahams/s/build/Ninja-Release/swift-macosx-x86_64/stdlib/public/core/macosx/x86_64/Swift.o @/Users/Shared/dabrahams/s/build/Ninja-Release/swift-macosx-x86_64/stdlib/public/core/6oN5j.txt
/Users/Shared/dabrahams/s/swift/stdlib/public/core/ForwardCollectionAPIs.swift.gyb:45:36: error: ambiguous use of 'unicodeScalars'
  return x.unicodeScalars.anyIndex(x.unicodeScalars.startIndex)
                                   ^
/Users/Shared/dabrahams/s/swift/stdlib/public/core/AnyUnicode.swift.gyb:292:7: note: found this candidate
  var unicodeScalars: RandomAccessUnicodeView<
      ^
/Users/Shared/dabrahams/s/swift/stdlib/public/core/AnyUnicode.swift.gyb:218:7: note: found this candidate
  var unicodeScalars: _UnicodeViews<CodeUnits,Encoding>.UnicodeScalars {
      ^
/Users/Shared/dabrahams/s/swift/stdlib/public/core/ForwardCollectionAPIs.swift.gyb:49:36: error: ambiguous use of 'unicodeScalars'
  return x.unicodeScalars.anyIndex(x.unicodeScalars.endIndex)
                                   ^
/Users/Shared/dabrahams/s/swift/stdlib/public/core/AnyUnicode.swift.gyb:292:7: note: found this candidate
  var unicodeScalars: RandomAccessUnicodeView<
      ^
/Users/Shared/dabrahams/s/swift/stdlib/public/core/AnyUnicode.swift.gyb:218:7: note: found this candidate
  var unicodeScalars: _UnicodeViews<CodeUnits,Encoding>.UnicodeScalars {
      ^
/Users/Shared/dabrahams/s/swift/stdlib/public/core/ForwardCollectionAPIs.swift.gyb:118:27: error: ambiguous use of 'unicodeScalars'
  return x.unicodeScalars[x.unicodeScalars.nativeIndex(i)]
                          ^
/Users/Shared/dabrahams/s/swift/stdlib/public/core/AnyUnicode.swift.gyb:292:7: note: found this candidate
  var unicodeScalars: RandomAccessUnicodeView<
      ^
/Users/Shared/dabrahams/s/swift/stdlib/public/core/AnyUnicode.swift.gyb:218:7: note: found this candidate
  var unicodeScalars: _UnicodeViews<CodeUnits,Encoding>.UnicodeScalars {
      ^
[3/79] Generating /Users/Shared/dabrahams/s/build/Ninja-Release/swift-macosx-x86_64/./lib/swift/macosx/x86_64/Swift.swiftmodule

These shouldn't be ambiguous because one of the extensions' constraints are a strict superset of the others'. Incidentally, trying to work around this by removing one of the extensions and putting it on the one concrete type to which it applies leads to further hilarity.

====

Other hashes:

clang                              5b642bad4e Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
cmark                              d875488 Merge pull request #&#8203;4 from llvm-beanz/generate-cmark-exports
compiler-rt                        fef6bcb58 Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
llbuild                            844fb8e [BuildSystem] Clarify a comment.
lldb                               6e17e33ef Xfail two tests that showed expressions that generate bad code.
llvm                               90ddc086b8f Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
Traceback (most recent call last):

My build-script invocation is:

build-script --skip-build-ios-device --skip-build-tvos-device --skip-build-compiler-rt --skip-build-benchmarks --release --no-assertions --
dabrahams commented 7 years ago

@swift-ci create

dabrahams commented 7 years ago

Please note: the previous revision on this branch, which had exactly the same overload set, compiled fine.

dabrahams commented 7 years ago

No longer blocked by this.