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

Crash when assigning a function with wrapped parameter to a variable. #77392

Open
zienag opened this issue Nov 5, 2024 · 0 comments
Open

Crash when assigning a function with wrapped parameter to a variable. #77392

zienag opened this issue Nov 5, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@zienag
Copy link

zienag commented Nov 5, 2024

Description

A problem arises when you try to assign a function with a wrapped parameter to a variable. A crash occurs when the variable has a type where the parameter is a wrapped type, not the wrappedValue's type.

Reproduction

@propertyWrapper struct Wrapper<T> {
  var wrappedValue: T
}

func test(@Wrapper _: Int) {}

let f1 = test(_:) // Type of expression is ambiguous without a type annotation
let f2: (Int) -> Void = test(_:) // ok
let f3: (Wrapper<Int>) -> Void = test(_:) // crash

Stack dump

0.	Program arguments: /Applications/Xcode16.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/zienag/dev/compiler_crash/compiler_crash/compiler_crash.swift -emit-dependencies-path /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/Objects-normal/arm64/compiler_crash.d -emit-const-values-path /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/Objects-normal/arm64/compiler_crash.swiftconstvalues -emit-reference-dependencies-path /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/Objects-normal/arm64/compiler_crash.swiftdeps -serialize-diagnostics-path /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/Objects-normal/arm64/compiler_crash.dia -target arm64-apple-macos14.6 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -I /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Products/Debug -F /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Products/Debug -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/zienag/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -const-gather-protocols-file /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/Objects-normal/arm64/compiler_crash_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -enable-experimental-feature OpaqueTypeErasure -enable-bare-slash-regex -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Users/zienag/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/zienag/dev/compiler_crash -resource-dir /Applications/Xcode16.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/zienag/dev/compiler_crash -Xcc -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -Xcc -ivfsstatcache -Xcc /Users/zienag/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.0-24A336-567210ce224e9c3bcd5bd1d73536faf0.sdkstatcache -Xcc -I/Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/compiler_crash-generated-files.hmap -Xcc -I/Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/compiler_crash-own-target-headers.hmap -Xcc -I/Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/compiler_crash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/compiler_crash-project-headers.hmap -Xcc -I/Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Products/Debug/include -Xcc -I/Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/DerivedSources-normal/arm64 -Xcc -I/Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/DerivedSources/arm64 -Xcc -I/Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/DerivedSources -Xcc -DDEBUG=1 -module-name compiler_crash -frontend-parseable-output -disable-clang-spi -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode16.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode16.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -o /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Build/Intermediates.noindex/compiler_crash.build/Debug/compiler_crash.build/Objects-normal/arm64/compiler_crash.o -index-unit-output-path /compiler_crash.build/Debug/compiler_crash.build/Objects-normal/arm64/compiler_crash.o -index-store-path /Users/zienag/Library/Developer/Xcode/DerivedData/compiler_crash-dsahfgoxbzvjrxfwqhuszlhhqpso/Index.noindex/DataStore -index-system-modules
1.	Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
2.	Compiling with effective version 5.10
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/zienag/dev/compiler_crash/compiler_crash/compiler_crash.swift")
4.	While silgen emitFunction SIL function "@$s14compiler_crash8MyStructV4mainyyFZ".
 for 'main()' (at /Users/zienag/dev/compiler_crash/compiler_crash/compiler_crash.swift:2:3)
5.	While emitting reabstraction thunk in SIL function "@$sSiIety_14compiler_crash7WrapperVySiGIegy_TR".
 for <<debugloc at "<compiler-generated>":0:0>>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           0x0000000105d630fc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000105d61350 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000105d636c8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000019c836584 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000019c805c20 pthread_kill + 288
5  libsystem_c.dylib        0x000000019c712a30 abort + 180
6  swift-frontend           0x0000000100ac6bc8 createDispatchingDiagnosticConsumerIfNeeded(swift::FrontendInputsAndOutputs const&, llvm::function_ref<std::__1::unique_ptr<swift::DiagnosticConsumer, std::__1::default_delete<swift::DiagnosticConsumer>> (swift::InputFile const&)>) + 0
7  swift-frontend           0x0000000105cd2e80 llvm::report_fatal_error(llvm::Twine const&, bool) + 280
8  swift-frontend           0x0000000105cd2d68 llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9  swift-frontend           0x000000010123f008 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 8236
10 swift-frontend           0x000000010124aff4 (anonymous namespace)::TranslateArguments::processSingle(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::ManagedValue, (anonymous namespace)::ParamInfo) + 436
11 swift-frontend           0x0000000101248910 (anonymous namespace)::ExpanderBase<(anonymous namespace)::TranslateArguments, (anonymous namespace)::ParamInfo>::expand(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType) + 600
12 swift-frontend           0x0000000101251898 (anonymous namespace)::TranslateArguments::expandParam(swift::Lowering::AbstractionPattern, swift::AnyFunctionType::CanParam, swift::Lowering::AbstractionPattern, swift::AnyFunctionType::CanParam) + 352
13 swift-frontend           0x0000000101241734 (anonymous namespace)::TranslateArguments::process(swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, bool) + 4724
14 swift-frontend           0x0000000101245e18 buildThunkBody(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanType, llvm::function_ref<void (swift::Lowering::SILGenFunction&)>) + 1268
15 swift-frontend           0x0000000101247f48 createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 3840
16 swift-frontend           0x000000010123d680 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 1700
17 swift-frontend           0x00000001011dd908 swift::Lowering::SILGenFunction::emitClosureValue(swift::SILLocation, swift::SILDeclRef, swift::Lowering::FunctionTypeInfo const&, swift::SubstitutionMap) + 1972
18 swift-frontend           0x00000001011abd68 swift::Lowering::SILGenFunction::emitRValueForDecl(swift::SILLocation, swift::ConcreteDeclRef, swift::Type, swift::AccessSemantics, swift::Lowering::SGFContext) + 524
19 swift-frontend           0x00000001011ab100 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 128
20 swift-frontend           0x0000000101196690 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 2016
21 swift-frontend           0x000000010119d5c4 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 140
22 swift-frontend           0x00000001012660ec swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 5756
23 swift-frontend           0x00000001011ddd4c swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 492
24 swift-frontend           0x00000001011298a0 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8420
25 swift-frontend           0x000000010112a140 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 216
26 swift-frontend           0x0000000101127770 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 364
27 swift-frontend           0x000000010127da10 (anonymous namespace)::SILGenType::visitFuncDecl(swift::FuncDecl*) + 32
28 swift-frontend           0x0000000101279fb8 (anonymous namespace)::SILGenType::emitType() + 424
29 swift-frontend           0x00000001011273a8 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 104
30 swift-frontend           0x000000010112ddbc swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1804
31 swift-frontend           0x00000001012646b0 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 196
32 swift-frontend           0x0000000101132c98 swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 528
33 swift-frontend           0x000000010070cf34 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 920
34 swift-frontend           0x0000000100710228 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1680
35 swift-frontend           0x000000010070ef58 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
36 swift-frontend           0x000000010069601c swift::mainEntry(int, char const**) + 3680
37 dyld                     0x000000019c47b154 start + 2476

Expected behavior

Compiler emits an error about mismatched types. Also, in f1 case, does complier really unable to infer type?

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0

Additional information

No response

@zienag zienag added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Nov 5, 2024
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. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant