Skip to content

Disallow implicit existential opening when calling function with an opaque result type #59840

Open
@karwa

Description

@karwa

Describe the bug

protocol P {
  associatedtype A
  func getA() -> A
}

struct S<T: P> {
    var s: T
}

func openSesame(_ p: some P) -> S<some P> {
    S(s: p)
}

func test(_ p: any P) {

  let x = openSesame(p)
//   print(x)

}
Unhandled coercion
UNREACHABLE executed at /home/build-user/swift/lib/Sema/CSApply.cpp:7219!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend -frontend -S -primary-file <source> -target x86_64-unknown-linux-gnu -disable-objc-interop -g -new-driver-path /opt/compiler-explorer/swift-nightly/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /opt/compiler-explorer/swift-nightly/usr/lib/swift -enable-anonymous-context-mangled-names -Xllvm --x86-asm-syntax=intel -module-name output -o /app/output.s
1.	Swift version 5.8-dev (LLVM befe8168eb51210, Swift 0daa5584f4a2471)
2.	Compiling with the current language version
3.	While evaluating request TypeCheckSourceFileRequest(source_file "<source>")
4.	While evaluating request TypeCheckFunctionBodyRequest(output.(file).testOpenSimple(p:)@<source>:14:6)
5.	While type-checking statement at [<source>:14:31 - line:19:1] RangeText="{

  let x = openSesame(p)
//   print(x)

"
6.	While type-checking declaration 0xa816bf0 (at <source>:16:3)
7.	While evaluating request PatternBindingEntryRequest((unknown decl), 0, 0)
8.	While type-checking expression at [<source>:16:11 - line:16:23] RangeText="openSesame(p"
9.	While type-checking-target starting at <source>:16:11

To Reproduce

Godbolt

Environment (please complete the following information):

  • Swift version 5.8-dev (LLVM befe8168eb51210, Swift 0daa558)
  • OS: Linux

Metadata

Metadata

Labels

assertion failureBug → crash: An assertion failurebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesexpressionsFeature: expressionsgenericsFeature: generic declarations and typesimplicit existential openingFeature → existentials: implicit opening of existentials when passed to parameters of generic typeopaque result typesFeature → types → opaque types: opaque result typesopaque typesFeature → types: opaque typesswift 6.1type checkerArea → compiler: Semantic analysistypesFeature: types

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions