Files
swift-mirror/test/diagnostics/multi-module-diagnostics.swift
Doug Gregor 5df96a7a6e Turn pretty-printing of a declaration into a request
The diagnostics engine has some code to pretty-print a declaration when
there is no source location for that declaration. The declaration is
pretty-printed into a source buffer, and a source location into that
buffer is synthesizes. This applies to synthesized declarations as well
as those imported from Swift modules (without source code) or from Clang.

Reimplement this pretty-printing for declarations as a request. In
doing so, change the manner in which we do the printing: the
diagnostics engine printed the entire enclosing type into a buffer
whose name was the module + that type. This meant that the buffer was
shared by every member of that type, but also meant that we would end
up deserializing a lot of declarations just for printing and
potentially doing a lot more work for these diagnostics.
2024-10-01 15:49:15 -07:00

94 lines
4.1 KiB
Swift

#if MODA_NORMAL
open class ParentClass {
open func overridableMethodA(param: Int) {}
open func overridableMethodB(param: Int) {}
open func overridableMethodC(param: Int) {}
open func overridableMethodD(param: Int) {}
}
#endif
#if MODA_LOC
open class ParentClass {
#sourceLocation(file: "doesnotexist.swift", line: 10)
open func overridableMethodA(param: Int) {}
open func overridableMethodB(param: Int) {}
#sourceLocation(file: "REPLACEDWITHSED", line: 20)
open func overridableMethodC(param: Int) {}
open func overridableMethodD(param: Int) {}
#sourceLocation()
}
#endif
#if MODB
import moda
open class SubClass: ParentClass {
open override func overridableMethodA(param: String) {}
open override func overridableMethodB(param: String) {}
open override func overridableMethodC(param: String) {}
open override func overridableMethodD(param: String) {}
}
#endif
// This test depends on line numbers, hence RUN lines being underneath the
// code.
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/mods)
// RUN: sed -e 's|REPLACEDWITHSED|%/t/alternative.swift|g' %s > %t/moda.swift
// RUN: %target-swift-frontend -emit-module -emit-module-source-info -o %t/mods/moda.swiftmodule -D MODA_NORMAL %t/moda.swift
// The diagnostic should have the real location from .swiftsourceinfo
// RUN: not %target-swift-frontend -typecheck -I %t/mods -D MODB %s 2>&1 | %FileCheck -check-prefix=CHECK-EXISTS %s
// CHECK-EXISTS: moda.swift:3:13: note
// CHECK-EXISTS: moda.swift:4:13: note
// CHECK-EXISTS: moda.swift:5:13: note
// CHECK-EXISTS: moda.swift:6:13: note
// Removed the underlying file, so should use the generated source instead
// RUN: mv %t/moda.swift %t/moda.swift-moved
// RUN: not %target-swift-frontend -typecheck -I %t/mods -D MODB %s 2>&1 | %FileCheck -check-prefix=CHECK-GENERATED %s
// CHECK-GENERATED: moda.ParentClass.overridableMethodA:{{.*}}: note:
// Underlying file has changed, so the locations in .swiftsourceinfo may not
// make sense any more. Ignored for now (ie. it is used regardless)
// RUN: echo "// file was modified" > %t/moda.swift
// RUN: cat %t/moda.swift-moved >> %t/moda.swift
// RUN: not %target-swift-frontend -typecheck -I %t/mods -D MODB %s 2>&1 | %FileCheck -check-prefix=CHECK-OUTOFDATE %s
// CHECK-OUTOFDATE-NOT: moda.ParentClass:{{.*}}: note:
// CHECK-OUTOFDATE: moda.swift:{{.*}}: note:
// Underlying file is empty, the locations are now completely invalid (ie. not
// within the buffer). Make sure there's no crash and that we fallback to using
// the generated source.
// RUN: rm %t/moda.swift
// RUN: touch %t/moda.swift
// RUN: not %target-swift-frontend -typecheck -I %t/mods -D MODB %s 2>&1 | %FileCheck -check-prefix=CHECK-EMPTY %s
// CHECK-EMPTY: moda.ParentClass.overridableMethodA:{{.*}}: note:
// The file and line from a location directive should be used whether or not it
// exists - the actual source still comes from the original file, so that's what
// matters in terms of whether generated code is used or not
// RUN: %empty-directory(%t/mods)
// RUN: mv %t/moda.swift-moved %t/moda.swift
// RUN: %target-swift-frontend -emit-module -emit-module-source-info -o %t/mods/moda.swiftmodule -D MODA_LOC %t/moda.swift
// RUN: cp %t/moda.swift %t/alternative.swift
// RUN: not %target-swift-frontend -typecheck -I %t/mods -D MODB %s 2>&1 | %FileCheck -check-prefix=CHECK-DIRECTIVE %s
// CHECK-DIRECTIVE: {{^}}doesnotexist.swift:10:13: note
// CHECK-DIRECTIVE: {{^}}doesnotexist.swift:11:13: note
// CHECK-DIRECTIVE: alternative.swift:20:13: note
// CHECK-DIRECTIVE: alternative.swift:21:13: note
// File in line directive exists, but location does not
// RUN: mv %t/alternative.swift %t/alternative.swift-moved
// RUN: echo "" > %t/alternative.swift
// RUN: not %target-swift-frontend -typecheck -I %t/mods -D MODB %s 2>&1 | %FileCheck -check-prefix=CHECK-DIRECTIVE %s
// Removed the underlying file, so should use the generated source instead
// RUN: mv %t/alternative.swift-moved %t/alternative.swift
// RUN: mv %t/moda.swift %t/moda.swift-moved
// RUN: not %target-swift-frontend -typecheck -I %t/mods -D MODB %s 2>&1 | %FileCheck -check-prefix=CHECK-GENERATED %s