edit: this was intended to be a reply to @Douglas_Gregor
I'm trying out the toolchain linked in the pitch, and I'm having trouble. It seems that accessing the synthesized wrapper property outside of the type causes the compiler to crash.
@propertyDelegate
struct Test<V> {
var value: V
init(initialValue: V) {
value = initialValue
}
func test() {}
}
class C {
@Test var a = 0
@Test var b = ""
init() {
$a.test() // <--- This one is fine
}
}
let c = C()
c.$a.test() // <--- Seg fault: 11
Stack dump:
0. Program arguments: /Users/avi/Library/Developer/Toolchains/swift-PR-23701-300.xctoolchain/usr/bin/swift -frontend -c /Users/avi/Projects/CmdTest/CmdTest/Observable.swift -primary-file /Users/avi/Projects/CmdTest/CmdTest/main.swift /Users/avi/Projects/CmdTest/CmdTest/Observables.swift -emit-module-path /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/Objects-normal/x86_64/main~partial.swiftmodule -emit-module-doc-path /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/Objects-normal/x86_64/main~partial.swiftdoc -serialize-diagnostics-path /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/Objects-normal/x86_64/main.swiftdeps -target x86_64-apple-macosx10.14 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Products/Debug -F /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Products/Debug -enable-testing -g -module-cache-path /Users/avi/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -enable-anonymous-context-mangled-names -Xcc -I/Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/CmdTest-generated-files.hmap -Xcc -I/Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/CmdTest-own-target-headers.hmap -Xcc -I/Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/CmdTest-all-target-headers.hmap -Xcc -iquote -Xcc /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/CmdTest-project-headers.hmap -Xcc -I/Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Products/Debug/include -Xcc -I/Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/DerivedSources-normal/x86_64 -Xcc -I/Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/DerivedSources/x86_64 -Xcc -I/Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/avi/Projects/CmdTest -module-name CmdTest -o /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Build/Intermediates.noindex/CmdTest.build/Debug/CmdTest.build/Objects-normal/x86_64/main.o -index-store-path /Users/avi/Library/Developer/Xcode/DerivedData/CmdTest-aaomfvgeclatyvbhhwovvxdgladw/Index/DataStore -index-system-modules
0 swift 0x000000010b9cc7b5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1 swift 0x000000010b9cba75 llvm::sys::RunSignalHandlers() + 85
2 swift 0x000000010b9ccd98 SignalHandler(int) + 264
3 libsystem_platform.dylib 0x00007fff65d99b5d _sigtramp + 29
4 libsystem_platform.dylib 000000000000000000 _sigtramp + 2586207424
5 swift 0x00000001082ede3a SILGenLValue::visitMemberRefExpr(swift::MemberRefExpr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 890
6 swift 0x00000001082e9a81 swift::ASTVisitor<SILGenLValue, swift::Lowering::LValue, void, void, void, void, void, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions>::visit(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 305
7 swift 0x00000001082e97e7 swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 55
8 swift 0x00000001082c977c swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 8092
9 swift 0x00000001082bc6d9 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57
10 swift 0x0000000108272ece (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1838
11 swift 0x0000000108260ac6 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 70
12 swift 0x000000010827df43 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 163
13 swift 0x000000010827dc5a (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 730
14 swift 0x000000010827d46b (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1723
15 swift 0x0000000108263d74 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2980
16 swift 0x0000000108263080 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2464
17 swift 0x00000001082c7836 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 86
18 swift 0x00000001082bcc01 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 1137
19 swift 0x0000000108257684 swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 564
20 swift 0x0000000108257ed6 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 822
21 swift 0x0000000108258e85 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 293
22 swift 0x00000001082593f9 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&) + 41
23 swift 0x0000000107f59cbe performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 8398
24 swift 0x0000000107f56b92 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2978
25 swift 0x0000000107efd918 main + 696
26 libdyld.dylib 0x00007fff65bae3d5 start + 1
27 libdyld.dylib 0x0000000000000047 start + 2588220531
error: Segmentation fault: 11