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

Protocol with typed throwing getter cannot be witnessed #80288

Closed
stephencelis opened this issue Mar 25, 2025 · 2 comments · Fixed by #80445
Closed

Protocol with typed throwing getter cannot be witnessed #80288

stephencelis opened this issue Mar 25, 2025 · 2 comments · Fixed by #80445
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@stephencelis
Copy link
Contributor

Description

It does not appear to be possible to fulfill a typed throwing getter requirement in a protocol.

Reproduction

// Does not work
protocol Fooable {
  associatedtype Failure: Error = Never
  var prop: Int { get throws(Failure) }
}
extension Int: Fooable {
  var prop: Int {
    get throws(Never) {
      fatalError()
    }
  }
}

// Works
protocol Barable {
  associatedtype Failure: Error = Never
  func f() throws(Failure) -> Int
}
extension Int: Barable {
  func f() throws(Never) -> Int {
    self
  }
}

Expected behavior

I expect all of the above code to compile.

Environment

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.5 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

Additional information

No response

@stephencelis stephencelis added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 25, 2025
@slavapestov
Copy link
Contributor

Fails with an asserts build as follows:

slava@Mac swift % xcrun ../build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/bin/swiftc throw.swift  
error: compile command failed due to signal 6 (use -v to see invocation)
Assertion failed: (isAdmissibleType(First)), function Constraint at Constraint.cpp:64.
(to display assertion configuration options: -Xllvm -assert-help)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Users/slava/src/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/bin/swift-frontend -frontend -c -primary-file throw.swift -target arm64-apple-macosx15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX15.4.sdk -color-diagnostics -Xcc -fcolor-diagnostics -empty-abi-descriptor -no-auto-bridging-header-chaining -module-name throw -in-process-plugin-server-path /Users/slava/src/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Users/slava/src/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/lib/swift/host/plugins -plugin-path /Users/slava/src/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/local/lib/swift/host/plugins -target-sdk-version 15.4 -target-sdk-name macosx15.4 -external-plugin-path /Library/Developer/Developer/usr/lib/swift/host/plugins#/Library/Developer/Developer/usr/bin/swift-plugin-server -external-plugin-path /Library/Developer/Developer/usr/local/lib/swift/host/plugins#/Library/Developer/Developer/usr/bin/swift-plugin-server -o /var/folders/qn/b1yvkm_x0ml3hphs428lmyx40000gn/T/TemporaryDirectory.a0Uvng/throw-1.o
1.	Swift version 6.2-dev (LLVM da17cd8368b0838, Swift 8f934fdf9409b62)
2.	Compiling with effective version 5.10
3.	While evaluating request TypeCheckPrimaryFileRequest(source_file "throw.swift")
4.	While type-checking extension of Int (at throw.swift:6:1)
5.	While type-checking protocol conformance Int: Fooable at extension of Int (at throw.swift:6:1)
6.	While evaluating request ResolveValueWitnessesRequest(Int: Fooable module throw)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001061e8104 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001061e6854 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001061e874c SignalHandler(int, __siginfo*, void*) + 296
3  libsystem_platform.dylib 0x0000000199e3f624 _sigtramp + 56
4  libsystem_pthread.dylib  0x0000000199e0588c pthread_kill + 296
5  libsystem_c.dylib        0x0000000199d0ec60 abort + 124
6  swift-frontend           0x0000000102454040 ASSERT_help() + 0
7  swift-frontend           0x0000000101c5af28 swift::constraints::Constraint::Constraint(swift::constraints::ConstraintKind, swift::Type, swift::Type, swift::constraints::ConstraintLocator*, llvm::SmallPtrSetImpl<swift::TypeVariableType*>&) + 432
8  swift-frontend           0x0000000101c5d004 swift::constraints::Constraint::create(swift::constraints::ConstraintSystem&, swift::constraints::ConstraintKind, swift::Type, swift::Type, swift::constraints::ConstraintLocator*, llvm::ArrayRef<swift::TypeVariableType*>) + 448
9  swift-frontend           0x0000000101bb2374 swift::constraints::ConstraintSystem::addConstraint(swift::constraints::ConstraintKind, swift::Type, swift::Type, swift::constraints::ConstraintLocatorBuilder, bool) + 204
10 swift-frontend           0x0000000101e2b2f8 std::__1::optional<swift::RequirementMatch> llvm::function_ref<std::__1::optional<swift::RequirementMatch> (swift::Type, swift::Type)>::callback_fn<swift::matchWitness(llvm::DenseMap<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, swift::RequirementEnvironment, llvm::DenseMapInfo<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, void>, llvm::detail::DenseMapPair<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, swift::RequirementEnvironment>>&, swift::ProtocolDecl*, swift::RootProtocolConformance*, swift::DeclContext*, swift::ValueDecl*, swift::ValueDecl*)::$_1>(long, swift::Type, swift::Type) + 96
11 swift-frontend           0x0000000101e0fd2c swift::matchWitness(swift::DeclContext*, swift::ValueDecl*, swift::ValueDecl*, llvm::function_ref<std::__1::tuple<std::__1::optional<swift::RequirementMatch>, swift::Type, swift::Type> ()>, llvm::function_ref<std::__1::optional<swift::RequirementMatch> (swift::Type, swift::Type)>, llvm::function_ref<swift::RequirementMatch (bool, llvm::ArrayRef<swift::OptionalAdjustment>)>) + 3448
12 swift-frontend           0x0000000101e10cc4 swift::matchWitness(llvm::DenseMap<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, swift::RequirementEnvironment, llvm::DenseMapInfo<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, void>, llvm::detail::DenseMapPair<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, swift::RequirementEnvironment>>&, swift::ProtocolDecl*, swift::RootProtocolConformance*, swift::DeclContext*, swift::ValueDecl*, swift::ValueDecl*) + 628
13 swift-frontend           0x0000000101e117ac swift::WitnessChecker::findBestWitness(swift::ValueDecl*, bool*, swift::NormalProtocolConformance*, llvm::SmallVectorImpl<swift::RequirementMatch>&, unsigned int&, unsigned int&, bool&) + 532

@slavapestov slavapestov self-assigned this Apr 1, 2025
@slavapestov
Copy link
Contributor

We're not handling the case where an effectful getter's thrown error type contains type parameters at all. It needs to be refactored to open the type first like we do in other cases. I'll try to figure it out.

slavapestov added a commit to slavapestov/swift that referenced this issue Apr 1, 2025
Witness matching didn't handle the case where either the
requirement or the witness is a property with a throwing
getter, and the thrown error type contains a type parameter.

We must open the thrown error types first, replacing type
parameters with type variables, for the matching to work.

Associated type inference needs a similar fix. I'll land a
combined test case for both once I fix that.

Fixes swiftlang#80288.
Fixes rdar://problem/147874955.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants