mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's contents in the SourceManager, has always been optional. However, the effectively every SourceFile actually does have a buffer ID, and the vast majority of accesses to this information dereference the optional without checking. Update the handful of call sites that provided `nullopt` as the buffer ID to provide a proper buffer instead. These were mostly unit tests and testing programs, with a few places that passed a never-empty optional through to the SourceFile constructor. Then, remove optionality from the representation and accessors. It is now the case that every SourceFile has a buffer ID, simplying a bunch of code.
This commit is contained in:
@@ -49,7 +49,7 @@ collectRefactoringsAtCursor(SourceFile *SF, unsigned Line, unsigned Column,
|
||||
DiagnosticEngine DiagEngine(SM);
|
||||
std::for_each(DiagConsumers.begin(), DiagConsumers.end(),
|
||||
[&](DiagnosticConsumer *Con) { DiagEngine.addConsumer(*Con); });
|
||||
SourceLoc Loc = SM.getLocForLineCol(SF->getBufferID().value(), Line, Column);
|
||||
SourceLoc Loc = SM.getLocForLineCol(SF->getBufferID(), Line, Column);
|
||||
if (Loc.isInvalid())
|
||||
return {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user