mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/master' into master-next
This commit is contained in:
@@ -1337,6 +1337,12 @@ static bool processCommandLineAndRunImmediately(CompilerInvocation &Invocation,
|
||||
ProcessCmdLine(opts.ImmediateArgv.begin(), opts.ImmediateArgv.end());
|
||||
Instance.setSILModule(std::move(SM));
|
||||
|
||||
|
||||
PrettyStackTraceStringAction trace(
|
||||
"running user code",
|
||||
MSF.is<SourceFile *>() ? MSF.get<SourceFile *>()->getFilename()
|
||||
: MSF.get<ModuleDecl *>()->getModuleFilename());
|
||||
|
||||
ReturnValue =
|
||||
RunImmediately(Instance, CmdLine, IRGenOpts, Invocation.getSILOptions());
|
||||
return Instance.getASTContext().hadError();
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#if SWIFT_OBJC_INTEROP
|
||||
#include "swift/Runtime/ObjCBridge.h"
|
||||
#include "SwiftObject.h"
|
||||
#include "SwiftValue.h"
|
||||
#endif
|
||||
|
||||
@@ -2330,9 +2331,10 @@ static bool swift_dynamicCastImpl(OpaqueValue *dest, OpaqueValue *src,
|
||||
case MetadataKind::Class:
|
||||
case MetadataKind::ObjCClassWrapper:
|
||||
#if SWIFT_OBJC_INTEROP
|
||||
// If the destination type is an NSError, and the source type is an
|
||||
// Error, then the cast can succeed by NSError bridging.
|
||||
if (targetType == getNSErrorMetadata()) {
|
||||
// If the destination type is an NSError or NSObject, and the source type
|
||||
// is an Error, then the cast can succeed by NSError bridging.
|
||||
if (targetType == getNSErrorMetadata() ||
|
||||
targetType == getNSObjectMetadata()) {
|
||||
// Don't rebridge if the source is already some kind of NSError.
|
||||
if (srcType->isAnyClass()
|
||||
&& swift_dynamicCastObjCClass(*reinterpret_cast<id*>(src),
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
|
||||
#if SWIFT_OBJC_INTEROP
|
||||
#if __OBJC__
|
||||
|
||||
// Source code: "SwiftObject"
|
||||
// Real class name: mangled "Swift._SwiftObject"
|
||||
@@ -83,5 +84,13 @@ id getDescription(OpaqueValue *value, const Metadata *type);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace swift {
|
||||
|
||||
/// Get the NSObject metadata.
|
||||
const Metadata *getNSObjectMetadata();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1552,6 +1552,11 @@ void swift_objc_swift3ImplicitObjCEntrypoint(id self, SEL selector,
|
||||
free(nullTerminatedFilename);
|
||||
}
|
||||
|
||||
const Metadata *swift::getNSObjectMetadata() {
|
||||
return SWIFT_LAZY_CONSTANT(
|
||||
swift_getObjCClassMetadata((const ClassMetadata *)[NSObject class]));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const ClassMetadata *swift::getRootSuperclass() {
|
||||
|
||||
15
test/Frontend/crash-in-user-code.swift
Normal file
15
test/Frontend/crash-in-user-code.swift
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
// RUN: echo %s > %t.filelist.txt
|
||||
// RUN: not --crash %target-swift-frontend -interpret -filelist %t.filelist.txt 2>&1 | %FileCheck %s
|
||||
|
||||
// CHECK: Stack dump:
|
||||
// CHECK-NEXT: Program arguments:
|
||||
// CHECK-NEXT: Swift version
|
||||
// CHECK-NEXT: Contents of {{.*}}.filelist.txt:
|
||||
// CHECK-NEXT: ---
|
||||
// CHECK-NEXT: crash-in-user-code.swift
|
||||
// CHECK-NEXT: ---
|
||||
// CHECK-NEXT: While running user code "{{.*}}crash-in-user-code.swift"
|
||||
|
||||
let x: Int? = nil
|
||||
x!
|
||||
@@ -767,4 +767,29 @@ ErrorBridgingTests.test("@objc error domains for nested types") {
|
||||
String(reflecting: NonPrintAsObjCError.self))
|
||||
}
|
||||
|
||||
@inline(never)
|
||||
@_optimize(none)
|
||||
func anyToAny<T, U>(_ a: T, _ : U.Type) -> U {
|
||||
return a as! U
|
||||
}
|
||||
|
||||
ErrorBridgingTests.test("error-to-NSObject casts") {
|
||||
let error = MyCustomizedError(code: 12345)
|
||||
|
||||
// Unconditional cast
|
||||
let nsErrorAsObject1 = unconditionalCast(error, to: NSObject.self)
|
||||
let nsError1 = unconditionalCast(nsErrorAsObject1, to: NSError.self)
|
||||
expectEqual("custom", nsError1.domain)
|
||||
expectEqual(12345, nsError1.code)
|
||||
|
||||
// Conditional cast
|
||||
let nsErrorAsObject2 = conditionalCast(error, to: NSObject.self)!
|
||||
let nsError2 = unconditionalCast(nsErrorAsObject2, to: NSError.self)
|
||||
expectEqual("custom", nsError2.domain)
|
||||
expectEqual(12345, nsError2.code)
|
||||
|
||||
// "is" check
|
||||
expectTrue(error is NSObject)
|
||||
}
|
||||
|
||||
runAllTests()
|
||||
|
||||
Reference in New Issue
Block a user